svelte-realtime 0.4.17 → 0.4.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server.js +20 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-realtime",
3
- "version": "0.4.17",
3
+ "version": "0.4.18",
4
4
  "description": "Realtime RPC and reactive subscriptions for SvelteKit, built on svelte-adapter-uws",
5
5
  "author": "Kevin Radziszewski",
6
6
  "license": "MIT",
package/server.js CHANGED
@@ -1369,8 +1369,24 @@ export function __registerDerived(path, fn) {
1369
1369
  if (/** @type {any} */ (fn).__derivedDynamic) {
1370
1370
  const sourceFactory = /** @type {any} */ (fn).__derivedSourceFactory;
1371
1371
  const debounce = /** @type {any} */ (fn).__derivedDebounce || 0;
1372
+
1373
+ /** @type {Map<string, any[]>} */
1374
+ const topicArgs = new Map();
1375
+ const topicFn = (...args) => {
1376
+ const t = path + '\x00' + args.map(a => String(a).replace(/\x00/g, '')).join('\x00');
1377
+ topicArgs.set(t, args);
1378
+ if (topicArgs.size > 10000) {
1379
+ const iter = topicArgs.keys();
1380
+ topicArgs.delete(iter.next().value);
1381
+ }
1382
+ return t;
1383
+ };
1384
+ /** @type {any} */ (topicFn).__topicUsesCtx = false;
1385
+ /** @type {any} */ (fn).__streamTopic = topicFn;
1386
+ /** @type {any} */ (fn).__derivedTopicArgs = topicArgs;
1387
+
1372
1388
  const entry = {
1373
- sources: null, sourceFactory, fn, topic: /** @type {any} */ (fn).__streamTopic,
1389
+ sources: null, sourceFactory, fn, topic: topicFn,
1374
1390
  debounce, timer: null, dynamic: true, instances: new Map()
1375
1391
  };
1376
1392
  derivedRegistry.set(path, entry);
@@ -1379,11 +1395,11 @@ export function __registerDerived(path, fn) {
1379
1395
  return;
1380
1396
  }
1381
1397
 
1398
+ /** @type {any} */ (fn).__streamTopic = path;
1382
1399
  const sources = /** @type {any} */ (fn).__derivedSources;
1383
- const topic = /** @type {any} */ (fn).__streamTopic;
1384
1400
  const debounce = /** @type {any} */ (fn).__derivedDebounce || 0;
1385
- if (!sources || !topic) return;
1386
- derivedRegistry.set(path, { sources, fn, topic, debounce, timer: null });
1401
+ if (!sources) return;
1402
+ derivedRegistry.set(path, { sources, fn, topic: path, debounce, timer: null });
1387
1403
  for (const src of sources) {
1388
1404
  let set = _derivedBySource.get(src);
1389
1405
  if (!set) { set = new Set(); _derivedBySource.set(src, set); }