@esportsplus/template 0.26.4 → 0.26.6
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/build/slot/effect.js +13 -12
- package/build/slot/render.js +3 -3
- package/package.json +1 -1
- package/src/slot/effect.ts +17 -14
- package/src/slot/render.ts +3 -4
package/build/slot/effect.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import { effect } from '@esportsplus/reactivity';
|
|
2
|
-
import { STATE_HYDRATING, STATE_NONE } from '../constants.js';
|
|
3
2
|
import { firstChild, lastChild, nodeValue } from '../utilities/node.js';
|
|
4
3
|
import { raf } from '../utilities/queue.js';
|
|
5
4
|
import { remove } from './cleanup.js';
|
|
6
5
|
import text from '../utilities/text.js';
|
|
7
6
|
import render from './render.js';
|
|
7
|
+
function read(value) {
|
|
8
|
+
if (typeof value === 'function') {
|
|
9
|
+
return read(value());
|
|
10
|
+
}
|
|
11
|
+
if (value == null || value === false) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
8
16
|
class EffectSlot {
|
|
9
17
|
anchor;
|
|
10
18
|
disposer;
|
|
11
19
|
group = null;
|
|
12
20
|
textnode = null;
|
|
13
21
|
constructor(anchor, fn) {
|
|
14
|
-
let dispose = fn.length ? () => this.dispose() : undefined
|
|
22
|
+
let dispose = fn.length ? () => this.dispose() : undefined;
|
|
15
23
|
this.anchor = anchor;
|
|
16
24
|
this.disposer = effect(() => {
|
|
17
|
-
let value = fn(dispose);
|
|
18
|
-
if (
|
|
19
|
-
state = STATE_NONE;
|
|
25
|
+
let value = read(fn(dispose));
|
|
26
|
+
if (!this.disposer) {
|
|
20
27
|
this.update(value);
|
|
21
28
|
}
|
|
22
29
|
else {
|
|
@@ -45,13 +52,7 @@ class EffectSlot {
|
|
|
45
52
|
remove(group);
|
|
46
53
|
this.group = null;
|
|
47
54
|
}
|
|
48
|
-
if (
|
|
49
|
-
value = '';
|
|
50
|
-
}
|
|
51
|
-
if (typeof value === 'function') {
|
|
52
|
-
this.update(value());
|
|
53
|
-
}
|
|
54
|
-
else if (typeof value !== 'object') {
|
|
55
|
+
if (typeof value !== 'object') {
|
|
55
56
|
if (textnode) {
|
|
56
57
|
nodeValue.call(textnode, String(value));
|
|
57
58
|
if (!textnode.isConnected) {
|
package/build/slot/render.js
CHANGED
|
@@ -26,9 +26,9 @@ export default function render(anchor, value) {
|
|
|
26
26
|
return fragment;
|
|
27
27
|
}
|
|
28
28
|
if (value instanceof NodeList) {
|
|
29
|
-
let fragment = cloneNode.call(EMPTY_FRAGMENT)
|
|
30
|
-
for (let i = 0, n =
|
|
31
|
-
append.call(fragment,
|
|
29
|
+
let fragment = cloneNode.call(EMPTY_FRAGMENT);
|
|
30
|
+
for (let i = 0, n = value.length; i < n; i++) {
|
|
31
|
+
append.call(fragment, value[i]);
|
|
32
32
|
}
|
|
33
33
|
return fragment;
|
|
34
34
|
}
|
package/package.json
CHANGED
package/src/slot/effect.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { effect } from '@esportsplus/reactivity';
|
|
2
|
-
import { STATE_HYDRATING, STATE_NONE } from '~/constants';
|
|
3
2
|
import { Element, Renderable, SlotGroup } from '~/types';
|
|
4
3
|
import { firstChild, lastChild, nodeValue } from '~/utilities/node'
|
|
5
4
|
import { raf } from '~/utilities/queue'
|
|
@@ -8,6 +7,19 @@ import text from '~/utilities/text';
|
|
|
8
7
|
import render from './render';
|
|
9
8
|
|
|
10
9
|
|
|
10
|
+
function read(value: unknown): unknown {
|
|
11
|
+
if (typeof value === 'function') {
|
|
12
|
+
return read( value() );
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (value == null || value === false) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
11
23
|
class EffectSlot {
|
|
12
24
|
anchor: Element;
|
|
13
25
|
disposer: VoidFunction;
|
|
@@ -16,15 +28,13 @@ class EffectSlot {
|
|
|
16
28
|
|
|
17
29
|
|
|
18
30
|
constructor(anchor: Element, fn: (dispose?: VoidFunction) => Renderable<any>) {
|
|
19
|
-
let dispose = fn.length ? () => this.dispose() : undefined
|
|
20
|
-
state = STATE_HYDRATING;
|
|
31
|
+
let dispose = fn.length ? () => this.dispose() : undefined;
|
|
21
32
|
|
|
22
33
|
this.anchor = anchor;
|
|
23
34
|
this.disposer = effect(() => {
|
|
24
|
-
let value = fn(dispose);
|
|
35
|
+
let value = read( fn(dispose) );
|
|
25
36
|
|
|
26
|
-
if (
|
|
27
|
-
state = STATE_NONE;
|
|
37
|
+
if (!this.disposer) {
|
|
28
38
|
this.update(value);
|
|
29
39
|
}
|
|
30
40
|
else {
|
|
@@ -61,14 +71,7 @@ class EffectSlot {
|
|
|
61
71
|
this.group = null;
|
|
62
72
|
}
|
|
63
73
|
|
|
64
|
-
if (
|
|
65
|
-
value = '';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (typeof value === 'function') {
|
|
69
|
-
this.update( value() );
|
|
70
|
-
}
|
|
71
|
-
else if (typeof value !== 'object') {
|
|
74
|
+
if (typeof value !== 'object') {
|
|
72
75
|
if (textnode) {
|
|
73
76
|
nodeValue.call(textnode, String(value));
|
|
74
77
|
|
package/src/slot/render.ts
CHANGED
|
@@ -36,11 +36,10 @@ export default function render(anchor: Element, value: unknown): Node {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
if (value instanceof NodeList) {
|
|
39
|
-
let fragment = cloneNode.call(EMPTY_FRAGMENT)
|
|
40
|
-
nodes = Array.from(value as NodeList);
|
|
39
|
+
let fragment = cloneNode.call(EMPTY_FRAGMENT);
|
|
41
40
|
|
|
42
|
-
for (let i = 0, n =
|
|
43
|
-
append.call(fragment,
|
|
41
|
+
for (let i = 0, n = value.length; i < n; i++) {
|
|
42
|
+
append.call(fragment, value[i]);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
return fragment;
|