cx 23.12.2 → 24.0.0

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,164 +1,174 @@
1
- import { Expression } from "./Expression";
2
- import assert from "assert";
3
-
4
- describe("Expression", function () {
5
- describe("#compile()", function () {
6
- it("returns a selector", function () {
7
- var e = Expression.compile("{person.name}");
8
- var state = {
9
- person: {
10
- name: "Jim",
11
- },
12
- };
13
- assert.equal(e(state), "Jim");
14
- });
15
-
16
- it("ignores bindings in strings", function () {
17
- var e = Expression.compile('"{person.name}"');
18
- var state = {
19
- person: {
20
- name: "Jim",
21
- },
22
- };
23
- assert.equal(e(state), "{person.name}");
24
- });
25
-
26
- it("properly encodes quotes #1", function () {
27
- var e = Expression.compile('"\'"');
28
- var state = {};
29
- assert.equal(e(state), "'");
30
- });
31
-
32
- it("properly encodes quotes #2", function () {
33
- var e = Expression.compile('"\\""');
34
- var state = {};
35
- assert.equal(e(state), '"');
36
- });
37
- });
38
-
39
- describe("allow subexpressions", function () {
40
- it("in square brackets", function () {
41
- var e = Expression.compile("{[{person.name}]}");
42
- var state = {
43
- person: {
44
- name: "Jim",
45
- },
46
- };
47
- assert.equal(e(state), "Jim");
48
- });
49
-
50
- it("in square brackets", function () {
51
- var e = Expression.compile("{[{person.alias} || {person.name}]}");
52
- var state = {
53
- person: {
54
- name: "Jim",
55
- alias: "J",
56
- },
57
- };
58
- assert.equal(e(state), "J");
59
- });
60
-
61
- it("prefixed with % sign", function () {
62
- var e = Expression.compile("%{1+1}");
63
- assert.equal(e(), "2");
64
- });
65
-
66
- it("can be formatted", function () {
67
- var e = Expression.compile("{[1+1]:f;2}");
68
- assert.equal(e(), "2.00");
69
- });
70
-
71
- it("n level deep", function () {
72
- var e = Expression.compile("{[{[{[1+1]}]}]:f;2}");
73
- assert.equal(e(), "2.00");
74
- });
75
-
76
- it("with complex math inside", function () {
77
- var e = Expression.compile("%{{data}.reduce((a,b)=>a+b, 0):f;2}");
78
- var state = {
79
- data: [1, 2, 3],
80
- };
81
- assert.equal(e(state), "6.00");
82
- });
83
-
84
- it("with a conditional operator inside", function () {
85
- var e = Expression.compile('{[true ? "T" : "F"]}');
86
- assert.equal(e(), "T");
87
- });
88
- });
89
-
90
- describe("are working", function () {
91
- it("function expressions with get", function () {
92
- var e = Expression.get((get) => get("a") + get("b"));
93
- assert.equal(e({ a: 1, b: 2 }), 3);
94
- });
95
-
96
- it("are properly memoized", function () {
97
- let inv = 0;
98
- var e = Expression.get((get) => {
99
- inv++;
100
- return get("a") + get("b");
101
- }).memoize();
102
-
103
- assert.equal(e({ a: 1, b: 1 }), 2);
104
- assert.equal(inv, 1);
105
-
106
- assert.equal(e({ a: 1, b: 1 }), 2);
107
- assert.equal(inv, 1);
108
-
109
- assert.equal(e({ a: 1, b: 2 }), 3);
110
- assert.equal(inv, 2);
111
-
112
- assert.equal(e({ a: 1, b: 2 }), 3);
113
- assert.equal(inv, 2);
114
-
115
- assert.equal(e({ a: 2, b: 2 }), 4);
116
- assert.equal(inv, 3);
117
- });
118
-
119
- it("formatting can be used inside bindings", function () {
120
- var e = Expression.get((get) => get("name:prefix;Hello "));
121
- assert(e({ name: "CxJS" }), "Hello CxJS");
122
- });
123
-
124
- // it('are properly memoized with proxies', function () {
125
- // let inv = 0;
126
- // var e = Expression.get(d => { inv++; return d.a + d.b}).memoize();
127
- //
128
- // assert.equal(e({ a: 1, b: 1 }), 2);
129
- // assert.equal(inv, 1);
130
- //
131
- // assert.equal(e({ a: 1, b: 1 }), 2);
132
- // assert.equal(inv, 1);
133
- //
134
- // assert.equal(e({ a: 1, b: 2 }), 3);
135
- // assert.equal(inv, 2);
136
- //
137
- // assert.equal(e({ a: 1, b: 2 }), 3);
138
- // assert.equal(inv, 2);
139
- //
140
- // assert.equal(e({ a: 2, b: 2 }), 4);
141
- // assert.equal(inv, 3);
142
- // });
143
- //
144
- // it('are properly memoized with proxies and deep data', function () {
145
- // let inv = 0;
146
- // var e = Expression.get(d => { inv++; return d.v.a + d.v.b}).memoize();
147
- //
148
- // assert.equal(e({ v: { a: 1, b: 1 }}), 2);
149
- // assert.equal(inv, 1);
150
- //
151
- // assert.equal(e({ v: { a: 1, b: 1 }}), 2);
152
- // assert.equal(inv, 1);
153
- //
154
- // assert.equal(e({ v: { a: 1, b: 2 }}), 3);
155
- // assert.equal(inv, 2);
156
- //
157
- // assert.equal(e({ v: { a: 1, b: 2 }}), 3);
158
- // assert.equal(inv, 2);
159
- //
160
- // assert.equal(e({ v: { a: 2, b: 2 }}), 4);
161
- // assert.equal(inv, 3);
162
- // });
163
- });
164
- });
1
+ import { Expression } from "./Expression";
2
+ import assert from "assert";
3
+
4
+ describe("Expression", function () {
5
+ describe("#compile()", function () {
6
+ it("returns a selector", function () {
7
+ var e = Expression.compile("{person.name}");
8
+ var state = {
9
+ person: {
10
+ name: "Jim",
11
+ },
12
+ };
13
+ assert.equal(e(state), "Jim");
14
+ });
15
+
16
+ it("ignores bindings in strings", function () {
17
+ var e = Expression.compile('"{person.name}"');
18
+ var state = {
19
+ person: {
20
+ name: "Jim",
21
+ },
22
+ };
23
+ assert.equal(e(state), "{person.name}");
24
+ });
25
+
26
+ it("properly encodes quotes #1", function () {
27
+ var e = Expression.compile('"\'"');
28
+ var state = {};
29
+ assert.equal(e(state), "'");
30
+ });
31
+
32
+ it("properly encodes quotes #2", function () {
33
+ var e = Expression.compile('"\\""');
34
+ var state = {};
35
+ assert.equal(e(state), '"');
36
+ });
37
+ });
38
+
39
+ describe("allow subexpressions", function () {
40
+ it("in square brackets", function () {
41
+ var e = Expression.compile("{[{person.name}]}");
42
+ var state = {
43
+ person: {
44
+ name: "Jim",
45
+ },
46
+ };
47
+ assert.equal(e(state), "Jim");
48
+ });
49
+
50
+ it("in square brackets", function () {
51
+ var e = Expression.compile("{[{person.alias} || {person.name}]}");
52
+ var state = {
53
+ person: {
54
+ name: "Jim",
55
+ alias: "J",
56
+ },
57
+ };
58
+ assert.equal(e(state), "J");
59
+ });
60
+
61
+ it("prefixed with % sign", function () {
62
+ var e = Expression.compile("%{1+1}");
63
+ assert.equal(e(), "2");
64
+ });
65
+
66
+ it("can be formatted", function () {
67
+ var e = Expression.compile("{[1+1]:f;2}");
68
+ assert.equal(e(), "2.00");
69
+ });
70
+
71
+ it("n level deep", function () {
72
+ var e = Expression.compile("{[{[{[1+1]}]}]:f;2}");
73
+ assert.equal(e(), "2.00");
74
+ });
75
+
76
+ it("with complex math inside", function () {
77
+ var e = Expression.compile("%{{data}.reduce((a,b)=>a+b, 0):f;2}");
78
+ var state = {
79
+ data: [1, 2, 3],
80
+ };
81
+ assert.equal(e(state), "6.00");
82
+ });
83
+
84
+ it("with a conditional operator inside", function () {
85
+ var e = Expression.compile('{[true ? "T" : "F"]}');
86
+ assert.equal(e(), "T");
87
+ });
88
+
89
+ it("with string interpolation inside", function () {
90
+ var e = Expression.compile("{[`${{test}}`]}");
91
+ assert.equal(e({ test: "T" }), "T");
92
+ });
93
+ });
94
+
95
+ describe("are working", function () {
96
+ it("function expressions with get", function () {
97
+ var e = Expression.get((get) => get("a") + get("b"));
98
+ assert.equal(e({ a: 1, b: 2 }), 3);
99
+ });
100
+
101
+ it("are properly memoized", function () {
102
+ let inv = 0;
103
+ var e = Expression.get((get) => {
104
+ inv++;
105
+ return get("a") + get("b");
106
+ }).memoize();
107
+
108
+ assert.equal(e({ a: 1, b: 1 }), 2);
109
+ assert.equal(inv, 1);
110
+
111
+ assert.equal(e({ a: 1, b: 1 }), 2);
112
+ assert.equal(inv, 1);
113
+
114
+ assert.equal(e({ a: 1, b: 2 }), 3);
115
+ assert.equal(inv, 2);
116
+
117
+ assert.equal(e({ a: 1, b: 2 }), 3);
118
+ assert.equal(inv, 2);
119
+
120
+ assert.equal(e({ a: 2, b: 2 }), 4);
121
+ assert.equal(inv, 3);
122
+ });
123
+
124
+ it("formatting can be used inside bindings", function () {
125
+ var e = Expression.get((get) => get("name:prefix;Hello "));
126
+ assert(e({ name: "CxJS" }), "Hello CxJS");
127
+ });
128
+
129
+ it("allows using the fmt function inside", function () {
130
+ var e = Expression.compile('{[fmt({text}, "prefix;Hello ")]}');
131
+ assert.equal(e({ text: "CxJS" }), "Hello CxJS");
132
+ });
133
+
134
+ // it('are properly memoized with proxies', function () {
135
+ // let inv = 0;
136
+ // var e = Expression.get(d => { inv++; return d.a + d.b}).memoize();
137
+ //
138
+ // assert.equal(e({ a: 1, b: 1 }), 2);
139
+ // assert.equal(inv, 1);
140
+ //
141
+ // assert.equal(e({ a: 1, b: 1 }), 2);
142
+ // assert.equal(inv, 1);
143
+ //
144
+ // assert.equal(e({ a: 1, b: 2 }), 3);
145
+ // assert.equal(inv, 2);
146
+ //
147
+ // assert.equal(e({ a: 1, b: 2 }), 3);
148
+ // assert.equal(inv, 2);
149
+ //
150
+ // assert.equal(e({ a: 2, b: 2 }), 4);
151
+ // assert.equal(inv, 3);
152
+ // });
153
+ //
154
+ // it('are properly memoized with proxies and deep data', function () {
155
+ // let inv = 0;
156
+ // var e = Expression.get(d => { inv++; return d.v.a + d.v.b}).memoize();
157
+ //
158
+ // assert.equal(e({ v: { a: 1, b: 1 }}), 2);
159
+ // assert.equal(inv, 1);
160
+ //
161
+ // assert.equal(e({ v: { a: 1, b: 1 }}), 2);
162
+ // assert.equal(inv, 1);
163
+ //
164
+ // assert.equal(e({ v: { a: 1, b: 2 }}), 3);
165
+ // assert.equal(inv, 2);
166
+ //
167
+ // assert.equal(e({ v: { a: 1, b: 2 }}), 3);
168
+ // assert.equal(inv, 2);
169
+ //
170
+ // assert.equal(e({ v: { a: 2, b: 2 }}), 4);
171
+ // assert.equal(inv, 3);
172
+ // });
173
+ });
174
+ });
package/src/ui/Format.js CHANGED
@@ -1,89 +1,87 @@
1
- import {Culture} from "./Culture";
2
- import {Format as Fmt, resolveMinMaxFractionDigits} from "../util/Format";
3
- import {GlobalCacheIdentifier} from '../util/GlobalCacheIdentifier';
4
-
5
- export const Format = Fmt;
6
-
7
- let cultureSensitiveFormatsRegistered = false;
8
-
9
- export function enableCultureSensitiveFormatting() {
10
-
11
- if (cultureSensitiveFormatsRegistered)
12
- return;
13
-
14
- cultureSensitiveFormatsRegistered = true;
15
-
16
- Fmt.registerFactory(
17
- ['number', 'n'],
18
- (format, minimumFractionDigits, maximumFractionDigits) => {
19
- let culture = Culture.getNumberCulture();
20
-
21
- let formatter = culture.getFormatter(resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits));
22
-
23
- return value => formatter.format(value);
24
- }
25
- );
26
-
27
- Fmt.registerFactory('currency',
28
- (format, currency, minimumFractionDigits, maximumFractionDigits) => {
29
- let culture = Culture.getNumberCulture();
30
- currency = currency || Culture.defaultCurrency;
31
-
32
- let formatter = culture.getFormatter({
33
- style: 'currency',
34
- currency: currency,
35
- ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits)
36
- });
37
-
38
- return value => formatter.format(value);
39
- }
40
- );
41
-
42
- Fmt.registerFactory(
43
- ['percentage', 'p', '%'],
44
- (format, minimumFractionDigits, maximumFractionDigits) => {
45
- let culture = Culture.getNumberCulture();
46
- let formatter = culture.getFormatter({
47
- style: 'percent',
48
- ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits)
49
- });
50
- return value => formatter.format(value);
51
- }
52
- );
53
-
54
- Fmt.registerFactory(
55
- ['percentSign', 'ps'],
56
- (format, minimumFractionDigits, maximumFractionDigits) => {
57
- let culture = Culture.getNumberCulture();
58
- let formatter = culture.getFormatter({
59
- style: 'percent',
60
- ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits)
61
- });
62
- return value => formatter.format(value / 100);
63
- }
64
- );
65
-
66
- Fmt.registerFactory(['date', 'd'], (fmt, format = 'yyyyMMdd') => {
67
- let culture = Culture.getDateTimeCulture();
68
- let formatter = culture.getFormatter(format);
69
- return value => formatter.format(new Date(value));
70
- });
71
-
72
-
73
- Fmt.registerFactory(['time', 't'], (fmt, format = 'hhmmss') => {
74
- let culture = Culture.getDateTimeCulture();
75
- let formatter = culture.getFormatter(format);
76
- return value => formatter.format(new Date(value));
77
- });
78
-
79
- Fmt.registerFactory(
80
- ['datetime', 'dt'],
81
- (fmt, format = 'yyyyMd hhmm') => {
82
- let culture = Culture.getDateTimeCulture();
83
- let formatter = culture.getFormatter(format);
84
- return value => formatter.format(new Date(value));
85
- }
86
- );
87
-
88
- GlobalCacheIdentifier.change();
89
- }
1
+ import { Culture } from "./Culture";
2
+ import { Format as Fmt, resolveMinMaxFractionDigits } from "../util/Format";
3
+ import { GlobalCacheIdentifier } from "../util/GlobalCacheIdentifier";
4
+
5
+ export const Format = Fmt;
6
+
7
+ let cultureSensitiveFormatsRegistered = false;
8
+
9
+ export function resolveNumberFormattingFlags(flags) {
10
+ if (!flags) return null;
11
+ let result = {};
12
+ if (flags.indexOf("+") >= 0) result.signDisplay = "exceptZero";
13
+ if (flags.indexOf("c") >= 0) result.notation = "compact";
14
+ if (flags.indexOf("a") >= 0) result.currencySign = "accounting";
15
+ return result;
16
+ }
17
+
18
+ export function enableCultureSensitiveFormatting() {
19
+ if (cultureSensitiveFormatsRegistered) return;
20
+
21
+ cultureSensitiveFormatsRegistered = true;
22
+
23
+ Fmt.registerFactory(["number", "n"], (format, minimumFractionDigits, maximumFractionDigits, flags) => {
24
+ let culture = Culture.getNumberCulture();
25
+
26
+ let formatter = culture.getFormatter({
27
+ ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
28
+ ...resolveNumberFormattingFlags(flags),
29
+ });
30
+
31
+ return (value) => formatter.format(value);
32
+ });
33
+
34
+ Fmt.registerFactory("currency", (format, currency, minimumFractionDigits, maximumFractionDigits, flags) => {
35
+ let culture = Culture.getNumberCulture();
36
+ currency = currency || Culture.defaultCurrency;
37
+
38
+ let formatter = culture.getFormatter({
39
+ style: "currency",
40
+ currency: currency,
41
+ ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
42
+ ...resolveNumberFormattingFlags(flags),
43
+ });
44
+
45
+ return (value) => formatter.format(value);
46
+ });
47
+
48
+ Fmt.registerFactory(["percentage", "p", "%"], (format, minimumFractionDigits, maximumFractionDigits, flags) => {
49
+ let culture = Culture.getNumberCulture();
50
+ let formatter = culture.getFormatter({
51
+ style: "percent",
52
+ ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
53
+ ...resolveNumberFormattingFlags(flags),
54
+ });
55
+ return (value) => formatter.format(value);
56
+ });
57
+
58
+ Fmt.registerFactory(["percentSign", "ps"], (format, minimumFractionDigits, maximumFractionDigits, flags) => {
59
+ let culture = Culture.getNumberCulture();
60
+ let formatter = culture.getFormatter({
61
+ style: "percent",
62
+ ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
63
+ ...resolveNumberFormattingFlags(flags),
64
+ });
65
+ return (value) => formatter.format(value / 100);
66
+ });
67
+
68
+ Fmt.registerFactory(["date", "d"], (fmt, format = "yyyyMMdd") => {
69
+ let culture = Culture.getDateTimeCulture();
70
+ let formatter = culture.getFormatter(format);
71
+ return (value) => formatter.format(new Date(value));
72
+ });
73
+
74
+ Fmt.registerFactory(["time", "t"], (fmt, format = "hhmmss") => {
75
+ let culture = Culture.getDateTimeCulture();
76
+ let formatter = culture.getFormatter(format);
77
+ return (value) => formatter.format(new Date(value));
78
+ });
79
+
80
+ Fmt.registerFactory(["datetime", "dt"], (fmt, format = "yyyyMd hhmm") => {
81
+ let culture = Culture.getDateTimeCulture();
82
+ let formatter = culture.getFormatter(format);
83
+ return (value) => formatter.format(new Date(value));
84
+ });
85
+
86
+ GlobalCacheIdentifier.change();
87
+ }
@@ -8,6 +8,9 @@ interface RestateProps extends Cx.PureContainerProps {
8
8
  idleTimeout?: Cx.NumberProp;
9
9
  cacheKey?: Cx.StringProp;
10
10
 
11
+ /* Set to true to disable batching of updates. */
12
+ immediate?: boolean;
13
+
11
14
  onError?: (err: Error, instance: Instance) => void;
12
15
  }
13
16
 
package/src/ui/Restate.js CHANGED
@@ -95,6 +95,7 @@ export class Restate extends PureContainer {
95
95
  onError={this.onError}
96
96
  deferredUntilIdle={instance.data.deferredUntilIdle}
97
97
  idleTimeout={instance.data.idleTimeout}
98
+ immediate={this.immediate}
98
99
  />
99
100
  );
100
101
  }
@@ -102,6 +103,7 @@ export class Restate extends PureContainer {
102
103
 
103
104
  Restate.prototype.detached = false;
104
105
  Restate.prototype.waitForIdle = false;
106
+ Restate.prototype.immediate = false;
105
107
 
106
108
  export const PrivateStore = Restate;
107
109