-
Notifications
You must be signed in to change notification settings - Fork 0
/
myReact.js
74 lines (74 loc) · 2.35 KB
/
myReact.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
let globalId = 0;
let globalParent;
export class mrc {
constructor(parent, component, _props) {
this.parent = parent;
this.component = component;
this._props = _props;
}
get props() {
return this._props;
}
set props(value) {
this._props = value;
}
static getmrc(parent, component, props) {
let mymrc = mrc.mrcmap.get(parent);
if (!mymrc)
mrc.mrcmap.set(parent, mymrc = new mrc(parent, component, props));
return mymrc;
}
render() {
this.parent.textContent = this.component(this);
;
}
}
mrc.mrcmap = new Map();
export class mrr extends mrc {
constructor(parent, component, props) {
super(parent, component, props);
this.parent = parent;
this.component = component;
}
get props() { return super.props; }
;
static getmrr(parent, component, props) {
let mymrr = mrc.mrcmap.get(parent);
if (!mymrr)
mrc.mrcmap.set(parent, mymrr = new mrr(parent, component, props));
return mymrr;
}
useEffect(callback, dependencies) {
const dependenciesChanged = !this.ueDependencies || dependencies.some((dep, i) => this.ueDependencies[i] !== dep);
if (dependenciesChanged) {
if (this.ueCleanup)
this.ueCleanup();
this.ueCleanup = callback();
this.ueDependencies = dependencies;
}
}
useState(initialState) {
if (this.usValue == undefined) // use ??
this.usValue = typeof initialState == "function" ? initialState(0) : initialState;
const setState = (state) => {
this.usValue = typeof state == 'function' ? state(this.usValue) : state;
this.render();
};
return [this.usValue, setState];
}
useMemo(callback, dependencies) {
try {
const dependenciesChanged = !this.umDependencies || dependencies.some((dep, i) => this.ueDependencies[i] !== dep);
if (dependenciesChanged) {
this.umValue = callback();
this.ueDependencies = dependencies;
}
return this.umValue;
}
catch (e) {
debugger;
throw e;
}
}
}
//# sourceMappingURL=MyReact.js.map