github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/binding/binding_test/binding_importedstruct_test.go (about) 1 package binding_test 2 3 import "github.com/AlpineAIO/wails/v2/internal/binding/binding_test/binding_test_import" 4 5 type ImportedStruct struct { 6 AWrapperContainer binding_test_import.AWrapper `json:"AWrapperContainer"` 7 } 8 9 func (s ImportedStruct) Get() ImportedStruct { 10 return s 11 } 12 13 var ImportedStructTest = BindingTest{ 14 name: "ImportedStruct", 15 structs: []interface{}{ 16 &ImportedStruct{}, 17 }, 18 exemptions: nil, 19 shouldError: false, 20 want: ` 21 export namespace binding_test { 22 export class ImportedStruct { 23 AWrapperContainer: binding_test_import.AWrapper; 24 static createFrom(source: any = {}) { 25 return new ImportedStruct(source); 26 } 27 constructor(source: any = {}) { 28 if ('string' === typeof source) source = JSON.parse(source); 29 this.AWrapperContainer = this.convertValues(source["AWrapperContainer"], binding_test_import.AWrapper); 30 } 31 convertValues(a: any, classs: any, asMap: boolean = false): any { 32 if (!a) { 33 return a; 34 } 35 36 if (a.slice) { 37 return (a as any[]).map(elem => this.convertValues(elem, classs)); 38 } else if ("object" === typeof a) { 39 if (asMap) { 40 for (const key of Object.keys(a)) { 41 a[key] = new classs(a[key]); 42 } 43 return a; 44 } 45 return new classs(a); 46 } 47 return a; 48 } 49 } 50 } 51 52 export namespace binding_test_import { 53 export class AWrapper { 54 AWrapper: binding_test_nestedimport.A; 55 static createFrom(source: any = {}) { 56 return new AWrapper(source); 57 } 58 constructor(source: any = {}) { 59 if ('string' === typeof source) source = JSON.parse(source); 60 this.AWrapper = this.convertValues(source["AWrapper"], binding_test_nestedimport.A); 61 } 62 convertValues(a: any, classs: any, asMap: boolean = false): any { 63 if (!a) { 64 return a; 65 } 66 if (a.slice) { 67 return (a as any[]).map(elem => this.convertValues(elem, classs)); 68 } else if ("object" === typeof a) { 69 if (asMap) { 70 for (const key of Object.keys(a)) { 71 a[key] = new classs(a[key]); 72 } 73 return a; 74 } 75 return new classs(a); 76 } 77 return a; 78 } 79 } 80 } 81 82 export namespace binding_test_nestedimport { 83 export class A { 84 A: string; 85 static createFrom(source: any = {}) { 86 return new A(source); 87 } 88 constructor(source: any = {}) { 89 if ('string' === typeof source) source = JSON.parse(source); 90 this.A = source["A"]; 91 } 92 } 93 } 94 `, 95 }