github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/binding/binding_test/binding_importedslice_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 ImportedSlice struct {
     6  	ASliceWrapperContainer binding_test_import.ASliceWrapper `json:"ASliceWrapperContainer"`
     7  }
     8  
     9  func (s ImportedSlice) Get() ImportedSlice {
    10  	return s
    11  }
    12  
    13  var ImportedSliceTest = BindingTest{
    14  	name: "ImportedSlice",
    15  	structs: []interface{}{
    16  		&ImportedSlice{},
    17  	},
    18  	exemptions:  nil,
    19  	shouldError: false,
    20  	want: `
    21  export namespace binding_test {
    22  	export class ImportedSlice {
    23  		ASliceWrapperContainer: binding_test_import.ASliceWrapper;
    24  		static createFrom(source: any = {}) {
    25  			return new ImportedSlice(source);
    26  		}
    27  		constructor(source: any = {}) {
    28  			if ('string' === typeof source) source = JSON.parse(source);
    29  			this.ASliceWrapperContainer = this.convertValues(source["ASliceWrapperContainer"], binding_test_import.ASliceWrapper);
    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 ASliceWrapper {
    53  		ASlice: binding_test_nestedimport.A[];
    54  		static createFrom(source: any = {}) {
    55  			return new ASliceWrapper(source);
    56  		}
    57  		constructor(source: any = {}) {
    58  			if ('string' === typeof source) source = JSON.parse(source);
    59  			this.ASlice = this.convertValues(source["ASlice"], binding_test_nestedimport.A);
    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  }