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

Configure Feed

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

feat: delay creation of rpc and consequently worker for custom elements

+24 -6
+24 -6
src/common/worker.js
··· 150 150 * @returns {ProxiedActions<Actions>} 151 151 */ 152 152 export function workerProxy(workerLinkCreator) { 153 - const io = new BrowserPostMessageIo(workerLinkCreator); 153 + /** @type {ProxiedActions<Actions> | undefined} */ 154 + let int_api; 155 + 156 + /** @returns {ProxiedActions<Actions>} */ 157 + function ensureAPI() { 158 + if (!int_api) { 159 + const io = new BrowserPostMessageIo(workerLinkCreator); 154 160 155 - /** @type {undefined | RPCChannel<{}, ProxiedActions<Actions>>} */ 156 - const rpc = new RPCChannel(io, { enableTransfer: true }); 161 + /** @type {undefined | RPCChannel<{}, ProxiedActions<Actions>>} */ 162 + const rpc = new RPCChannel(io, { enableTransfer: true }); 157 163 158 - /** @type {ProxiedActions<Actions>} */ 159 - const api = rpc.getAPI(); 160 - return api; 164 + int_api = rpc.getAPI(); 165 + } 166 + 167 + return int_api; 168 + } 169 + 170 + // Create proxy that creates RPC API when needed 171 + const proxy = new Proxy(() => {}, { 172 + get: (_target, prop) => { 173 + const api = ensureAPI(); 174 + return api[prop.toString()]; 175 + }, 176 + }); 177 + 178 + return /** @type {ProxiedActions<Actions>} */ (/** @type {any} */ (proxy)); 161 179 } 162 180 163 181 ////////////////////////////////////////////