cx 25.5.1 → 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,102 +1,102 @@
1
- import { Widget } from "../../ui/Widget";
2
- import { PureContainer } from "../../ui/PureContainer";
3
- import RouteMatcher from "route-parser";
4
- import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
5
- import { routeAppend } from "../../util/routeAppend";
6
-
7
- export class Route extends PureContainer {
8
- init() {
9
- if (this.path) this.route = this.path;
10
-
11
- super.init();
12
-
13
- if (this.route && this.route[0] !== "+")
14
- this.matcher = new RouteMatcher(this.route + (this.prefix ? "(*remainder)" : ""));
15
- }
16
-
17
- initInstance(context, instance) {
18
- instance.store = new ReadOnlyDataView({
19
- store: instance.parentStore,
20
- });
21
- super.initInstance(context, instance);
22
- }
23
-
24
- applyParentStore(instance) {
25
- instance.store.setStore(instance.parentStore);
26
- }
27
-
28
- declareData() {
29
- super.declareData(...arguments, {
30
- url: undefined,
31
- });
32
- }
33
-
34
- checkVisible(context, instance, data) {
35
- if (!data.visible) return false;
36
-
37
- if (data.url !== instance.cached.url) {
38
- instance.cached.url = data.url;
39
- let matcher = this.matcher;
40
- let route = this.route;
41
- if (this.route[0] === "+") {
42
- route = routeAppend(context.lastRoute.route, this.route.substring(1));
43
- if (!instance.cached.matcher || instance.cached.route !== route)
44
- instance.cached.matcher = new RouteMatcher(route + (this.prefix ? "(*remainder)" : ""));
45
- matcher = instance.cached.matcher;
46
- }
47
- instance.cached.result = matcher.match(data.url);
48
- instance.cached.matcher = matcher;
49
- instance.cached.route = data.route = route;
50
- }
51
- if (!instance.cached.result) return false;
52
-
53
- return super.checkVisible(context, instance, data);
54
- }
55
-
56
- prepareData(context, { data, store, cached }) {
57
- super.prepareData(...arguments);
58
-
59
- store.setData({
60
- [this.recordName]: cached.result,
61
- });
62
-
63
- //TODO: Replace comparison with deepEquals
64
- if (this.params && this.params.bind) {
65
- var params = store.get(this.params.bind);
66
- if (JSON.stringify(params) != JSON.stringify(cached.result)) {
67
- store.set(this.params.bind, cached.result);
68
- }
69
- }
70
-
71
- if (this.map) {
72
- for (var key in result) {
73
- var binding = this.map[key];
74
- if (binding) store.set(binding, result[key]);
75
- }
76
- }
77
- }
78
-
79
- explore(context, instance) {
80
- context.push("lastRoute", {
81
- route: instance.cached.route,
82
- result: instance.cached.result,
83
- reverse: function (data) {
84
- return instance.cached.matcher.reverse({
85
- ...instance.cached.result,
86
- remainder: "",
87
- ...data,
88
- });
89
- },
90
- });
91
- super.explore(context, instance);
92
- }
93
-
94
- exploreCleanup(context, instance) {
95
- context.pop("lastRoute");
96
- }
97
- }
98
-
99
- Route.prototype.recordName = "$route";
100
- Route.prototype.prefix = false;
101
-
102
- Widget.alias("route", Route);
1
+ import { Widget } from "../../ui/Widget";
2
+ import { PureContainer } from "../../ui/PureContainer";
3
+ import RouteMatcher from "route-parser";
4
+ import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
5
+ import { routeAppend } from "../../util/routeAppend";
6
+
7
+ export class Route extends PureContainer {
8
+ init() {
9
+ if (this.path) this.route = this.path;
10
+
11
+ super.init();
12
+
13
+ if (this.route && this.route[0] !== "+")
14
+ this.matcher = new RouteMatcher(this.route + (this.prefix ? "(*remainder)" : ""));
15
+ }
16
+
17
+ initInstance(context, instance) {
18
+ instance.store = new ReadOnlyDataView({
19
+ store: instance.parentStore,
20
+ });
21
+ super.initInstance(context, instance);
22
+ }
23
+
24
+ applyParentStore(instance) {
25
+ instance.store.setStore(instance.parentStore);
26
+ }
27
+
28
+ declareData() {
29
+ super.declareData(...arguments, {
30
+ url: undefined,
31
+ });
32
+ }
33
+
34
+ checkVisible(context, instance, data) {
35
+ if (!data.visible) return false;
36
+
37
+ if (data.url !== instance.cached.url) {
38
+ instance.cached.url = data.url;
39
+ let matcher = this.matcher;
40
+ let route = this.route;
41
+ if (this.route[0] === "+") {
42
+ route = routeAppend(context.lastRoute.route, this.route.substring(1));
43
+ if (!instance.cached.matcher || instance.cached.route !== route)
44
+ instance.cached.matcher = new RouteMatcher(route + (this.prefix ? "(*remainder)" : ""));
45
+ matcher = instance.cached.matcher;
46
+ }
47
+ instance.cached.result = matcher.match(data.url);
48
+ instance.cached.matcher = matcher;
49
+ instance.cached.route = data.route = route;
50
+ }
51
+ if (!instance.cached.result) return false;
52
+
53
+ return super.checkVisible(context, instance, data);
54
+ }
55
+
56
+ prepareData(context, { data, store, cached }) {
57
+ super.prepareData(...arguments);
58
+
59
+ store.setData({
60
+ [this.recordName]: cached.result,
61
+ });
62
+
63
+ //TODO: Replace comparison with deepEquals
64
+ if (this.params && this.params.bind) {
65
+ var params = store.get(this.params.bind);
66
+ if (JSON.stringify(params) != JSON.stringify(cached.result)) {
67
+ store.set(this.params.bind, cached.result);
68
+ }
69
+ }
70
+
71
+ if (this.map) {
72
+ for (var key in result) {
73
+ var binding = this.map[key];
74
+ if (binding) store.set(binding, result[key]);
75
+ }
76
+ }
77
+ }
78
+
79
+ explore(context, instance) {
80
+ context.push("lastRoute", {
81
+ route: instance.cached.route,
82
+ result: instance.cached.result,
83
+ reverse: function (data) {
84
+ return instance.cached.matcher.reverse({
85
+ ...instance.cached.result,
86
+ remainder: "",
87
+ ...data,
88
+ });
89
+ },
90
+ });
91
+ super.explore(context, instance);
92
+ }
93
+
94
+ exploreCleanup(context, instance) {
95
+ context.pop("lastRoute");
96
+ }
97
+ }
98
+
99
+ Route.prototype.recordName = "$route";
100
+ Route.prototype.prefix = false;
101
+
102
+ Widget.alias("route", Route);