A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: workerProxy

+7 -19
+7 -19
src/common/worker.js
··· 68 68 * @returns {ProxiedActions<Actions>} 69 69 */ 70 70 export function workerProxy(workerLinkCreator) { 71 - /** @type {ProxiedActions<Actions> | undefined} */ 72 - let int_api; 73 - 74 - /** @returns {ProxiedActions<Actions>} */ 75 - function ensureAPI() { 76 - if (!int_api) { 77 - /** @type {RpcChannel<Actions, Actions>} */ 78 - const channel = new RpcChannel(workerLinkCreator()); 79 - int_api = channel.getAPI(); 80 - } 81 - 82 - return int_api; 83 - } 71 + /** @type {RpcChannel<{}, Actions> | undefined} */ 72 + let channel; 84 73 85 - // Create proxy that creates RPC API when needed 86 - const proxy = new Proxy(() => {}, { 87 - get: (_target, prop) => { 74 + const proxy = new Proxy(/** @type {any} */ ({}), { 75 + get: (_target, /** @type {string} */ prop) => { 88 76 /** @param {Parameters<Actions[any]>} args */ 89 77 return (...args) => { 90 - const api = ensureAPI(); 91 - return api[prop.toString()](...args); 78 + channel ??= new RpcChannel(workerLinkCreator()); 79 + return channel.callMethod(prop, args); 92 80 }; 93 81 }, 94 82 }); 95 83 96 - return /** @type {ProxiedActions<Actions>} */ (/** @type {any} */ (proxy)); 84 + return /** @type {ProxiedActions<Actions>} */ (proxy); 97 85 } 98 86 99 87 /**