cx 26.7.4 → 26.7.5

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,55 +1,55 @@
1
- import { AccessorChain } from "../data";
2
- import { NestedDataView } from "../data/NestedDataView";
3
- import { StructuredProp, WritableProp } from "./Prop";
4
- import { PureContainerBase, PureContainerConfig } from "./PureContainer";
5
- import { StructuredInstanceDataAccessor } from "./StructuredInstanceDataAccessor";
6
-
7
- export interface DataProxyConfig extends PureContainerConfig {
8
- /** Data object with computed values to be exposed in the local store. */
9
- data?: StructuredProp;
10
-
11
- /** Binding to a value to be exposed under the `alias` name. */
12
- value?: WritableProp<any>;
13
-
14
- /** Alias name under which `value` is exposed in the local store. */
15
- alias?: string | AccessorChain<any>;
16
-
17
- /** Indicate that parent store data should not be mutated. */
18
- immutable?: boolean;
19
-
20
- /** Indicate that local store data should not be mutated. */
21
- sealed?: boolean;
22
- }
23
-
24
- export class DataProxy extends PureContainerBase<DataProxyConfig> {
25
- declare data?: any;
26
- declare alias?: string;
27
- declare value?: any;
28
- declare immutable: boolean;
29
- declare sealed: boolean;
30
-
31
- init() {
32
- if (!this.data) this.data = {};
33
-
34
- if (this.alias) this.data[this.alias] = this.value;
35
-
36
- super.init();
37
- }
38
-
39
- initInstance(context: any, instance: any) {
40
- instance.store = new NestedDataView({
41
- store: instance.parentStore,
42
- nestedData: new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true }),
43
- immutable: this.immutable,
44
- sealed: this.sealed,
45
- });
46
- super.initInstance(context, instance);
47
- }
48
-
49
- applyParentStore(instance: any) {
50
- instance.store.setStore(instance.parentStore);
51
- }
52
- }
53
-
54
- DataProxy.prototype.immutable = false;
55
- DataProxy.prototype.sealed = false;
1
+ import { AccessorChain } from "../data";
2
+ import { NestedDataView } from "../data/NestedDataView";
3
+ import { StructuredProp, WritableProp } from "./Prop";
4
+ import { PureContainerBase, PureContainerConfig } from "./PureContainer";
5
+ import { StructuredInstanceDataAccessor } from "./StructuredInstanceDataAccessor";
6
+
7
+ export interface DataProxyConfig extends PureContainerConfig {
8
+ /** Data object with computed values to be exposed in the local store. */
9
+ data?: StructuredProp;
10
+
11
+ /** Binding to a value to be exposed under the `alias` name. */
12
+ value?: WritableProp<any>;
13
+
14
+ /** Alias name under which `value` is exposed in the local store. */
15
+ alias?: string | AccessorChain<any>;
16
+
17
+ /** Indicate that parent store data should not be mutated. */
18
+ immutable?: boolean;
19
+
20
+ /** Indicate that local store data should not be mutated. */
21
+ sealed?: boolean;
22
+ }
23
+
24
+ export class DataProxy extends PureContainerBase<DataProxyConfig> {
25
+ declare data?: any;
26
+ declare alias?: string;
27
+ declare value?: any;
28
+ declare immutable: boolean;
29
+ declare sealed: boolean;
30
+
31
+ init() {
32
+ if (!this.data) this.data = {};
33
+
34
+ if (this.alias) this.data[this.alias] = this.value;
35
+
36
+ super.init();
37
+ }
38
+
39
+ initInstance(context: any, instance: any) {
40
+ instance.store = new NestedDataView({
41
+ store: instance.parentStore,
42
+ nestedData: new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true }),
43
+ immutable: this.immutable,
44
+ sealed: this.sealed,
45
+ });
46
+ super.initInstance(context, instance);
47
+ }
48
+
49
+ applyParentStore(instance: any) {
50
+ instance.store.setStore(instance.parentStore);
51
+ }
52
+ }
53
+
54
+ DataProxy.prototype.immutable = false;
55
+ DataProxy.prototype.sealed = false;
package/src/ui/Rescope.ts CHANGED
@@ -1,50 +1,50 @@
1
- import { Widget } from "./Widget";
2
- import { PureContainerBase, PureContainerConfig } 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
- import { StructuredProp } from "./Prop";
8
- import { AccessorChain } from "../data/createAccessorModelProxy";
9
-
10
- export interface RescopeConfig extends PureContainerConfig {
11
- bind: string | AccessorChain<any>;
12
- rootName?: string | AccessorChain<any>;
13
- rootAlias?: string | AccessorChain<any>;
14
- data?: StructuredProp;
15
- }
16
-
17
- export class Rescope extends PureContainerBase<RescopeConfig> {
18
- declare bind: string;
19
- declare binding: any;
20
- declare rootAlias?: string;
21
- declare rootName: string;
22
- declare data?: any;
23
-
24
- init() {
25
- this.binding = Binding.get(this.bind);
26
- if (this.rootAlias) this.rootName = this.rootAlias;
27
- super.init();
28
- }
29
-
30
- initInstance(context: any, instance: any) {
31
- instance.store = new ZoomIntoPropertyView({
32
- store: instance.parentStore,
33
- binding: this.binding,
34
- rootName: this.rootName,
35
- nestedData: isObject(this.data)
36
- ? new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true })
37
- : undefined,
38
- });
39
- super.initInstance(context, instance);
40
- }
41
-
42
- applyParentStore(instance: any) {
43
- instance.store.setStore(instance.parentStore);
44
- }
45
- }
46
-
47
- Rescope.prototype.bind = "$page";
48
- Rescope.prototype.rootName = "$root";
49
-
50
- Widget.alias("rescope", Rescope);
1
+ import { Widget } from "./Widget";
2
+ import { PureContainerBase, PureContainerConfig } 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
+ import { StructuredProp } from "./Prop";
8
+ import { AccessorChain } from "../data/createAccessorModelProxy";
9
+
10
+ export interface RescopeConfig extends PureContainerConfig {
11
+ bind: string | AccessorChain<any>;
12
+ rootName?: string | AccessorChain<any>;
13
+ rootAlias?: string | AccessorChain<any>;
14
+ data?: StructuredProp;
15
+ }
16
+
17
+ export class Rescope extends PureContainerBase<RescopeConfig> {
18
+ declare bind: string;
19
+ declare binding: any;
20
+ declare rootAlias?: string;
21
+ declare rootName: string;
22
+ declare data?: any;
23
+
24
+ init() {
25
+ this.binding = Binding.get(this.bind);
26
+ if (this.rootAlias) this.rootName = this.rootAlias;
27
+ super.init();
28
+ }
29
+
30
+ initInstance(context: any, instance: any) {
31
+ instance.store = new ZoomIntoPropertyView({
32
+ store: instance.parentStore,
33
+ binding: this.binding,
34
+ rootName: this.rootName,
35
+ nestedData: isObject(this.data)
36
+ ? new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true })
37
+ : undefined,
38
+ });
39
+ super.initInstance(context, instance);
40
+ }
41
+
42
+ applyParentStore(instance: any) {
43
+ instance.store.setStore(instance.parentStore);
44
+ }
45
+ }
46
+
47
+ Rescope.prototype.bind = "$page";
48
+ Rescope.prototype.rootName = "$root";
49
+
50
+ Widget.alias("rescope", Rescope);
@@ -4,10 +4,12 @@ import { SubscriberList } from "../util/SubscriberList";
4
4
  interface UpdateCallback {
5
5
  pending: number;
6
6
  finished: number;
7
+ watermark: number;
7
8
  complete: (success?: boolean) => void;
8
9
  }
9
10
 
10
11
  let isBatching = 0;
12
+ let updateSequence = 0;
11
13
  let promiseSubscribers = new SubscriberList();
12
14
 
13
15
  export function batchUpdates(callback: () => void): void {
@@ -27,22 +29,22 @@ export function isBatchingUpdates(): boolean {
27
29
  return isBatching > 0;
28
30
  }
29
31
 
30
- // True while a batchUpdatesAndNotify accumulator is subscribed, i.e. some caller is waiting for the
31
- // current batch's renders to finish. Cx uses this to stay fully synchronous during page-breaking so the
32
- // notify callback still fires right after the change commits.
33
- export function hasBatchedUpdateSubscribers(): boolean {
34
- return !promiseSubscribers.isEmpty();
35
- }
36
-
37
- export function notifyBatchedUpdateStarting(): void {
32
+ // Returns a sequence number identifying the update; pass it to notifyBatchedUpdateCompleted once the
33
+ // update is rendered.
34
+ export function notifyBatchedUpdateStarting(): number {
35
+ let seq = ++updateSequence;
38
36
  promiseSubscribers.execute((x: any) => {
39
37
  (x as UpdateCallback).pending++;
40
38
  });
39
+ return seq;
41
40
  }
42
41
 
43
- export function notifyBatchedUpdateCompleted(): void {
42
+ export function notifyBatchedUpdateCompleted(seq: number): void {
44
43
  promiseSubscribers.execute((x: any) => {
45
44
  let cb = x as UpdateCallback;
45
+ // ignore updates that started before this subscriber attached -- counting them would let the notify
46
+ // callback fire before the updates the subscriber is actually waiting on are rendered
47
+ if (seq <= cb.watermark) return;
46
48
  cb.finished++;
47
49
  if (cb.finished >= cb.pending) cb.complete(true);
48
50
  });
@@ -60,6 +62,7 @@ export function batchUpdatesAndNotify(
60
62
  const update: UpdateCallback = {
61
63
  pending: 0,
62
64
  finished: 0,
65
+ watermark: updateSequence,
63
66
  complete: (success?: boolean) => {
64
67
  if (!done) {
65
68
  done = true;
@@ -1,96 +1,96 @@
1
- import { computable } from "../data/computable";
2
- import { AccessorChain } from "../data/createAccessorModelProxy";
3
- import { Selector } from "../data/Selector";
4
- import { Format } from "../util/Format";
5
- import { expr } from "./expr";
6
-
7
- /** Returns a selector that converts the value to boolean using !! */
8
- export function truthy<V>(arg: AccessorChain<V>): Selector<boolean> {
9
- return expr(arg, (x) => !!x);
10
- }
11
-
12
- /** Returns a selector that checks if the value is falsy using ! */
13
- export function falsy<V>(arg: AccessorChain<V>): Selector<boolean> {
14
- return expr(arg, (x) => !x);
15
- }
16
-
17
- /** Returns a selector that checks if the value is strictly true (=== true) */
18
- export function isTrue(arg: AccessorChain<any>): Selector<boolean> {
19
- return expr(arg, (x) => x === true);
20
- }
21
-
22
- /** Returns a selector that checks if the value is strictly false (=== false) */
23
- export function isFalse(arg: AccessorChain<any>): Selector<boolean> {
24
- return expr(arg, (x) => x === false);
25
- }
26
-
27
- /** Returns a selector that checks if the value is not null or undefined (x != null) */
28
- export function hasValue<V>(arg: AccessorChain<V>): Selector<boolean> {
29
- return expr(arg, (x) => x != null);
30
- }
31
-
32
- /** Returns a selector that checks if a string or array is empty (null, undefined, or length === 0) */
33
- export function isEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
34
- return expr(arg, (x) => x == null || x.length === 0);
35
- }
36
-
37
- /** Returns a selector that checks if a string or array is non-empty (not null/undefined and length > 0) */
38
- export function isNonEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
39
- return expr(arg, (x) => x != null && x.length > 0);
40
- }
41
-
42
- /** Returns a selector that checks if the value is less than the given value */
43
- export function lessThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
44
- return expr(arg, (x) => x < value);
45
- }
46
-
47
- /** Returns a selector that checks if the value is less than or equal to the given value */
48
- export function lessThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
49
- return expr(arg, (x) => x <= value);
50
- }
51
-
52
- /** Returns a selector that checks if the value is greater than the given value */
53
- export function greaterThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
54
- return expr(arg, (x) => x > value);
55
- }
56
-
57
- /** Returns a selector that checks if the value is greater than or equal to the given value */
58
- export function greaterThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
59
- return expr(arg, (x) => x >= value);
60
- }
61
-
62
- /** Returns a selector that checks if the value equals the given value using == */
63
- export function equal<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
64
- return expr(arg, (x) => x == value);
65
- }
66
-
67
- /** Returns a selector that checks if the value does not equal the given value using != */
68
- export function notEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
69
- return expr(arg, (x) => x != value);
70
- }
71
-
72
- /** Returns a selector that checks if the value strictly equals the given value using === */
73
- export function strictEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
74
- return expr(arg, (x) => x === value);
75
- }
76
-
77
- /** Returns a selector that checks if the value strictly does not equal the given value using !== */
78
- export function strictNotEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
79
- return expr(arg, (x) => x !== value);
80
- }
81
-
82
- /** Returns a selector that formats the value using the specified format string.
83
- * Format strings use semicolon-separated syntax: "formatType;param1;param2"
84
- * @param arg - The accessor chain to the value
85
- * @param fmt - The format string
86
- * @param nullText - Optional text to display for null/undefined values
87
- * @example
88
- * format(m.price, "n;2") // formats as number with 2 decimal places
89
- * format(m.date, "d") // formats as date
90
- * format(m.value, "p;0;2") // formats as percentage with 0-2 decimal places
91
- * format(m.value, "n;2", "N/A") // shows "N/A" for null values
92
- */
93
- export function format<V>(arg: AccessorChain<V>, fmt: string, nullText?: string): Selector<string> {
94
- let f = nullText != null ? `${fmt}|${nullText}` : fmt;
95
- return computable(arg, (x) => Format.value(x, f));
96
- }
1
+ import { computable } from "../data/computable";
2
+ import { AccessorChain } from "../data/createAccessorModelProxy";
3
+ import { Selector } from "../data/Selector";
4
+ import { Format } from "../util/Format";
5
+ import { expr } from "./expr";
6
+
7
+ /** Returns a selector that converts the value to boolean using !! */
8
+ export function truthy<V>(arg: AccessorChain<V>): Selector<boolean> {
9
+ return expr(arg, (x) => !!x);
10
+ }
11
+
12
+ /** Returns a selector that checks if the value is falsy using ! */
13
+ export function falsy<V>(arg: AccessorChain<V>): Selector<boolean> {
14
+ return expr(arg, (x) => !x);
15
+ }
16
+
17
+ /** Returns a selector that checks if the value is strictly true (=== true) */
18
+ export function isTrue(arg: AccessorChain<any>): Selector<boolean> {
19
+ return expr(arg, (x) => x === true);
20
+ }
21
+
22
+ /** Returns a selector that checks if the value is strictly false (=== false) */
23
+ export function isFalse(arg: AccessorChain<any>): Selector<boolean> {
24
+ return expr(arg, (x) => x === false);
25
+ }
26
+
27
+ /** Returns a selector that checks if the value is not null or undefined (x != null) */
28
+ export function hasValue<V>(arg: AccessorChain<V>): Selector<boolean> {
29
+ return expr(arg, (x) => x != null);
30
+ }
31
+
32
+ /** Returns a selector that checks if a string or array is empty (null, undefined, or length === 0) */
33
+ export function isEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
34
+ return expr(arg, (x) => x == null || x.length === 0);
35
+ }
36
+
37
+ /** Returns a selector that checks if a string or array is non-empty (not null/undefined and length > 0) */
38
+ export function isNonEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
39
+ return expr(arg, (x) => x != null && x.length > 0);
40
+ }
41
+
42
+ /** Returns a selector that checks if the value is less than the given value */
43
+ export function lessThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
44
+ return expr(arg, (x) => x < value);
45
+ }
46
+
47
+ /** Returns a selector that checks if the value is less than or equal to the given value */
48
+ export function lessThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
49
+ return expr(arg, (x) => x <= value);
50
+ }
51
+
52
+ /** Returns a selector that checks if the value is greater than the given value */
53
+ export function greaterThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
54
+ return expr(arg, (x) => x > value);
55
+ }
56
+
57
+ /** Returns a selector that checks if the value is greater than or equal to the given value */
58
+ export function greaterThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
59
+ return expr(arg, (x) => x >= value);
60
+ }
61
+
62
+ /** Returns a selector that checks if the value equals the given value using == */
63
+ export function equal<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
64
+ return expr(arg, (x) => x == value);
65
+ }
66
+
67
+ /** Returns a selector that checks if the value does not equal the given value using != */
68
+ export function notEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
69
+ return expr(arg, (x) => x != value);
70
+ }
71
+
72
+ /** Returns a selector that checks if the value strictly equals the given value using === */
73
+ export function strictEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
74
+ return expr(arg, (x) => x === value);
75
+ }
76
+
77
+ /** Returns a selector that checks if the value strictly does not equal the given value using !== */
78
+ export function strictNotEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
79
+ return expr(arg, (x) => x !== value);
80
+ }
81
+
82
+ /** Returns a selector that formats the value using the specified format string.
83
+ * Format strings use semicolon-separated syntax: "formatType;param1;param2"
84
+ * @param arg - The accessor chain to the value
85
+ * @param fmt - The format string
86
+ * @param nullText - Optional text to display for null/undefined values
87
+ * @example
88
+ * format(m.price, "n;2") // formats as number with 2 decimal places
89
+ * format(m.date, "d") // formats as date
90
+ * format(m.value, "p;0;2") // formats as percentage with 0-2 decimal places
91
+ * format(m.value, "n;2", "N/A") // shows "N/A" for null values
92
+ */
93
+ export function format<V>(arg: AccessorChain<V>, fmt: string, nullText?: string): Selector<string> {
94
+ let f = nullText != null ? `${fmt}|${nullText}` : fmt;
95
+ return computable(arg, (x) => Format.value(x, f));
96
+ }