@nordcraft/runtime 1.0.69 → 1.0.70
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/components/createElement.js +6 -17
- package/dist/components/createElement.js.map +1 -1
- package/dist/custom-element.main.esm.js +17 -17
- package/dist/custom-element.main.esm.js.map +3 -3
- package/dist/page.main.esm.js +3 -3
- package/dist/page.main.esm.js.map +3 -3
- package/dist/signal/signal.d.ts +1 -0
- package/dist/signal/signal.js +19 -8
- package/dist/signal/signal.js.map +1 -1
- package/package.json +3 -3
- package/src/components/createElement.ts +6 -18
- package/src/signal/signal.ts +20 -8
package/dist/signal/signal.d.ts
CHANGED
package/dist/signal/signal.js
CHANGED
|
@@ -3,6 +3,7 @@ export class Signal {
|
|
|
3
3
|
value;
|
|
4
4
|
subscribers;
|
|
5
5
|
subscriptions;
|
|
6
|
+
destroying = false;
|
|
6
7
|
constructor(value) {
|
|
7
8
|
this.value = value;
|
|
8
9
|
this.subscribers = new Set();
|
|
@@ -19,7 +20,9 @@ export class Signal {
|
|
|
19
20
|
}
|
|
20
21
|
if (fastDeepEqual(value, this.value) === false) {
|
|
21
22
|
this.value = value;
|
|
22
|
-
|
|
23
|
+
for (const subscriber of this.subscribers) {
|
|
24
|
+
subscriber.notify(this.value);
|
|
25
|
+
}
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
update(f) {
|
|
@@ -34,17 +37,25 @@ export class Signal {
|
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
39
|
destroy() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
// Prevent re-entrancy
|
|
41
|
+
if (this.destroying) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.destroying = true;
|
|
45
|
+
for (const subscriber of this.subscribers) {
|
|
46
|
+
subscriber.destroy?.();
|
|
47
|
+
}
|
|
40
48
|
this.subscribers.clear();
|
|
41
|
-
this.subscriptions
|
|
49
|
+
for (const subscription of this.subscriptions) {
|
|
50
|
+
subscription();
|
|
51
|
+
}
|
|
42
52
|
this.subscriptions.splice(0, this.subscriptions.length);
|
|
53
|
+
this.destroying = false;
|
|
43
54
|
}
|
|
44
55
|
cleanSubscribers() {
|
|
45
|
-
this.subscribers
|
|
46
|
-
destroy?.();
|
|
47
|
-
}
|
|
56
|
+
for (const subscriber of this.subscribers) {
|
|
57
|
+
subscriber.destroy?.();
|
|
58
|
+
}
|
|
48
59
|
this.subscribers.clear();
|
|
49
60
|
}
|
|
50
61
|
map(f) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signal.js","sourceRoot":"","sources":["../../src/signal/signal.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAE3C,MAAM,OAAO,MAAM;IACjB,KAAK,CAAG;IACR,WAAW,CAGT;IACF,aAAa,CAAmB;
|
|
1
|
+
{"version":3,"file":"signal.js","sourceRoot":"","sources":["../../src/signal/signal.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAE3C,MAAM,OAAO,MAAM;IACjB,KAAK,CAAG;IACR,WAAW,CAGT;IACF,aAAa,CAAmB;IAChC,UAAU,GAAG,KAAK,CAAA;IAElB,YAAY,KAAQ;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAA;QAC5B,IAAI,CAAC,aAAa,GAAG,EAAE,CAAA;IACzB,CAAC;IACD,GAAG;QACD,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IACD,GAAG,CAAC,KAAQ;QACV,0FAA0F;QAC1F,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;YAClB,OAAM;QACR,CAAC;QAED,IAAI,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CA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AgB;QACd,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC1C,UAAU,CAAC,OAAO,EAAE,EAAE,CAAA;QACxB,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;IAC1B,CAAC;IACD,GAAG,CAAK,CAAmB;QACzB,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QACrC,OAAO,CAAC,aAAa,CAAC,IAAI,CACxB,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE;YAC/C,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;SACjC,CAAC,CACH,CAAA;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AAED,MAAM,UAAU,MAAM,CAAI,KAAQ;IAChC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAA;AAC1B,CAAC;AAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,CAAC;IAAC,MAAc,CAAC,MAAM,GAAG,MAAM,CAC/B;IAAC,MAAc,CAAC,SAAS,GAAG,aAAa,CAAA;AAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://github.com/nordcraftengine/nordcraft",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@nordcraft/core": "1.0.
|
|
8
|
-
"@nordcraft/std-lib": "1.0.
|
|
7
|
+
"@nordcraft/core": "1.0.70",
|
|
8
|
+
"@nordcraft/std-lib": "1.0.70",
|
|
9
9
|
"fast-deep-equal": "3.1.3",
|
|
10
10
|
"path-to-regexp": "6.3.0"
|
|
11
11
|
},
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"files": ["dist", "src"],
|
|
22
22
|
"main": "dist/page.main.js",
|
|
23
23
|
"types": "dist/page.main.d.ts",
|
|
24
|
-
"version": "1.0.
|
|
24
|
+
"version": "1.0.70"
|
|
25
25
|
}
|
|
@@ -272,15 +272,6 @@ export function createElement({
|
|
|
272
272
|
.join('')
|
|
273
273
|
})
|
|
274
274
|
})
|
|
275
|
-
|
|
276
|
-
dataSignal.subscribe(() => {}, {
|
|
277
|
-
destroy: () => {
|
|
278
|
-
eventHandlers.forEach(([eventName, handler]) => {
|
|
279
|
-
elem.removeEventListener(eventName, handler)
|
|
280
|
-
})
|
|
281
|
-
elem.remove()
|
|
282
|
-
},
|
|
283
|
-
})
|
|
284
275
|
} else {
|
|
285
276
|
const childNodes: (Element | Text)[] = []
|
|
286
277
|
node.children.forEach((child, i) => {
|
|
@@ -297,16 +288,13 @@ export function createElement({
|
|
|
297
288
|
)
|
|
298
289
|
})
|
|
299
290
|
elem.append(...childNodes)
|
|
300
|
-
dataSignal.subscribe(() => {}, {
|
|
301
|
-
destroy: () => {
|
|
302
|
-
eventHandlers.forEach(([eventName, handler]) => {
|
|
303
|
-
elem.removeEventListener(eventName, handler)
|
|
304
|
-
})
|
|
305
|
-
childNodes.forEach((childNode) => childNode.remove())
|
|
306
|
-
elem.remove()
|
|
307
|
-
},
|
|
308
|
-
})
|
|
309
291
|
}
|
|
292
|
+
dataSignal.subscribe(() => {}, {
|
|
293
|
+
destroy: () => {
|
|
294
|
+
// TODO: Clean up event listeners, but after destruction of child signals (Maybe we need a "afterDestroy" hook on signals?)
|
|
295
|
+
elem.parentNode?.removeChild(elem)
|
|
296
|
+
},
|
|
297
|
+
})
|
|
310
298
|
|
|
311
299
|
return elem
|
|
312
300
|
}
|
package/src/signal/signal.ts
CHANGED
|
@@ -7,6 +7,7 @@ export class Signal<T> {
|
|
|
7
7
|
destroy?: () => void
|
|
8
8
|
}>
|
|
9
9
|
subscriptions: Array<() => void>
|
|
10
|
+
destroying = false
|
|
10
11
|
|
|
11
12
|
constructor(value: T) {
|
|
12
13
|
this.value = value
|
|
@@ -25,7 +26,9 @@ export class Signal<T> {
|
|
|
25
26
|
|
|
26
27
|
if (fastDeepEqual(value, this.value) === false) {
|
|
27
28
|
this.value = value
|
|
28
|
-
|
|
29
|
+
for (const subscriber of this.subscribers) {
|
|
30
|
+
subscriber.notify(this.value)
|
|
31
|
+
}
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
|
|
@@ -41,17 +44,26 @@ export class Signal<T> {
|
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
destroy() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
// Prevent re-entrancy
|
|
48
|
+
if (this.destroying) {
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.destroying = true
|
|
53
|
+
for (const subscriber of this.subscribers) {
|
|
54
|
+
subscriber.destroy?.()
|
|
55
|
+
}
|
|
47
56
|
this.subscribers.clear()
|
|
48
|
-
this.subscriptions
|
|
57
|
+
for (const subscription of this.subscriptions) {
|
|
58
|
+
subscription()
|
|
59
|
+
}
|
|
49
60
|
this.subscriptions.splice(0, this.subscriptions.length)
|
|
61
|
+
this.destroying = false
|
|
50
62
|
}
|
|
51
63
|
cleanSubscribers() {
|
|
52
|
-
this.subscribers
|
|
53
|
-
destroy?.()
|
|
54
|
-
}
|
|
64
|
+
for (const subscriber of this.subscribers) {
|
|
65
|
+
subscriber.destroy?.()
|
|
66
|
+
}
|
|
55
67
|
this.subscribers.clear()
|
|
56
68
|
}
|
|
57
69
|
map<T2>(f: (value: T) => T2): Signal<T2> {
|