cx 24.3.9 → 24.3.10
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/manifest.js +744 -744
- package/dist/ui.js +29 -17
- package/package.json +1 -1
- package/src/ui/CultureScope.js +2 -0
- package/src/ui/Cx.js +311 -313
- package/src/ui/Restate.js +163 -160
package/src/ui/Restate.js
CHANGED
|
@@ -1,160 +1,163 @@
|
|
|
1
|
-
import { PureContainer } from "./PureContainer";
|
|
2
|
-
import { Store } from "../data/Store";
|
|
3
|
-
import { Cx } from "./Cx";
|
|
4
|
-
import { isString } from "../util/isString";
|
|
5
|
-
import { VDOM } from "./VDOM";
|
|
6
|
-
import { isFunction } from "../util/isFunction";
|
|
7
|
-
import { isObject } from "../util/isObject";
|
|
8
|
-
import { isUndefined } from "../util/isUndefined";
|
|
9
|
-
import { Binding } from "../data/Binding";
|
|
10
|
-
import { StructuredSelector } from "../data/StructuredSelector";
|
|
11
|
-
|
|
12
|
-
let persistenceCache = {};
|
|
13
|
-
|
|
14
|
-
export class Restate extends PureContainer {
|
|
15
|
-
declareData() {
|
|
16
|
-
return super.declareData(...arguments, {
|
|
17
|
-
deferredUntilIdle: undefined,
|
|
18
|
-
idleTimeout: undefined,
|
|
19
|
-
cacheKey: undefined,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
init() {
|
|
24
|
-
this.container = PureContainer.create({
|
|
25
|
-
type: PureContainer,
|
|
26
|
-
items: this.children || this.items,
|
|
27
|
-
layout: this.layout,
|
|
28
|
-
controller: this.controller,
|
|
29
|
-
outerLayout: this.outerLayout,
|
|
30
|
-
useParentLayout: !this.detached,
|
|
31
|
-
ws: this.ws,
|
|
32
|
-
});
|
|
33
|
-
this.privateDataSelector = new StructuredSelector({
|
|
34
|
-
props: this.data || {},
|
|
35
|
-
values: this.data,
|
|
36
|
-
});
|
|
37
|
-
delete this.items;
|
|
38
|
-
delete this.children;
|
|
39
|
-
delete this.controller;
|
|
40
|
-
delete this.outerLayout;
|
|
41
|
-
delete this.layout;
|
|
42
|
-
if (this.useParentLayout == null) this.useParentLayout = !this.detached;
|
|
43
|
-
super.init();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
initSubStore(context, instance) {
|
|
47
|
-
let { cacheKey } = instance.data;
|
|
48
|
-
this.privateDataSelector.init(instance.store);
|
|
49
|
-
instance.subStore = new RestateStore({
|
|
50
|
-
store: instance.store,
|
|
51
|
-
detached: this.detached,
|
|
52
|
-
privateData: this.data || {},
|
|
53
|
-
data: cacheKey ? persistenceCache[cacheKey] || {} : {},
|
|
54
|
-
dataSelector: this.privateDataSelector.create(),
|
|
55
|
-
onSet: (path, value) => instance.nestedDataSet(path, value, this.data),
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
instance.setStore = (store) => {
|
|
59
|
-
instance.store = store;
|
|
60
|
-
instance.subStore.setStore(store);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
if (cacheKey) {
|
|
64
|
-
instance.subscribeOnDestroy(() => {
|
|
65
|
-
persistenceCache[cacheKey] = instance.subStore.getData();
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
explore(context, instance) {
|
|
71
|
-
if (!instance.subStore) this.initSubStore(context, instance);
|
|
72
|
-
if (instance.subStore.parentDataCheck()) instance.markShouldUpdate();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
instance.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
1
|
+
import { PureContainer } from "./PureContainer";
|
|
2
|
+
import { Store } from "../data/Store";
|
|
3
|
+
import { Cx } from "./Cx";
|
|
4
|
+
import { isString } from "../util/isString";
|
|
5
|
+
import { VDOM } from "./VDOM";
|
|
6
|
+
import { isFunction } from "../util/isFunction";
|
|
7
|
+
import { isObject } from "../util/isObject";
|
|
8
|
+
import { isUndefined } from "../util/isUndefined";
|
|
9
|
+
import { Binding } from "../data/Binding";
|
|
10
|
+
import { StructuredSelector } from "../data/StructuredSelector";
|
|
11
|
+
|
|
12
|
+
let persistenceCache = {};
|
|
13
|
+
|
|
14
|
+
export class Restate extends PureContainer {
|
|
15
|
+
declareData() {
|
|
16
|
+
return super.declareData(...arguments, {
|
|
17
|
+
deferredUntilIdle: undefined,
|
|
18
|
+
idleTimeout: undefined,
|
|
19
|
+
cacheKey: undefined,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
init() {
|
|
24
|
+
this.container = PureContainer.create({
|
|
25
|
+
type: PureContainer,
|
|
26
|
+
items: this.children || this.items,
|
|
27
|
+
layout: this.layout,
|
|
28
|
+
controller: this.controller,
|
|
29
|
+
outerLayout: this.outerLayout,
|
|
30
|
+
useParentLayout: !this.detached,
|
|
31
|
+
ws: this.ws,
|
|
32
|
+
});
|
|
33
|
+
this.privateDataSelector = new StructuredSelector({
|
|
34
|
+
props: this.data || {},
|
|
35
|
+
values: this.data,
|
|
36
|
+
});
|
|
37
|
+
delete this.items;
|
|
38
|
+
delete this.children;
|
|
39
|
+
delete this.controller;
|
|
40
|
+
delete this.outerLayout;
|
|
41
|
+
delete this.layout;
|
|
42
|
+
if (this.useParentLayout == null) this.useParentLayout = !this.detached;
|
|
43
|
+
super.init();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
initSubStore(context, instance) {
|
|
47
|
+
let { cacheKey } = instance.data;
|
|
48
|
+
this.privateDataSelector.init(instance.store);
|
|
49
|
+
instance.subStore = new RestateStore({
|
|
50
|
+
store: instance.store,
|
|
51
|
+
detached: this.detached,
|
|
52
|
+
privateData: this.data || {},
|
|
53
|
+
data: cacheKey ? persistenceCache[cacheKey] || {} : {},
|
|
54
|
+
dataSelector: this.privateDataSelector.create(),
|
|
55
|
+
onSet: (path, value) => instance.nestedDataSet(path, value, this.data),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
instance.setStore = (store) => {
|
|
59
|
+
instance.store = store;
|
|
60
|
+
instance.subStore.setStore(store);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (cacheKey) {
|
|
64
|
+
instance.subscribeOnDestroy(() => {
|
|
65
|
+
persistenceCache[cacheKey] = instance.subStore.getData();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
explore(context, instance) {
|
|
71
|
+
if (!instance.subStore) this.initSubStore(context, instance);
|
|
72
|
+
if (instance.subStore.parentDataCheck()) instance.markShouldUpdate();
|
|
73
|
+
instance.cultureInfo = context.cultureInfo;
|
|
74
|
+
if (instance.cache("cultureInfo", instance.culture)) instance.markShouldUpdate();
|
|
75
|
+
super.explore(context, instance);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
exploreItems(context, instance, items) {
|
|
79
|
+
if (!this.detached) {
|
|
80
|
+
instance.container = instance.getChild(context, this.container, "container", instance.subStore);
|
|
81
|
+
instance.container.scheduleExploreIfVisible(context);
|
|
82
|
+
instance.children = [instance.container];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
render(context, instance, key) {
|
|
87
|
+
if (!this.detached) return instance.container.render(context);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Cx
|
|
91
|
+
key={key}
|
|
92
|
+
widget={this.container}
|
|
93
|
+
parentInstance={instance}
|
|
94
|
+
store={instance.subStore}
|
|
95
|
+
subscribe
|
|
96
|
+
options={this.options}
|
|
97
|
+
onError={this.onError}
|
|
98
|
+
deferredUntilIdle={instance.data.deferredUntilIdle}
|
|
99
|
+
idleTimeout={instance.data.idleTimeout}
|
|
100
|
+
immediate={this.immediate}
|
|
101
|
+
cultureInfo={instance.cultureInfo}
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
Restate.prototype.detached = false;
|
|
108
|
+
Restate.prototype.waitForIdle = false;
|
|
109
|
+
Restate.prototype.immediate = false;
|
|
110
|
+
|
|
111
|
+
export const PrivateStore = Restate;
|
|
112
|
+
|
|
113
|
+
class RestateStore extends Store {
|
|
114
|
+
constructor(config) {
|
|
115
|
+
super(config);
|
|
116
|
+
this.parentDataVersion = -1;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getData() {
|
|
120
|
+
this.silently(() => {
|
|
121
|
+
this.parentDataCheck();
|
|
122
|
+
});
|
|
123
|
+
return super.getData();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
parentDataCheck() {
|
|
127
|
+
if (this.parentDataVersion == this.store.meta.version) return false;
|
|
128
|
+
this.parentDataVersion = this.store.meta.version;
|
|
129
|
+
this.parentData = this.dataSelector(this.store.getData());
|
|
130
|
+
return this.batch(() => {
|
|
131
|
+
for (let key in this.parentData) {
|
|
132
|
+
super.setItem(key, this.parentData[key]);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
setItem(path, value) {
|
|
138
|
+
let binding = Binding.get(path);
|
|
139
|
+
let bindingRoot = binding.parts[0];
|
|
140
|
+
if (!isObject(this.privateData) || !this.privateData.hasOwnProperty(bindingRoot)) {
|
|
141
|
+
let changed = isUndefined(value) ? super.deleteItem(path) : super.setItem(path, value);
|
|
142
|
+
return changed;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let newValue = value;
|
|
146
|
+
if (binding.parts.length > 1) newValue = binding.set(this.getData(), value)[bindingRoot];
|
|
147
|
+
this.onSet(bindingRoot, newValue);
|
|
148
|
+
this.batch(() => {
|
|
149
|
+
super.setItem(bindingRoot, newValue);
|
|
150
|
+
this.parentDataCheck();
|
|
151
|
+
});
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
deleteItem(path) {
|
|
156
|
+
return this.setItem(path, undefined);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
doNotify() {
|
|
160
|
+
if (!this.detached) this.store.notify();
|
|
161
|
+
super.doNotify();
|
|
162
|
+
}
|
|
163
|
+
}
|