rask-ui 0.3.3 → 0.3.4
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/component.d.ts +3 -2
- package/dist/component.d.ts.map +1 -1
- package/dist/component.js +46 -27
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -8,15 +8,16 @@ declare class RaskComponent<P extends Props<any>> extends Component<P & {
|
|
|
8
8
|
}> {
|
|
9
9
|
private renderFn?;
|
|
10
10
|
private reactiveProps?;
|
|
11
|
-
private prevChildren;
|
|
12
11
|
private observer;
|
|
13
|
-
private
|
|
12
|
+
private isRendering;
|
|
14
13
|
contexts: Map<any, any>;
|
|
15
14
|
getChildContext(): any;
|
|
16
15
|
onMounts: Array<() => void>;
|
|
17
16
|
onCleanups: Array<() => void>;
|
|
17
|
+
private createReactiveProps;
|
|
18
18
|
componentDidMount(): void;
|
|
19
19
|
componentWillUnmount(): void;
|
|
20
|
+
componentDidUpdate(): void;
|
|
20
21
|
shouldComponentUpdate(nextProps: Props<any>): boolean;
|
|
21
22
|
render(): any;
|
|
22
23
|
}
|
package/dist/component.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,EACL,SAAS,EACT,KAAK,EAEN,MAAM,SAAS,CAAC;AAMjB,wBAAgB,mBAAmB,uBAMlC;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,IAAI,QAMrC;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,QAMvC;AAED,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,IAClD,CAAC,MAAM,MAAM,KAAK,CAAC,GACnB,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC;AAEhC,cAAM,aAAa,CAAC,CAAC,SA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CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO;IAerD,MAAM;CAyCP;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,SAO9D"}
|
package/dist/component.js
CHANGED
|
@@ -22,11 +22,10 @@ export function onCleanup(cb) {
|
|
|
22
22
|
class RaskComponent extends Component {
|
|
23
23
|
renderFn;
|
|
24
24
|
reactiveProps;
|
|
25
|
-
prevChildren;
|
|
26
25
|
observer = new Observer(() => {
|
|
27
26
|
this.forceUpdate();
|
|
28
27
|
});
|
|
29
|
-
|
|
28
|
+
isRendering = false;
|
|
30
29
|
contexts = new Map();
|
|
31
30
|
getChildContext() {
|
|
32
31
|
const parentGetContext = this.context.getContext;
|
|
@@ -39,25 +38,65 @@ class RaskComponent extends Component {
|
|
|
39
38
|
}
|
|
40
39
|
onMounts = [];
|
|
41
40
|
onCleanups = [];
|
|
41
|
+
createReactiveProps() {
|
|
42
|
+
const reactiveProps = {};
|
|
43
|
+
const self = this;
|
|
44
|
+
for (const prop in this.props) {
|
|
45
|
+
const signal = new Signal();
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
let reactiveValue = this.props[prop];
|
|
48
|
+
Object.defineProperty(reactiveProps, prop, {
|
|
49
|
+
get() {
|
|
50
|
+
if (!self.isRendering) {
|
|
51
|
+
const observer = getCurrentObserver();
|
|
52
|
+
if (observer) {
|
|
53
|
+
observer.subscribeSignal(signal);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
return self.props[prop];
|
|
58
|
+
},
|
|
59
|
+
set(value) {
|
|
60
|
+
if (reactiveValue !== value) {
|
|
61
|
+
reactiveValue = value;
|
|
62
|
+
signal.notify();
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return reactiveProps;
|
|
68
|
+
}
|
|
42
69
|
componentDidMount() {
|
|
43
70
|
this.onMounts.forEach((cb) => cb());
|
|
44
71
|
}
|
|
45
72
|
componentWillUnmount() {
|
|
46
73
|
this.onCleanups.forEach((cb) => cb());
|
|
47
74
|
}
|
|
75
|
+
componentDidUpdate() {
|
|
76
|
+
for (const prop in this.props) {
|
|
77
|
+
if (prop === "__component" || prop === "children") {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
this.reactiveProps[prop] = this.props[prop];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
48
84
|
shouldComponentUpdate(nextProps) {
|
|
85
|
+
// Shallow comparison of props, excluding internal props
|
|
49
86
|
for (const prop in nextProps) {
|
|
50
87
|
if (prop === "__component") {
|
|
51
88
|
continue;
|
|
52
89
|
}
|
|
53
90
|
// @ts-ignore
|
|
54
|
-
this.
|
|
91
|
+
if (this.props[prop] !== nextProps[prop]) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
55
94
|
}
|
|
56
|
-
return
|
|
95
|
+
return false;
|
|
57
96
|
}
|
|
58
97
|
render() {
|
|
59
98
|
if (!this.renderFn) {
|
|
60
|
-
this.reactiveProps = createReactiveProps(
|
|
99
|
+
this.reactiveProps = this.createReactiveProps();
|
|
61
100
|
currentComponent = this;
|
|
62
101
|
try {
|
|
63
102
|
this.renderFn = this.props.__component(this.reactiveProps);
|
|
@@ -77,7 +116,9 @@ class RaskComponent extends Component {
|
|
|
77
116
|
const stopObserving = this.observer.observe();
|
|
78
117
|
let result = null;
|
|
79
118
|
try {
|
|
119
|
+
this.isRendering = true;
|
|
80
120
|
result = this.renderFn();
|
|
121
|
+
this.isRendering = false;
|
|
81
122
|
}
|
|
82
123
|
catch (error) {
|
|
83
124
|
if (typeof this.context.notifyError !== "function") {
|
|
@@ -94,25 +135,3 @@ class RaskComponent extends Component {
|
|
|
94
135
|
export function createComponent(props, key) {
|
|
95
136
|
return createComponentVNode(4 /* VNodeFlags.ComponentClass */, RaskComponent, props, key);
|
|
96
137
|
}
|
|
97
|
-
function createReactiveProps(props) {
|
|
98
|
-
const reactiveProps = {};
|
|
99
|
-
for (const prop in props) {
|
|
100
|
-
const signal = new Signal();
|
|
101
|
-
Object.defineProperty(reactiveProps, prop, {
|
|
102
|
-
get() {
|
|
103
|
-
const observer = getCurrentObserver();
|
|
104
|
-
if (observer) {
|
|
105
|
-
observer.subscribeSignal(signal);
|
|
106
|
-
}
|
|
107
|
-
return props[prop];
|
|
108
|
-
},
|
|
109
|
-
set(value) {
|
|
110
|
-
if (props[prop] !== value) {
|
|
111
|
-
props[prop] = value;
|
|
112
|
-
signal.notify();
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
return reactiveProps;
|
|
118
|
-
}
|