lupine.components 1.1.5 → 1.1.7
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/package.json +1 -1
- package/src/components/html-var.tsx +39 -12
package/package.json
CHANGED
|
@@ -6,26 +6,53 @@ export class HtmlVar implements HtmlVarResult {
|
|
|
6
6
|
private _value: string | VNode<any>;
|
|
7
7
|
private _dirty = false;
|
|
8
8
|
private _ref: RefProps;
|
|
9
|
+
private resolve!: () => void;
|
|
10
|
+
private promise: Promise<void>;
|
|
9
11
|
|
|
10
12
|
constructor(initial?: string | VNode<any>) {
|
|
13
|
+
this.promise = new Promise<void>((res) => {
|
|
14
|
+
this.resolve = res;
|
|
15
|
+
});
|
|
16
|
+
|
|
11
17
|
this._value = initial || '';
|
|
12
18
|
this._ref = {
|
|
13
19
|
onLoad: async (el: Element) => {
|
|
14
|
-
|
|
20
|
+
// in case new resolve is created while updating
|
|
21
|
+
const res = this.resolve;
|
|
22
|
+
if (this._dirty) {
|
|
23
|
+
await this.update();
|
|
24
|
+
}
|
|
25
|
+
res();
|
|
15
26
|
},
|
|
16
27
|
};
|
|
17
28
|
}
|
|
18
29
|
|
|
19
|
-
private async
|
|
20
|
-
|
|
21
|
-
await this._ref.mountInnerComponent!(value);
|
|
30
|
+
private async update(): Promise<void> {
|
|
31
|
+
await this._ref.mountInnerComponent!(this._value);
|
|
22
32
|
this._dirty = false;
|
|
33
|
+
this._value = '';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// need to wait before use ref.current
|
|
37
|
+
async waitUpdate() {
|
|
38
|
+
await this.promise;
|
|
23
39
|
}
|
|
24
40
|
|
|
25
41
|
set value(value: string | VNode<any>) {
|
|
26
42
|
this._value = value;
|
|
43
|
+
if (this._dirty) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
27
47
|
this._dirty = true;
|
|
28
|
-
this.
|
|
48
|
+
if (!this._ref.current) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.promise = new Promise<void>(async (res) => {
|
|
52
|
+
this.resolve = res;
|
|
53
|
+
await this.update();
|
|
54
|
+
this.resolve();
|
|
55
|
+
});
|
|
29
56
|
}
|
|
30
57
|
|
|
31
58
|
get value(): string | VNode<any> {
|
|
@@ -39,13 +66,13 @@ export class HtmlVar implements HtmlVarResult {
|
|
|
39
66
|
get node(): VNode<any> {
|
|
40
67
|
this._dirty = false;
|
|
41
68
|
// the Fragment Tag will be present in the html if ref is assigned
|
|
42
|
-
return {
|
|
43
|
-
type: 'Fragment',
|
|
44
|
-
props: {
|
|
45
|
-
ref: this._ref,
|
|
46
|
-
children: this._value
|
|
47
|
-
},
|
|
48
|
-
html: []
|
|
69
|
+
return {
|
|
70
|
+
type: 'Fragment',
|
|
71
|
+
props: {
|
|
72
|
+
ref: this._ref,
|
|
73
|
+
children: this._value,
|
|
74
|
+
},
|
|
75
|
+
html: [],
|
|
49
76
|
};
|
|
50
77
|
}
|
|
51
78
|
}
|