UNPKG

buntralino

Version:

Bun library for Buntralino. Buntralino unites Bun and Neutralino.js to make a simpler, lighter alternative to Electron and NW.js. Use Neutralino.js API at client and send harder tasks to Bun while keeping your development process easy.

27 lines (25 loc) 777 B
type methodCall = (payload: any) => any; const methodsMap = new Map<string, methodCall>(); export const registerMethod = (name: string, method: methodCall) => { methodsMap.set(name, method); }; export const registerMethodMap = (methods: Record<string, methodCall> | Map<string, methodCall>) => { if (methods instanceof Map) { for (const [name, method] of methods) { registerMethod(name, method); } } else { for (const name in methods) { registerMethod(name, methods[name]); } } }; export const callMethod = (name: string, payload: unknown) => { const method = methodsMap.get(name); if (method) { return method(payload); } throw new Error(`Method "${name}" not found`); };