5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 23:39:21 +08:00

Refactor TS imports

This commit is contained in:
Lea Anthony 2022-04-04 07:19:39 +10:00
parent 2c8d94ca48
commit 8bb3af2282
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405

View File

@ -35,7 +35,7 @@ func (b *Bindings) GenerateGoBindings(baseDir string) error {
tsContent.WriteString(`// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
`)
var importClasses []string
var importClasses slicer.StringSlicer
for methodName, methodDetails := range methods {
// Generate JS
@ -55,9 +55,7 @@ func (b *Bindings) GenerateGoBindings(baseDir string) error {
// Generate TS
if len(methodDetails.StructNames) > 0 {
for _, structName := range methodDetails.StructNames {
importClasses = append(importClasses, structName)
}
importClasses.AddSlice(methodDetails.StructNames)
}
tsBody.WriteString(fmt.Sprintf("\nexport function %s(", methodName))
@ -82,10 +80,10 @@ func (b *Bindings) GenerateGoBindings(baseDir string) error {
tsBody.WriteString(returnType + ";\n")
}
importClasses = removeDuplicates(importClasses)
for _, class := range importClasses {
importClasses.Deduplicate()
importClasses.Each(func(class string) {
tsContent.WriteString("import {" + class + "} from '../models';\n")
}
})
tsContent.WriteString(tsBody.String())
jsfilename := filepath.Join(packageDir, structName+".js")
@ -333,15 +331,3 @@ func goTypeToTypescriptType(input string, useModelsNamespace bool) string {
}
return goTypeToJSDocType(input, useModelsNamespace)
}
func removeDuplicates(input []string) []string {
seen := make(map[string]bool)
var result []string
for _, val := range input {
if _, ok := seen[val]; !ok {
result = append(result, val)
seen[val] = true
}
}
return result
}