@esportsplus/template 0.22.5 → 0.23.0
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.d.ts +2 -2
- package/build/slot/effect.js +15 -3
- package/package.json +1 -1
- package/src/slot/effect.ts +29 -13
package/build/slot/effect.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Element } from '../types.js';
|
|
2
|
-
declare const _default: (anchor: Element, fn:
|
|
1
|
+
import { Element, Renderable } from '../types.js';
|
|
2
|
+
declare const _default: (anchor: Element, fn: (dispose?: VoidFunction) => Renderable<any>) => void;
|
|
3
3
|
export default _default;
|
package/build/slot/effect.js
CHANGED
|
@@ -43,9 +43,21 @@ export default (anchor, fn) => {
|
|
|
43
43
|
let context = {
|
|
44
44
|
group: undefined,
|
|
45
45
|
textnode: undefined
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
}, dispose = fn.length ? () => {
|
|
47
|
+
let { group, textnode } = context;
|
|
48
|
+
if (textnode) {
|
|
49
|
+
group = { head: anchor, tail: textnode };
|
|
50
|
+
}
|
|
51
|
+
else if (group) {
|
|
52
|
+
group.head = anchor;
|
|
53
|
+
}
|
|
54
|
+
d();
|
|
55
|
+
if (group) {
|
|
56
|
+
remove([group]);
|
|
57
|
+
}
|
|
58
|
+
} : undefined, state = STATE_HYDRATING;
|
|
59
|
+
let d = effect(() => {
|
|
60
|
+
let value = fn(dispose);
|
|
49
61
|
if (state === STATE_HYDRATING) {
|
|
50
62
|
update.call(context, anchor, value);
|
|
51
63
|
state = STATE_NONE;
|
package/package.json
CHANGED
package/src/slot/effect.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { effect } from '@esportsplus/reactivity';
|
|
2
2
|
import { STATE_HYDRATING, STATE_NONE } from '~/constants';
|
|
3
|
-
import { Element, SlotGroup } from '~/types';
|
|
3
|
+
import { Element, Renderable, SlotGroup } from '~/types';
|
|
4
4
|
import { firstChild, lastChild, nodeValue } from '~/utilities/node'
|
|
5
5
|
import { raf } from '~/utilities/queue'
|
|
6
6
|
import { remove } from './cleanup';
|
|
@@ -52,24 +52,40 @@ function update(this: { group?: SlotGroup, textnode?: Node }, anchor: Element, v
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
export default (anchor: Element, fn:
|
|
55
|
+
export default (anchor: Element, fn: (dispose?: VoidFunction) => Renderable<any>) => {
|
|
56
56
|
let context = {
|
|
57
57
|
group: undefined as SlotGroup | undefined,
|
|
58
58
|
textnode: undefined as Node | undefined
|
|
59
59
|
},
|
|
60
|
+
dispose = fn.length ? () => {
|
|
61
|
+
let { group, textnode } = context;
|
|
62
|
+
|
|
63
|
+
if (textnode) {
|
|
64
|
+
group = { head: anchor, tail: textnode as Element };
|
|
65
|
+
}
|
|
66
|
+
else if (group) {
|
|
67
|
+
group.head = anchor;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
d();
|
|
71
|
+
|
|
72
|
+
if (group) {
|
|
73
|
+
remove([group]);
|
|
74
|
+
}
|
|
75
|
+
} : undefined,
|
|
60
76
|
state = STATE_HYDRATING;
|
|
61
77
|
|
|
62
|
-
effect(() => {
|
|
63
|
-
|
|
78
|
+
let d = effect(() => {
|
|
79
|
+
let value = fn(dispose);
|
|
64
80
|
|
|
65
|
-
|
|
66
|
-
update.call(context, anchor, value);
|
|
67
|
-
state = STATE_NONE;
|
|
68
|
-
}
|
|
69
|
-
else if (state === STATE_NONE) {
|
|
70
|
-
raf.add(() => {
|
|
81
|
+
if (state === STATE_HYDRATING) {
|
|
71
82
|
update.call(context, anchor, value);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
state = STATE_NONE;
|
|
84
|
+
}
|
|
85
|
+
else if (state === STATE_NONE) {
|
|
86
|
+
raf.add(() => {
|
|
87
|
+
update.call(context, anchor, value);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
75
91
|
};
|