valyrian.js 7.2.1 → 7.2.2
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/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +32 -32
- package/dist/hooks/index.mjs +32 -32
- package/dist/signal/index.d.ts.map +1 -1
- package/dist/signal/index.js +25 -18
- package/dist/signal/index.mjs +26 -19
- package/lib/hooks/index.ts +38 -54
- package/lib/signal/index.ts +34 -22
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/hooks/index.ts"],"names":[],"mappings":"AAQA,oBAAY,IAAI,GAAG,GAAG,CAAC;AAEvB,MAAM,WAAW,cAAc;IAE7B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAElC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAE/C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;IAEhC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;IAE/B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;CACnC;AAED,MAAM,WAAW,UAAU;IAEzB,CAAC,cAAc,EAAE,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;CAC3D;AAED,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/hooks/index.ts"],"names":[],"mappings":"AAQA,oBAAY,IAAI,GAAG,GAAG,CAAC;AAEvB,MAAM,WAAW,cAAc;IAE7B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAElC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAE/C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;IAEhC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;IAE/B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;CACnC;AAED,MAAM,WAAW,UAAU;IAEzB,CAAC,cAAc,EAAE,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;CAC3D;AAED,eAAO,MAAM,UAAU,YAiEG,CAAC;AAS3B,eAAO,MAAM,QAAQ,YA7EyB,GAAG,EAAE,KAAK,GAgGtD,CAAC;AAGH,eAAO,MAAM,SAAS,YAnGwB,GAAG,EAAE,KAAK,GAuJtD,CAAC;AAEH,eAAO,MAAM,MAAM,YAzJ2B,GAAG,EAAE,KAAK,GAgKtD,CAAC;AAEH,eAAO,MAAM,WAAW,YAlKsB,GAAG,EAAE,KAAK,GAgLtD,CAAC;AAEH,eAAO,MAAM,OAAO,YAlL0B,GAAG,EAAE,KAAK,GAkMtD,CAAC"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -36,33 +36,31 @@ var createHook = function createHook2({
|
|
|
36
36
|
returnValue
|
|
37
37
|
}) {
|
|
38
38
|
return (...args) => {
|
|
39
|
-
let { component, vnode
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
vnode.components.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
let { component, vnode } = import_valyrian.current;
|
|
40
|
+
let hook = null;
|
|
41
|
+
if (vnode) {
|
|
42
|
+
if (!vnode.components) {
|
|
43
|
+
vnode.components = [];
|
|
44
|
+
}
|
|
45
|
+
if (vnode.components.indexOf(component) === -1) {
|
|
46
|
+
vnode.hook_calls = -1;
|
|
47
|
+
vnode.components.push(component);
|
|
48
|
+
if (!component.hooks) {
|
|
49
|
+
component.hooks = [];
|
|
50
|
+
(0, import_valyrian.onUnmount)(() => Reflect.deleteProperty(component, "hooks"));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
hook = component.hooks[++vnode.hook_calls];
|
|
50
54
|
}
|
|
51
|
-
|
|
52
|
-
if (!oldVnode || !oldVnode.components || oldVnode.components[vnode.components.length - 1] !== component) {
|
|
55
|
+
if (!hook) {
|
|
53
56
|
hook = onCreate(...args);
|
|
54
|
-
|
|
57
|
+
if (vnode) {
|
|
58
|
+
component.hooks.push(hook);
|
|
59
|
+
}
|
|
55
60
|
if (onRemove) {
|
|
56
61
|
(0, import_valyrian.onUnmount)(() => onRemove(hook));
|
|
57
62
|
}
|
|
58
63
|
} else {
|
|
59
|
-
if ("calls" in component === false) {
|
|
60
|
-
component.calls = -1;
|
|
61
|
-
(0, import_valyrian.onUnmount)(() => Reflect.deleteProperty(component, "calls"));
|
|
62
|
-
}
|
|
63
|
-
(0, import_valyrian.onCleanup)(() => component.calls = -1);
|
|
64
|
-
component.calls++;
|
|
65
|
-
hook = component.hooks[component.calls];
|
|
66
64
|
if (onUpdateHook) {
|
|
67
65
|
onUpdateHook(hook, ...args);
|
|
68
66
|
}
|
|
@@ -83,18 +81,20 @@ function delayedUpdate() {
|
|
|
83
81
|
}
|
|
84
82
|
var useState = createHook({
|
|
85
83
|
onCreate: (value) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
84
|
+
function get() {
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
get.value = value;
|
|
88
|
+
get.toJSON = get.valueOf = get;
|
|
89
|
+
get.toString = () => `${value}`;
|
|
90
|
+
function set(newValue) {
|
|
91
|
+
if (value !== newValue) {
|
|
92
|
+
value = newValue;
|
|
93
|
+
get.value = newValue;
|
|
94
|
+
delayedUpdate();
|
|
96
95
|
}
|
|
97
|
-
|
|
96
|
+
}
|
|
97
|
+
return [get, set];
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
var useEffect = createHook({
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -8,33 +8,31 @@ var createHook = function createHook2({
|
|
|
8
8
|
returnValue
|
|
9
9
|
}) {
|
|
10
10
|
return (...args) => {
|
|
11
|
-
let { component, vnode
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
vnode.components.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
let { component, vnode } = current;
|
|
12
|
+
let hook = null;
|
|
13
|
+
if (vnode) {
|
|
14
|
+
if (!vnode.components) {
|
|
15
|
+
vnode.components = [];
|
|
16
|
+
}
|
|
17
|
+
if (vnode.components.indexOf(component) === -1) {
|
|
18
|
+
vnode.hook_calls = -1;
|
|
19
|
+
vnode.components.push(component);
|
|
20
|
+
if (!component.hooks) {
|
|
21
|
+
component.hooks = [];
|
|
22
|
+
onUnmount(() => Reflect.deleteProperty(component, "hooks"));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
hook = component.hooks[++vnode.hook_calls];
|
|
22
26
|
}
|
|
23
|
-
|
|
24
|
-
if (!oldVnode || !oldVnode.components || oldVnode.components[vnode.components.length - 1] !== component) {
|
|
27
|
+
if (!hook) {
|
|
25
28
|
hook = onCreate(...args);
|
|
26
|
-
|
|
29
|
+
if (vnode) {
|
|
30
|
+
component.hooks.push(hook);
|
|
31
|
+
}
|
|
27
32
|
if (onRemove) {
|
|
28
33
|
onUnmount(() => onRemove(hook));
|
|
29
34
|
}
|
|
30
35
|
} else {
|
|
31
|
-
if ("calls" in component === false) {
|
|
32
|
-
component.calls = -1;
|
|
33
|
-
onUnmount(() => Reflect.deleteProperty(component, "calls"));
|
|
34
|
-
}
|
|
35
|
-
onCleanup(() => component.calls = -1);
|
|
36
|
-
component.calls++;
|
|
37
|
-
hook = component.hooks[component.calls];
|
|
38
36
|
if (onUpdateHook) {
|
|
39
37
|
onUpdateHook(hook, ...args);
|
|
40
38
|
}
|
|
@@ -55,18 +53,20 @@ function delayedUpdate() {
|
|
|
55
53
|
}
|
|
56
54
|
var useState = createHook({
|
|
57
55
|
onCreate: (value) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
function get() {
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
get.value = value;
|
|
60
|
+
get.toJSON = get.valueOf = get;
|
|
61
|
+
get.toString = () => `${value}`;
|
|
62
|
+
function set(newValue) {
|
|
63
|
+
if (value !== newValue) {
|
|
64
|
+
value = newValue;
|
|
65
|
+
get.value = newValue;
|
|
66
|
+
delayedUpdate();
|
|
68
67
|
}
|
|
69
|
-
|
|
68
|
+
}
|
|
69
|
+
return [get, set];
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
var useEffect = createHook({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signal/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,YAAY,KAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signal/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,YAAY,KAAA,OA+GlC"}
|
package/dist/signal/index.js
CHANGED
|
@@ -24,15 +24,22 @@ __export(signal_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(signal_exports);
|
|
25
25
|
var import_valyrian = require("valyrian.js");
|
|
26
26
|
function Signal(initialValue) {
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
if (!
|
|
30
|
-
|
|
31
|
-
context.vnode.calls = -1;
|
|
32
|
-
context.vnode.subscribers = context.oldVnode?.subscribers || [];
|
|
33
|
-
context.vnode.initialChildren = [...context.vnode.children];
|
|
27
|
+
const { vnode, oldVnode, component } = { ...import_valyrian.current };
|
|
28
|
+
if (vnode) {
|
|
29
|
+
if (!vnode.components) {
|
|
30
|
+
vnode.components = [];
|
|
34
31
|
}
|
|
35
|
-
|
|
32
|
+
if (vnode.components.indexOf(component) === -1) {
|
|
33
|
+
vnode.subscribers = oldVnode?.subscribers || [];
|
|
34
|
+
vnode.initialChildren = [...vnode.children];
|
|
35
|
+
vnode.signal_calls = -1;
|
|
36
|
+
vnode.components.push(component);
|
|
37
|
+
if (!component.signals) {
|
|
38
|
+
component.signals = [];
|
|
39
|
+
(0, import_valyrian.onUnmount)(() => Reflect.deleteProperty(component, "signals"));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let signal2 = component.signals[++vnode.signal_calls];
|
|
36
43
|
if (signal2) {
|
|
37
44
|
return signal2;
|
|
38
45
|
}
|
|
@@ -56,22 +63,22 @@ function Signal(initialValue) {
|
|
|
56
63
|
for (let i = 0, l = subscribers.length; i < l; i++) {
|
|
57
64
|
subscribers[i](value);
|
|
58
65
|
}
|
|
59
|
-
if (
|
|
60
|
-
let newVnode = (0, import_valyrian.v)(
|
|
61
|
-
newVnode.dom =
|
|
62
|
-
newVnode.isSVG =
|
|
63
|
-
|
|
66
|
+
if (vnode) {
|
|
67
|
+
let newVnode = (0, import_valyrian.v)(vnode.tag, vnode.props, ...vnode.initialChildren);
|
|
68
|
+
newVnode.dom = vnode.dom;
|
|
69
|
+
newVnode.isSVG = vnode.isSVG;
|
|
70
|
+
vnode.subscribers.forEach(
|
|
64
71
|
(subscribers2) => subscribers2.length = 0
|
|
65
72
|
);
|
|
66
|
-
|
|
67
|
-
return (0, import_valyrian.updateVnode)(newVnode,
|
|
73
|
+
vnode.subscribers = [];
|
|
74
|
+
return (0, import_valyrian.updateVnode)(newVnode, vnode);
|
|
68
75
|
}
|
|
69
76
|
return (0, import_valyrian.update)();
|
|
70
77
|
};
|
|
71
78
|
let signal = [get, set, subscribe];
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
if (vnode) {
|
|
80
|
+
component.signals.push(signal);
|
|
81
|
+
vnode.subscribers.push(subscribers);
|
|
75
82
|
}
|
|
76
83
|
return signal;
|
|
77
84
|
}
|
package/dist/signal/index.mjs
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
// lib/signal/index.ts
|
|
2
|
-
import { current, update, updateVnode, v } from "valyrian.js";
|
|
2
|
+
import { current, onUnmount, update, updateVnode, v } from "valyrian.js";
|
|
3
3
|
function Signal(initialValue) {
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
if (!
|
|
7
|
-
|
|
8
|
-
context.vnode.calls = -1;
|
|
9
|
-
context.vnode.subscribers = context.oldVnode?.subscribers || [];
|
|
10
|
-
context.vnode.initialChildren = [...context.vnode.children];
|
|
4
|
+
const { vnode, oldVnode, component } = { ...current };
|
|
5
|
+
if (vnode) {
|
|
6
|
+
if (!vnode.components) {
|
|
7
|
+
vnode.components = [];
|
|
11
8
|
}
|
|
12
|
-
|
|
9
|
+
if (vnode.components.indexOf(component) === -1) {
|
|
10
|
+
vnode.subscribers = oldVnode?.subscribers || [];
|
|
11
|
+
vnode.initialChildren = [...vnode.children];
|
|
12
|
+
vnode.signal_calls = -1;
|
|
13
|
+
vnode.components.push(component);
|
|
14
|
+
if (!component.signals) {
|
|
15
|
+
component.signals = [];
|
|
16
|
+
onUnmount(() => Reflect.deleteProperty(component, "signals"));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let signal2 = component.signals[++vnode.signal_calls];
|
|
13
20
|
if (signal2) {
|
|
14
21
|
return signal2;
|
|
15
22
|
}
|
|
@@ -33,22 +40,22 @@ function Signal(initialValue) {
|
|
|
33
40
|
for (let i = 0, l = subscribers.length; i < l; i++) {
|
|
34
41
|
subscribers[i](value);
|
|
35
42
|
}
|
|
36
|
-
if (
|
|
37
|
-
let newVnode = v(
|
|
38
|
-
newVnode.dom =
|
|
39
|
-
newVnode.isSVG =
|
|
40
|
-
|
|
43
|
+
if (vnode) {
|
|
44
|
+
let newVnode = v(vnode.tag, vnode.props, ...vnode.initialChildren);
|
|
45
|
+
newVnode.dom = vnode.dom;
|
|
46
|
+
newVnode.isSVG = vnode.isSVG;
|
|
47
|
+
vnode.subscribers.forEach(
|
|
41
48
|
(subscribers2) => subscribers2.length = 0
|
|
42
49
|
);
|
|
43
|
-
|
|
44
|
-
return updateVnode(newVnode,
|
|
50
|
+
vnode.subscribers = [];
|
|
51
|
+
return updateVnode(newVnode, vnode);
|
|
45
52
|
}
|
|
46
53
|
return update();
|
|
47
54
|
};
|
|
48
55
|
let signal = [get, set, subscribe];
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
if (vnode) {
|
|
57
|
+
component.signals.push(signal);
|
|
58
|
+
vnode.subscribers.push(subscribers);
|
|
52
59
|
}
|
|
53
60
|
return signal;
|
|
54
61
|
}
|
package/lib/hooks/index.ts
CHANGED
|
@@ -34,35 +34,37 @@ export const createHook = function createHook({
|
|
|
34
34
|
returnValue
|
|
35
35
|
}: HookDefinition): Hook {
|
|
36
36
|
return (...args: any[]) => {
|
|
37
|
-
let { component, vnode
|
|
37
|
+
let { component, vnode } = current as CurrentOnPatch;
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
if (!vnode.components) {
|
|
41
|
-
vnode.components = [];
|
|
42
|
-
onUnmount(() => Reflect.deleteProperty(vnode, "components"));
|
|
43
|
-
}
|
|
39
|
+
let hook = null;
|
|
44
40
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
vnode.components
|
|
48
|
-
|
|
41
|
+
if (vnode) {
|
|
42
|
+
// Init the components array for the current vnode
|
|
43
|
+
if (!vnode.components) {
|
|
44
|
+
vnode.components = [];
|
|
45
|
+
}
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
if (vnode.components.indexOf(component) === -1) {
|
|
48
|
+
vnode.hook_calls = -1;
|
|
49
|
+
vnode.components.push(component);
|
|
50
|
+
if (!component.hooks) {
|
|
51
|
+
component.hooks = [];
|
|
52
|
+
onUnmount(() => Reflect.deleteProperty(component, "hooks"));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
hook = component.hooks[++vnode.hook_calls];
|
|
57
|
+
}
|
|
57
58
|
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
if (!oldVnode || !oldVnode.components || oldVnode.components[vnode.components.length - 1] !== component) {
|
|
59
|
+
// If the hook doesn't exist, create it
|
|
60
|
+
if (!hook) {
|
|
61
61
|
// create a new hook
|
|
62
62
|
hook = onCreate(...args);
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
if (vnode) {
|
|
65
|
+
// Add the hook to the component
|
|
66
|
+
component.hooks.push(hook);
|
|
67
|
+
}
|
|
66
68
|
|
|
67
69
|
// if we have a onRemove hook, add it to the onUnmount set
|
|
68
70
|
if (onRemove) {
|
|
@@ -70,24 +72,6 @@ export const createHook = function createHook({
|
|
|
70
72
|
onUnmount(() => onRemove(hook));
|
|
71
73
|
}
|
|
72
74
|
} else {
|
|
73
|
-
// old vnode has components, we are updating the component
|
|
74
|
-
|
|
75
|
-
// Set the calls property to the current component if it's not already set
|
|
76
|
-
if ("calls" in component === false) {
|
|
77
|
-
component.calls = -1;
|
|
78
|
-
onUnmount(() => Reflect.deleteProperty(component, "calls"));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Reset the calls property to -1 on cleanup so we can detect if the component is updated again
|
|
82
|
-
onCleanup(() => (component.calls = -1));
|
|
83
|
-
|
|
84
|
-
// Increment the calls property
|
|
85
|
-
component.calls++;
|
|
86
|
-
|
|
87
|
-
// Get the current hook from the component's hooks array
|
|
88
|
-
hook = component.hooks[component.calls];
|
|
89
|
-
|
|
90
|
-
// If we have an onUpdate hook, call it
|
|
91
75
|
if (onUpdateHook) {
|
|
92
76
|
onUpdateHook(hook, ...args);
|
|
93
77
|
}
|
|
@@ -118,22 +102,22 @@ function delayedUpdate() {
|
|
|
118
102
|
// Use state hook
|
|
119
103
|
export const useState = createHook({
|
|
120
104
|
onCreate: (value) => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
delayedUpdate();
|
|
134
|
-
}
|
|
105
|
+
function get() {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
get.value = value;
|
|
109
|
+
get.toJSON = get.valueOf = get;
|
|
110
|
+
get.toString = () => `${value}`;
|
|
111
|
+
|
|
112
|
+
function set(newValue) {
|
|
113
|
+
if (value !== newValue) {
|
|
114
|
+
value = newValue;
|
|
115
|
+
get.value = newValue;
|
|
116
|
+
delayedUpdate();
|
|
135
117
|
}
|
|
136
|
-
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return [get, set];
|
|
137
121
|
}
|
|
138
122
|
});
|
|
139
123
|
|
package/lib/signal/index.ts
CHANGED
|
@@ -1,26 +1,38 @@
|
|
|
1
|
-
import { VnodeWithDom, current, update, updateVnode, v } from "valyrian.js";
|
|
1
|
+
import { VnodeWithDom, current, onUnmount, update, updateVnode, v } from "valyrian.js";
|
|
2
2
|
|
|
3
3
|
export function Signal(initialValue) {
|
|
4
4
|
// Create a copy of the current context object
|
|
5
|
-
const
|
|
5
|
+
const { vnode, oldVnode, component } = { ...current };
|
|
6
6
|
|
|
7
7
|
// Check if the context object has a vnode property
|
|
8
|
-
if (
|
|
8
|
+
if (vnode) {
|
|
9
9
|
// Is first call
|
|
10
|
-
if (!
|
|
11
|
-
// Set the
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
context.vnode.calls = -1;
|
|
15
|
-
// Set the subscribers property to the subscribers property of the oldVnode object, or an empty array if that doesn't exist
|
|
16
|
-
context.vnode.subscribers = context.oldVnode?.subscribers || [];
|
|
10
|
+
if (!vnode.components) {
|
|
11
|
+
// Set the components property to an empty array
|
|
12
|
+
vnode.components = [];
|
|
13
|
+
}
|
|
17
14
|
|
|
15
|
+
if (vnode.components.indexOf(component) === -1) {
|
|
16
|
+
// Set the subscribers property to the subscribers property of the oldVnode object, or an empty array if that doesn't exist
|
|
17
|
+
vnode.subscribers = oldVnode?.subscribers || [];
|
|
18
18
|
// Set the initialChildren property of the vnode object to a copy of the children array of the vnode object
|
|
19
|
-
|
|
19
|
+
vnode.initialChildren = [...vnode.children];
|
|
20
|
+
|
|
21
|
+
// Set the calls property to -1
|
|
22
|
+
vnode.signal_calls = -1;
|
|
23
|
+
// Add the component to the components array
|
|
24
|
+
vnode.components.push(component);
|
|
25
|
+
|
|
26
|
+
if (!component.signals) {
|
|
27
|
+
// Set the signals property of the component object to an empty array
|
|
28
|
+
component.signals = [];
|
|
29
|
+
// Add a function to the cleanup stack that removes the signals property from the component object
|
|
30
|
+
onUnmount(() => Reflect.deleteProperty(component, "signals"));
|
|
31
|
+
}
|
|
20
32
|
}
|
|
21
33
|
|
|
22
34
|
// Assign the signal variable to the signal stored at the index of the vnode object's calls property in the vnode's signals array
|
|
23
|
-
let signal =
|
|
35
|
+
let signal = component.signals[++vnode.signal_calls];
|
|
24
36
|
|
|
25
37
|
// If a signal has already been assigned to the signal variable, return it
|
|
26
38
|
if (signal) {
|
|
@@ -63,24 +75,24 @@ export function Signal(initialValue) {
|
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
// Check if the context object has a vnode property
|
|
66
|
-
if (
|
|
78
|
+
if (vnode) {
|
|
67
79
|
// If it does, create a new vnode object based on the original vnode, its children, and its DOM and SVG properties
|
|
68
|
-
let newVnode = v(
|
|
69
|
-
newVnode.dom =
|
|
70
|
-
newVnode.isSVG =
|
|
80
|
+
let newVnode = v(vnode.tag, vnode.props, ...vnode.initialChildren) as VnodeWithDom;
|
|
81
|
+
newVnode.dom = vnode.dom;
|
|
82
|
+
newVnode.isSVG = vnode.isSVG;
|
|
71
83
|
|
|
72
84
|
// Clear the subscribers array by setting the length property to 0
|
|
73
|
-
|
|
85
|
+
vnode.subscribers.forEach(
|
|
74
86
|
(subscribers) =>
|
|
75
87
|
// Setting the length property to 0 is faster than clearing the array with a loop
|
|
76
88
|
(subscribers.length = 0)
|
|
77
89
|
);
|
|
78
90
|
|
|
79
91
|
// Clear the subscribers array by setting it to an empty array
|
|
80
|
-
|
|
92
|
+
vnode.subscribers = [];
|
|
81
93
|
|
|
82
94
|
// Return the result of updating the original vnode with the new vnode
|
|
83
|
-
return updateVnode(newVnode,
|
|
95
|
+
return updateVnode(newVnode, vnode);
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
// If the context object doesn't have a vnode property, return the result of calling the update function
|
|
@@ -92,9 +104,9 @@ export function Signal(initialValue) {
|
|
|
92
104
|
|
|
93
105
|
// If the context object has a vnode property, add the signal to the vnode's signals array
|
|
94
106
|
// and add the subscribers array to the vnode's subscribers array
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
107
|
+
if (vnode) {
|
|
108
|
+
component.signals.push(signal);
|
|
109
|
+
vnode.subscribers.push(subscribers);
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
// Return the signal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valyrian.js",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.2",
|
|
4
4
|
"description": "Lightweight steel to forge PWAs. (Minimal Frontend Framework with server side rendering and other capabilities)",
|
|
5
5
|
"repository": "git@github.com:Masquerade-Circus/valyrian.js.git",
|
|
6
6
|
"author": "Masquerade <christian@masquerade-circus.net>",
|