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