mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 03:20:09 +08:00
Example bindings
This commit is contained in:
parent
00c458f948
commit
443ea46d1d
26
v3/examples/binding/bindings.js
Normal file
26
v3/examples/binding/bindings.js
Normal file
@ -0,0 +1,26 @@
|
||||
function GreetService(method) {
|
||||
return {
|
||||
packageName: "main",
|
||||
serviceName: "GreetService",
|
||||
methodName: method,
|
||||
args: Array.prototype.slice.call(arguments, 1),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* GreetService.Greet
|
||||
* Greet someone
|
||||
* @param name {string}
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
function Greet(name) {
|
||||
return wails.Call(GreetService("Greet", name));
|
||||
}
|
||||
|
||||
window.go = {
|
||||
main: {
|
||||
GreetService: {
|
||||
Greet,
|
||||
}
|
||||
}
|
||||
};
|
@ -37,6 +37,7 @@ export function callCallback(id, data, isJSON) {
|
||||
callResponses.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
export function callErrorCallback(id, message) {
|
||||
let p = callResponses.get(id);
|
||||
if (p) {
|
||||
@ -45,7 +46,7 @@ export function callErrorCallback(id, message) {
|
||||
}
|
||||
}
|
||||
|
||||
function dialog(type, options) {
|
||||
function callBinding(type, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let id = generateID();
|
||||
options = options || {};
|
||||
@ -60,6 +61,6 @@ function dialog(type, options) {
|
||||
|
||||
|
||||
export function Call(options) {
|
||||
return dialog("Call", options);
|
||||
return callBinding("Call", options);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user