cx 25.5.0 → 25.5.2

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