forked from wailsapp/wails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved bindings generation: support JS Models.
- Loading branch information
1 parent
23c2660
commit 182f430
Showing
11 changed files
with
448 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{{$pkg := .Package}} | ||
// Defining the {{$pkg}} namespace | ||
export const {{$pkg}} = {}; | ||
{{range $enumindex, $enumdef := .Enums}} | ||
// Simulating the enum with an object | ||
{{$pkg}}.{{$enumdef.Name}} = { | ||
{{- range $constindex, $constdef := .Consts}} | ||
{{- if $constdef.DocComment}} | ||
// {{$constdef.DocComment}} | ||
{{- end}} | ||
{{$constdef.Name}}: {{$constdef.Value}},{{end}} | ||
}; | ||
{{- end}} | ||
{{range $name, $def := .Models}} | ||
{{- if $def.DocComment}} | ||
// {{$def.DocComment}} | ||
{{- end -}} | ||
{{$pkg}}.{{$def.Name}} = class { | ||
/** | ||
* Creates a new {{$def.Name}} instance. | ||
* @constructor | ||
* @param {Object} source - The source object to create the {{$def.Name}}. | ||
{{- range $field := $def.Fields}} | ||
* @param { {{- .JSDocType $pkg -}} } source.{{$field.Name}}{{end}} | ||
*/ | ||
constructor(source = {}) { | ||
const { {{$def.DefaultValueList}} } = source; {{range $def.Fields}} | ||
this.{{.JSName}} = {{.JSName}};{{end}} | ||
} | ||
|
||
/** | ||
* Creates a new {{$def.Name}} instance from a string or object. | ||
* @param {string|object} source - The source data to create a {{$def.Name}} instance from. | ||
* @returns {{$pkg}}.{{$def.Name}} A new {{$def.Name}} instance. | ||
*/ | ||
static createFrom(source = {}) { | ||
let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; | ||
return new {{$pkg}}.{{$def.Name}}(parsedSource); | ||
} | ||
}; | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// @ts-check | ||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL | ||
// This file is automatically generated. DO NOT EDIT | ||
|
||
// Defining the main namespace | ||
export const main = {}; | ||
|
||
// Simulating the enum with an object | ||
main.Title = { | ||
// Mister is a title | ||
Mister: "Mr", | ||
Miss: "Miss", | ||
Ms: "Ms", | ||
Mrs: "Mrs", | ||
Dr: "Dr", | ||
}; | ||
main.Person = class { | ||
/** | ||
* Creates a new Person instance. | ||
* @constructor | ||
* @param {Object} source - The source object to create the Person. | ||
* @param {main.Title} source.Title | ||
* @param {string} source.Name | ||
*/ | ||
constructor(source = {}) { | ||
const { title = null, name = "" } = source; | ||
this.title = title; | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Creates a new Person instance from a string or object. | ||
* @param {string|object} source - The source data to create a Person instance from. | ||
* @returns main.Person A new Person instance. | ||
*/ | ||
static createFrom(source = {}) { | ||
let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; | ||
return new main.Person(parsedSource); | ||
} | ||
}; | ||
|
63 changes: 63 additions & 0 deletions
63
v3/internal/parser/testdata/function_from_imported_package/models.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// @ts-check | ||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL | ||
// This file is automatically generated. DO NOT EDIT | ||
|
||
// Defining the main namespace | ||
export const main = {}; | ||
|
||
main.Person = class { | ||
/** | ||
* Creates a new Person instance. | ||
* @constructor | ||
* @param {Object} source - The source object to create the Person. | ||
* @param {string} source.Name | ||
* @param {services.Address} source.Address | ||
*/ | ||
constructor(source = {}) { | ||
const { name = "", address = null } = source; | ||
this.name = name; | ||
this.address = address; | ||
} | ||
|
||
/** | ||
* Creates a new Person instance from a string or object. | ||
* @param {string|object} source - The source data to create a Person instance from. | ||
* @returns main.Person A new Person instance. | ||
*/ | ||
static createFrom(source = {}) { | ||
let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; | ||
return new main.Person(parsedSource); | ||
} | ||
}; | ||
|
||
|
||
// Defining the services namespace | ||
export const services = {}; | ||
|
||
services.Address = class { | ||
/** | ||
* Creates a new Address instance. | ||
* @constructor | ||
* @param {Object} source - The source object to create the Address. | ||
* @param {string} source.Street | ||
* @param {string} source.State | ||
* @param {string} source.Country | ||
*/ | ||
constructor(source = {}) { | ||
const { street = "", state = "", country = "" } = source; | ||
this.street = street; | ||
this.state = state; | ||
this.country = country; | ||
} | ||
|
||
/** | ||
* Creates a new Address instance from a string or object. | ||
* @param {string|object} source - The source data to create a Address instance from. | ||
* @returns services.Address A new Address instance. | ||
*/ | ||
static createFrom(source = {}) { | ||
let parsedSource = typeof source === 'string' ? JSON.parse(source) : source; | ||
return new services.Address(parsedSource); | ||
} | ||
}; | ||
|
Oops, something went wrong.