Files

68 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2021-08-13 23:44:24 +10:00
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The electron alternative for Go
2021-08-13 23:44:24 +10:00
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
import {Call} from './calls';
2021-08-13 23:44:24 +10:00
2021-09-09 20:10:18 +10:00
// This is where we bind go method wrappers
2021-09-01 20:52:34 +10:00
window.go = {};
2021-08-13 23:44:24 +10:00
export function SetBindings(bindingsMap) {
try {
bindingsMap = JSON.parse(bindingsMap);
} catch (e) {
console.error(e);
}
2021-09-01 20:52:34 +10:00
// Initialise the bindings map
window.go = window.go || {};
2021-08-13 23:44:24 +10:00
// Iterate package names
Object.keys(bindingsMap).forEach((packageName) => {
// Create inner map if it doesn't exist
2021-09-01 20:52:34 +10:00
window.go[packageName] = window.go[packageName] || {};
2021-08-13 23:44:24 +10:00
// Iterate struct names
Object.keys(bindingsMap[packageName]).forEach((structName) => {
// Create inner map if it doesn't exist
2021-09-01 20:52:34 +10:00
window.go[packageName][structName] = window.go[packageName][structName] || {};
2021-08-13 23:44:24 +10:00
Object.keys(bindingsMap[packageName][structName]).forEach((methodName) => {
2021-09-01 20:52:34 +10:00
window.go[packageName][structName][methodName] = function () {
2021-08-13 23:44:24 +10:00
// No timeout by default
let timeout = 0;
// Actual function
function dynamic() {
const args = [].slice.call(arguments);
return Call([packageName, structName, methodName].join('.'), args, timeout);
}
// Allow setting timeout to function
dynamic.setTimeout = function (newTimeout) {
timeout = newTimeout;
};
// Allow getting timeout to function
dynamic.getTimeout = function () {
return timeout;
};
return dynamic;
}();
});
});
});
}