5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 11:29:29 +08:00
wails/v3/internal/parser/templates/model.ts.tmpl
Lea Anthony 2bb25b12ff
Update bindings generator to generate bindings in packages and files.
Remove unused JavaScript files
Update tests.
Update v3 docs
2023-12-22 20:01:42 +11:00

38 lines
1.2 KiB
Cheetah

{{- $pkg := .Package}}{{- range .Imports}}
import * as {{.PackageName}} from "{{.Path}}/models";{{- end}}
{{- range $enumindex, $enumdef := .Enums}}
{{- range $commentindex, $commentdef := $enumdef.DocComments}}
{{$commentdef -}}
{{- end}}
export enum {{$enumdef.Name}} {
{{- range $constindex, $constdef := .Consts}}
{{- if $constdef.DocComments}}
{{- range $commentindex, $commentdef := $constdef.DocComments}}
{{$commentdef -}}
{{- end }}
{{- end}}
{{$constdef.Name}} = {{$constdef.Value}},{{end}}
}
{{- end}}
{{range $name, $def := .Models}}
{{- if $def.DocComments}}
{{- range $commentindex, $commentdef := $def.DocComments}}
{{$commentdef -}}
{{- end }}
{{- end}}
export class {{$def.Name}} {
{{- range $def.Fields}}
{{.JSDef $pkg}}{{end}}
constructor(source: Partial<{{$def.Name}}> = {}) {
const { {{- $def.DefaultValueList -}} } = source;
{{- range $def.Fields}}
this.{{.JSName}} = {{.JSName}};{{end}}
}
static createFrom(source: string | object = {}): {{$def.Name}} {
let parsedSource = typeof source === 'string' ? JSON.parse(source) : source;
return new {{$def.Name}}(parsedSource as Partial<{{$def.Name}}>);
}
}
{{end}}