valyrian.js 7.1.2 → 7.2.1

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.
package/dist/index.mjs CHANGED
@@ -263,11 +263,12 @@ function directive(name, directive2) {
263
263
  }
264
264
  function sharedSetAttribute(name, value, newVnode, oldVnode) {
265
265
  if (typeof value === "function") {
266
- if (name in eventListenerNames === false) {
267
- mainVnode.dom.addEventListener(name.slice(2), eventListener);
268
- eventListenerNames[name] = true;
266
+ let lowercaseName = name.toLowerCase();
267
+ if (lowercaseName in eventListenerNames === false) {
268
+ mainVnode.dom.addEventListener(lowercaseName.slice(2), eventListener);
269
+ eventListenerNames[lowercaseName] = true;
269
270
  }
270
- newVnode.dom[`v-${name}`] = value;
271
+ newVnode.dom[`v-${lowercaseName}`] = value;
271
272
  return;
272
273
  }
273
274
  if (name in newVnode.dom && newVnode.isSVG === false) {
@@ -366,41 +367,18 @@ function patch(newVnode, oldVnode) {
366
367
  for (let i = 0; i < newTree.length; i++) {
367
368
  let newChild = newTree[i];
368
369
  if (newChild instanceof Vnode && newChild.tag !== textTag) {
369
- if (typeof newChild.tag !== "string") {
370
- current.component = newChild.tag;
371
- newTree.splice(
372
- i--,
373
- 1,
374
- ("view" in newChild.tag ? newChild.tag.view.bind(newChild.tag) : newChild.tag.bind(newChild.tag))(
375
- newChild.props,
376
- ...newChild.children
377
- )
378
- );
370
+ if (typeof newChild.tag === "string") {
379
371
  continue;
380
372
  }
381
- newChild.isSVG = newVnode.isSVG || newChild.tag === "svg";
382
- if (i < oldTreeLength) {
383
- let oldChild = oldTree[i];
384
- if (newChild.tag === oldChild.tag) {
385
- newChild.dom = oldChild.dom;
386
- if ("v-keep" in newChild.props && newChild.props["v-keep"] === oldChild.props["v-keep"]) {
387
- newChild.children = oldChild.children;
388
- continue;
389
- }
390
- updateAttributes(newChild, oldChild);
391
- patch(newChild, oldChild);
392
- continue;
393
- }
394
- newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
395
- updateAttributes(newChild);
396
- newVnode.dom.replaceChild(newChild.dom, oldChild.dom);
397
- patch(newChild);
398
- continue;
399
- }
400
- newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
401
- updateAttributes(newChild);
402
- newVnode.dom.appendChild(newChild.dom);
403
- patch(newChild);
373
+ current.component = newChild.tag;
374
+ newTree.splice(
375
+ i--,
376
+ 1,
377
+ ("view" in newChild.tag ? newChild.tag.view.bind(newChild.tag) : newChild.tag.bind(newChild.tag))(
378
+ newChild.props,
379
+ ...newChild.children
380
+ )
381
+ );
404
382
  continue;
405
383
  }
406
384
  if (Array.isArray(newChild)) {
@@ -411,26 +389,55 @@ function patch(newVnode, oldVnode) {
411
389
  newTree.splice(i--, 1);
412
390
  continue;
413
391
  }
414
- newTree[i] = new Vnode(textTag, {}, []);
415
392
  if (newChild instanceof Vnode) {
416
- newTree[i].dom = newChild.dom;
417
- newChild = newChild.dom.textContent;
393
+ newChild.children[0] = newChild.dom.textContent;
394
+ continue;
418
395
  }
396
+ newChild = newTree[i] = new Vnode(textTag, {}, [newChild]);
397
+ }
398
+ for (let i = 0; i < newTree.length; i++) {
399
+ let newChild = newTree[i];
400
+ if (newChild.tag === textTag) {
401
+ if (i < oldTreeLength) {
402
+ let oldChild = oldTree[i];
403
+ if (oldChild.tag === textTag) {
404
+ newChild.dom = oldChild.dom;
405
+ if (newChild.children[0] != oldChild.dom.textContent) {
406
+ oldChild.dom.textContent = newChild.children[0];
407
+ }
408
+ continue;
409
+ }
410
+ newChild.dom = document.createTextNode(newChild.children[0]);
411
+ newVnode.dom.replaceChild(newChild.dom, oldChild.dom);
412
+ continue;
413
+ }
414
+ newChild.dom = document.createTextNode(newChild.children[0]);
415
+ newVnode.dom.appendChild(newChild.dom);
416
+ continue;
417
+ }
418
+ newChild.isSVG = newVnode.isSVG || newChild.tag === "svg";
419
419
  if (i < oldTreeLength) {
420
420
  let oldChild = oldTree[i];
421
- if (oldChild.tag === textTag) {
422
- newTree[i].dom = oldChild.dom;
423
- if (newChild != oldChild.dom.textContent) {
424
- oldChild.dom.textContent = newChild;
421
+ if (newChild.tag === oldChild.tag) {
422
+ newChild.dom = oldChild.dom;
423
+ if ("v-keep" in newChild.props && newChild.props["v-keep"] === oldChild.props["v-keep"]) {
424
+ newChild.children = oldChild.children;
425
+ continue;
425
426
  }
427
+ updateAttributes(newChild, oldChild);
428
+ patch(newChild, oldChild);
426
429
  continue;
427
430
  }
428
- newTree[i].dom = document.createTextNode(newChild);
429
- newVnode.dom.replaceChild(newTree[i].dom, oldChild.dom);
431
+ newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
432
+ updateAttributes(newChild);
433
+ newVnode.dom.replaceChild(newChild.dom, oldChild.dom);
434
+ patch(newChild);
430
435
  continue;
431
436
  }
432
- newTree[i].dom = document.createTextNode(newChild);
433
- newVnode.dom.appendChild(newTree[i].dom);
437
+ newChild.dom = createDomElement(newChild.tag, newChild.isSVG);
438
+ updateAttributes(newChild);
439
+ newVnode.dom.appendChild(newChild.dom);
440
+ patch(newChild);
434
441
  }
435
442
  for (let i = newTree.length; i < oldTreeLength; i++) {
436
443
  newVnode.dom.removeChild(oldTree[i].dom);
@@ -454,6 +461,21 @@ function update() {
454
461
  }
455
462
  }
456
463
  }
464
+ function updateVnode(vnode, oldVnode) {
465
+ callSet(onCleanupSet);
466
+ patch(vnode, oldVnode);
467
+ oldVnode.tag = vnode.tag;
468
+ oldVnode.props = { ...vnode.props };
469
+ oldVnode.children = [...vnode.children];
470
+ callSet(isMounted ? onUpdateSet : onMountSet);
471
+ isMounted = true;
472
+ current.vnode = null;
473
+ current.oldVnode = null;
474
+ current.component = null;
475
+ if (isNodeJs) {
476
+ return vnode.dom.innerHTML;
477
+ }
478
+ }
457
479
  function unmount() {
458
480
  if (mainVnode) {
459
481
  mainComponent = new Vnode(() => null, {}, []);
@@ -508,5 +530,6 @@ export {
508
530
  unmount,
509
531
  update,
510
532
  updateAttributes,
533
+ updateVnode,
511
534
  v
512
535
  };
@@ -86,6 +86,7 @@ declare module "valyrian.js" {
86
86
  function updateAttributes(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
87
87
  function patch(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
88
88
  function update(): void | string;
89
+ function updateVnode(vnode: VnodeWithDom, oldVnode: VnodeWithDom): string | void;
89
90
  function unmount(): string | void;
90
91
  function mount(dom: any, component: any): string | void;
91
92
  const v: V;
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../lib/interfaces.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAiB,KAAK;QACpB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,GAAG,CAAC;QACZ,QAAQ,CAAC,EAAE;YACT,CAAC,KAAK,EAAE,cAAc,GAAG,KAAK,CAAC;SAChC,CAAC;QACF,QAAQ,CAAC,EAAE;YACT,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,GAAG,KAAK,CAAC;SAC1D,CAAC;QACF,QAAQ,CAAC,EAAE;YACT,CAAC,QAAQ,EAAE,cAAc,GAAG,KAAK,CAAC;SACnC,CAAC;QACF,YAAY,CAAC,EAAE;YACb,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,GAAG,SAAS,GAAG,OAAO,CAAC;SACxE,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KACtC;IACD,UAAiB,UAAW,SAAQ,OAAO;QACzC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB;IACD,UAAiB,cAAc;QAC7B,KAAK,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC;QAChG,GAAG,EAAE,MAAM,GAAG,SAA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I,CAAC;IACzC,SAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC;IACxD,MAAM,CAAC,EAAE,CAAC,CAAC;CACnB"}
@@ -0,0 +1,23 @@
1
+ interface Cleanup {
2
+ (): void;
3
+ }
4
+ interface Subscription {
5
+ (value: ProxySignal["value"]): void | Cleanup;
6
+ }
7
+ interface Getter {
8
+ (value: ProxySignal["value"]): any;
9
+ }
10
+ interface ProxySignal {
11
+ (): ProxySignal["value"];
12
+ (value: Subscription): ProxySignal;
13
+ (path: string, handler: (valueAtPathPosition: any) => any): ProxySignal["value"];
14
+ (path: string, value: any): ProxySignal["value"];
15
+ (value: any): ProxySignal["value"];
16
+ value: any;
17
+ cleanup: () => void;
18
+ getter: (name: string, handler: Getter) => any;
19
+ [key: string | number | symbol]: any;
20
+ }
21
+ export declare function ProxySignal(value: any): ProxySignal;
22
+ export {};
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/proxy-signal/index.ts"],"names":[],"mappings":"AAGA,UAAU,OAAO;IACf,IAAI,IAAI,CAAC;CACV;AAED,UAAU,YAAY;IAEpB,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC;CAC/C;AAID,UAAU,MAAM;IAEd,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC;CACpC;AAMD,UAAU,WAAW;IAEnB,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;IAGzB,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAAC;IAGnC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,mBAAmB,EAAE,GAAG,KAAK,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAGjF,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAGjD,CAAC,KAAK,EAAE,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAEnC,KAAK,EAAE,GAAG,CAAC;IAEX,OAAO,EAAE,MAAM,IAAI,CAAC;IAGpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,GAAG,CAAC;IAE/C,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CACtC;AAoCD,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,WAAW,CAuGnD"}
@@ -0,0 +1,136 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // lib/proxy-signal/index.ts
20
+ var proxy_signal_exports = {};
21
+ __export(proxy_signal_exports, {
22
+ ProxySignal: () => ProxySignal
23
+ });
24
+ module.exports = __toCommonJS(proxy_signal_exports);
25
+ var import_valyrian = require("valyrian.js");
26
+ function makeUnsubscribe(subscriptions, computed, handler, cleanup) {
27
+ if (typeof cleanup === "function") {
28
+ computed.cleanup = cleanup;
29
+ }
30
+ computed.unsubscribe = () => {
31
+ subscriptions.delete(handler);
32
+ computed?.cleanup();
33
+ };
34
+ }
35
+ function createSubscription(signal, subscriptions, handler) {
36
+ if (subscriptions.has(handler) === false) {
37
+ let computed = ProxySignal(() => handler(signal.value));
38
+ let cleanup = computed();
39
+ makeUnsubscribe(subscriptions, computed, handler, cleanup);
40
+ subscriptions.set(handler, computed);
41
+ }
42
+ return subscriptions.get(handler);
43
+ }
44
+ var updateTimeout;
45
+ function delayedUpdate() {
46
+ clearTimeout(updateTimeout);
47
+ updateTimeout = setTimeout(import_valyrian.update);
48
+ }
49
+ function ProxySignal(value) {
50
+ let subscriptions = /* @__PURE__ */ new Map();
51
+ let getters = {};
52
+ let forceUpdate = false;
53
+ let signal = new Proxy(
54
+ function(valOrPath, handler) {
55
+ if (typeof valOrPath === "undefined") {
56
+ return signal.value;
57
+ }
58
+ if (typeof valOrPath === "function") {
59
+ return createSubscription(signal, subscriptions, valOrPath);
60
+ }
61
+ if (typeof valOrPath === "string" && typeof handler !== "undefined") {
62
+ let parsed = valOrPath.split(".");
63
+ let result = signal.value;
64
+ let next;
65
+ while (parsed.length) {
66
+ next = parsed.shift();
67
+ if (parsed.length > 0) {
68
+ if (typeof result[next] !== "object") {
69
+ result[next] = {};
70
+ }
71
+ result = result[next];
72
+ } else {
73
+ result[next] = typeof handler === "function" ? handler(result[next]) : handler;
74
+ }
75
+ }
76
+ forceUpdate = true;
77
+ signal.value = signal.value;
78
+ return signal.value;
79
+ }
80
+ signal.value = valOrPath;
81
+ return signal.value;
82
+ },
83
+ {
84
+ set(state, prop, val) {
85
+ if (prop === "value" || prop === "unsubscribe" || prop === "cleanup") {
86
+ let old = state[prop];
87
+ state[prop] = val;
88
+ if (prop === "value" && (forceUpdate || val !== old)) {
89
+ forceUpdate = false;
90
+ for (let [handler, computed] of subscriptions) {
91
+ computed.cleanup();
92
+ let cleanup = handler(val);
93
+ makeUnsubscribe(subscriptions, computed, handler, cleanup);
94
+ }
95
+ delayedUpdate();
96
+ }
97
+ return true;
98
+ }
99
+ return false;
100
+ },
101
+ get(state, prop) {
102
+ if (prop === "value") {
103
+ return typeof state.value === "function" ? state.value() : state.value;
104
+ }
105
+ if (prop === "cleanup" || prop === "unsubscribe" || prop === "getter") {
106
+ return state[prop];
107
+ }
108
+ if (prop in getters) {
109
+ return getters[prop](state.value);
110
+ }
111
+ }
112
+ }
113
+ );
114
+ Object.defineProperties(signal, {
115
+ value: { value, writable: true, enumerable: true },
116
+ cleanup: {
117
+ value() {
118
+ for (let [handler, computed] of subscriptions) {
119
+ computed.unsubscribe();
120
+ }
121
+ },
122
+ writable: true,
123
+ enumerable: true
124
+ },
125
+ getter: {
126
+ value(name, handler) {
127
+ if (name in getters) {
128
+ throw new Error("Named computed already exists.");
129
+ }
130
+ getters[name] = handler;
131
+ },
132
+ enumerable: true
133
+ }
134
+ });
135
+ return signal;
136
+ }
@@ -0,0 +1,116 @@
1
+ // lib/proxy-signal/index.ts
2
+ import { update } from "valyrian.js";
3
+ function makeUnsubscribe(subscriptions, computed, handler, cleanup) {
4
+ if (typeof cleanup === "function") {
5
+ computed.cleanup = cleanup;
6
+ }
7
+ computed.unsubscribe = () => {
8
+ subscriptions.delete(handler);
9
+ computed?.cleanup();
10
+ };
11
+ }
12
+ function createSubscription(signal, subscriptions, handler) {
13
+ if (subscriptions.has(handler) === false) {
14
+ let computed = ProxySignal(() => handler(signal.value));
15
+ let cleanup = computed();
16
+ makeUnsubscribe(subscriptions, computed, handler, cleanup);
17
+ subscriptions.set(handler, computed);
18
+ }
19
+ return subscriptions.get(handler);
20
+ }
21
+ var updateTimeout;
22
+ function delayedUpdate() {
23
+ clearTimeout(updateTimeout);
24
+ updateTimeout = setTimeout(update);
25
+ }
26
+ function ProxySignal(value) {
27
+ let subscriptions = /* @__PURE__ */ new Map();
28
+ let getters = {};
29
+ let forceUpdate = false;
30
+ let signal = new Proxy(
31
+ function(valOrPath, handler) {
32
+ if (typeof valOrPath === "undefined") {
33
+ return signal.value;
34
+ }
35
+ if (typeof valOrPath === "function") {
36
+ return createSubscription(signal, subscriptions, valOrPath);
37
+ }
38
+ if (typeof valOrPath === "string" && typeof handler !== "undefined") {
39
+ let parsed = valOrPath.split(".");
40
+ let result = signal.value;
41
+ let next;
42
+ while (parsed.length) {
43
+ next = parsed.shift();
44
+ if (parsed.length > 0) {
45
+ if (typeof result[next] !== "object") {
46
+ result[next] = {};
47
+ }
48
+ result = result[next];
49
+ } else {
50
+ result[next] = typeof handler === "function" ? handler(result[next]) : handler;
51
+ }
52
+ }
53
+ forceUpdate = true;
54
+ signal.value = signal.value;
55
+ return signal.value;
56
+ }
57
+ signal.value = valOrPath;
58
+ return signal.value;
59
+ },
60
+ {
61
+ set(state, prop, val) {
62
+ if (prop === "value" || prop === "unsubscribe" || prop === "cleanup") {
63
+ let old = state[prop];
64
+ state[prop] = val;
65
+ if (prop === "value" && (forceUpdate || val !== old)) {
66
+ forceUpdate = false;
67
+ for (let [handler, computed] of subscriptions) {
68
+ computed.cleanup();
69
+ let cleanup = handler(val);
70
+ makeUnsubscribe(subscriptions, computed, handler, cleanup);
71
+ }
72
+ delayedUpdate();
73
+ }
74
+ return true;
75
+ }
76
+ return false;
77
+ },
78
+ get(state, prop) {
79
+ if (prop === "value") {
80
+ return typeof state.value === "function" ? state.value() : state.value;
81
+ }
82
+ if (prop === "cleanup" || prop === "unsubscribe" || prop === "getter") {
83
+ return state[prop];
84
+ }
85
+ if (prop in getters) {
86
+ return getters[prop](state.value);
87
+ }
88
+ }
89
+ }
90
+ );
91
+ Object.defineProperties(signal, {
92
+ value: { value, writable: true, enumerable: true },
93
+ cleanup: {
94
+ value() {
95
+ for (let [handler, computed] of subscriptions) {
96
+ computed.unsubscribe();
97
+ }
98
+ },
99
+ writable: true,
100
+ enumerable: true
101
+ },
102
+ getter: {
103
+ value(name, handler) {
104
+ if (name in getters) {
105
+ throw new Error("Named computed already exists.");
106
+ }
107
+ getters[name] = handler;
108
+ },
109
+ enumerable: true
110
+ }
111
+ });
112
+ return signal;
113
+ }
114
+ export {
115
+ ProxySignal
116
+ };
@@ -1,23 +1,2 @@
1
- interface Cleanup {
2
- (): void;
3
- }
4
- interface Subscription {
5
- (value: Signal["value"]): void | Cleanup;
6
- }
7
- interface Getter {
8
- (value: Signal["value"]): any;
9
- }
10
- interface Signal {
11
- (): Signal["value"];
12
- (value: Subscription): Signal;
13
- (path: string, handler: (valueAtPathPosition: any) => any): Signal["value"];
14
- (path: string, value: any): Signal["value"];
15
- (value: any): Signal["value"];
16
- value: any;
17
- cleanup: () => void;
18
- getter: (name: string, handler: Getter) => any;
19
- [key: string | number | symbol]: any;
20
- }
21
- export declare function Signal(value: any): Signal;
22
- export {};
1
+ export declare function Signal(initialValue: any): any;
23
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signal/index.ts"],"names":[],"mappings":"AAGA,UAAU,OAAO;IACf,IAAI,IAAI,CAAC;CACV;AAED,UAAU,YAAY;IAEpB,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC;CAC1C;AAID,UAAU,MAAM;IAEd,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC;CAC/B;AAMD,UAAU,MAAM;IAEd,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IAGpB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAAC;IAG9B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,mBAAmB,EAAE,GAAG,KAAK,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAG5E,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAG5C,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAE9B,KAAK,EAAE,GAAG,CAAC;IAEX,OAAO,EAAE,MAAM,IAAI,CAAC;IAGpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,GAAG,CAAC;IAE/C,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CACtC;AA+BD,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,CAuGzC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signal/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,YAAY,KAAA,OAmGlC"}
@@ -23,114 +23,55 @@ __export(signal_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(signal_exports);
25
25
  var import_valyrian = require("valyrian.js");
26
- function makeUnsubscribe(subscriptions, computed, handler, cleanup) {
27
- if (typeof cleanup === "function") {
28
- computed.cleanup = cleanup;
26
+ function Signal(initialValue) {
27
+ const context = { ...import_valyrian.current };
28
+ if (context.vnode) {
29
+ if (!context.vnode.signals) {
30
+ context.vnode.signals = context.oldVnode?.signals || [];
31
+ context.vnode.calls = -1;
32
+ context.vnode.subscribers = context.oldVnode?.subscribers || [];
33
+ context.vnode.initialChildren = [...context.vnode.children];
34
+ }
35
+ let signal2 = context.vnode.signals[++context.vnode.calls];
36
+ if (signal2) {
37
+ return signal2;
38
+ }
29
39
  }
30
- computed.unsubscribe = () => {
31
- subscriptions.delete(handler);
32
- computed?.cleanup();
40
+ let value = initialValue;
41
+ const subscribers = [];
42
+ const subscribe = (callback) => {
43
+ if (subscribers.indexOf(callback) === -1) {
44
+ subscribers.push(callback);
45
+ }
33
46
  };
34
- }
35
- function createSubscription(signal, subscriptions, handler) {
36
- if (subscriptions.has(handler) === false) {
37
- let computed = Signal(() => handler(signal.value));
38
- let cleanup = computed();
39
- makeUnsubscribe(subscriptions, computed, handler, cleanup);
40
- subscriptions.set(handler, computed);
47
+ function get() {
48
+ return value;
41
49
  }
42
- return subscriptions.get(handler);
43
- }
44
- var updateTimeout;
45
- function delayedUpdate() {
46
- clearTimeout(updateTimeout);
47
- updateTimeout = setTimeout(import_valyrian.update);
48
- }
49
- function Signal(value) {
50
- let subscriptions = /* @__PURE__ */ new Map();
51
- let getters = {};
52
- let forceUpdate = false;
53
- let signal = new Proxy(
54
- function(valOrPath, handler) {
55
- if (typeof valOrPath === "undefined") {
56
- return signal.value;
57
- }
58
- if (typeof valOrPath === "function") {
59
- return createSubscription(signal, subscriptions, valOrPath);
60
- }
61
- if (typeof valOrPath === "string" && typeof handler !== "undefined") {
62
- let parsed = valOrPath.split(".");
63
- let result = signal.value;
64
- let next;
65
- while (parsed.length) {
66
- next = parsed.shift();
67
- if (parsed.length > 0) {
68
- if (typeof result[next] !== "object") {
69
- result[next] = {};
70
- }
71
- result = result[next];
72
- } else {
73
- result[next] = typeof handler === "function" ? handler(result[next]) : handler;
74
- }
75
- }
76
- forceUpdate = true;
77
- signal.value = signal.value;
78
- return signal.value;
79
- }
80
- signal.value = valOrPath;
81
- return signal.value;
82
- },
83
- {
84
- set(state, prop, val) {
85
- if (prop === "value" || prop === "unsubscribe" || prop === "cleanup") {
86
- let old = state[prop];
87
- state[prop] = val;
88
- if (prop === "value" && (forceUpdate || val !== old)) {
89
- forceUpdate = false;
90
- for (let [handler, computed] of subscriptions) {
91
- computed.cleanup();
92
- let cleanup = handler(val);
93
- makeUnsubscribe(subscriptions, computed, handler, cleanup);
94
- }
95
- delayedUpdate();
96
- }
97
- return true;
98
- }
99
- return false;
100
- },
101
- get(state, prop) {
102
- if (prop === "value") {
103
- return typeof state.value === "function" ? state.value() : state.value;
104
- }
105
- if (prop === "cleanup" || prop === "unsubscribe" || prop === "getter") {
106
- return state[prop];
107
- }
108
- if (prop in getters) {
109
- return getters[prop](state.value);
110
- }
111
- }
50
+ get.value = value;
51
+ get.toJSON = get.valueOf = get;
52
+ get.toString = () => `${value}`;
53
+ const set = (newValue) => {
54
+ value = newValue;
55
+ get.value = value;
56
+ for (let i = 0, l = subscribers.length; i < l; i++) {
57
+ subscribers[i](value);
112
58
  }
113
- );
114
- Object.defineProperties(signal, {
115
- value: { value, writable: true, enumerable: true },
116
- cleanup: {
117
- value() {
118
- for (let [handler, computed] of subscriptions) {
119
- computed.unsubscribe();
120
- }
121
- },
122
- writable: true,
123
- enumerable: true
124
- },
125
- getter: {
126
- value(name, handler) {
127
- if (name in getters) {
128
- throw new Error("Named computed already exists.");
129
- }
130
- getters[name] = handler;
131
- },
132
- enumerable: true
59
+ if (context.vnode) {
60
+ let newVnode = (0, import_valyrian.v)(context.vnode.tag, context.vnode.props, ...context.vnode.initialChildren);
61
+ newVnode.dom = context.vnode.dom;
62
+ newVnode.isSVG = context.vnode.isSVG;
63
+ context.vnode.subscribers.forEach(
64
+ (subscribers2) => subscribers2.length = 0
65
+ );
66
+ context.vnode.subscribers = [];
67
+ return (0, import_valyrian.updateVnode)(newVnode, context.vnode);
133
68
  }
134
- });
69
+ return (0, import_valyrian.update)();
70
+ };
71
+ let signal = [get, set, subscribe];
72
+ if (context.vnode) {
73
+ context.vnode.signals.push(signal);
74
+ context.vnode.subscribers.push(subscribers);
75
+ }
135
76
  return signal;
136
77
  }