cx 25.5.1 → 25.6.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.
- package/dist/charts.js +40 -21
- package/dist/manifest.js +771 -771
- package/dist/ui.js +0 -15
- package/dist/widgets.js +34 -25
- package/package.json +1 -1
- package/src/charts/LineGraph.js +1 -1
- package/src/charts/axis/NumericAxis.d.ts +46 -46
- package/src/charts/helpers/PointReducer.d.ts +9 -0
- package/src/charts/helpers/PointReducer.js +36 -22
- package/src/data/AugmentedViewBase.js +77 -77
- package/src/data/ExposedRecordView.js +75 -75
- package/src/data/ExposedValueView.js +73 -73
- package/src/data/Ref.d.ts +24 -24
- package/src/data/Ref.spec.js +79 -79
- package/src/data/StoreRef.spec.js +24 -24
- package/src/data/StructuredDataAccessor.d.ts +7 -7
- package/src/data/SubscribableView.js +54 -54
- package/src/ui/Container.js +154 -154
- package/src/ui/DataProxy.js +31 -45
- package/src/ui/DetachedScope.js +98 -98
- package/src/ui/Instance.d.ts +72 -72
- package/src/ui/Instance.js +623 -623
- package/src/ui/IsolatedScope.js +30 -30
- package/src/ui/Repeater.js +109 -109
- package/src/ui/Rescope.js +35 -35
- package/src/ui/Restate.js +167 -167
- package/src/ui/Widget.js +184 -184
- package/src/ui/adapter/ArrayAdapter.js +152 -152
- package/src/ui/adapter/TreeAdapter.js +101 -101
- package/src/ui/createFunctionalComponent.d.ts +1 -1
- package/src/ui/index.d.ts +42 -42
- package/src/ui/layout/exploreChildren.d.ts +12 -12
- package/src/ui/layout/exploreChildren.js +27 -27
- package/src/util/debounce.js +18 -18
- package/src/util/validatedDebounce.js +19 -19
- package/src/widgets/Button.js +118 -118
- package/src/widgets/List.js +594 -594
- package/src/widgets/form/Calendar.d.ts +86 -86
- package/src/widgets/form/Checkbox.js +5 -2
- package/src/widgets/form/MonthField.d.ts +5 -0
- package/src/widgets/form/MonthField.js +1 -0
- package/src/widgets/form/MonthPicker.d.ts +13 -0
- package/src/widgets/form/MonthPicker.js +25 -21
- package/src/widgets/grid/Grid.js +3421 -3421
- package/src/widgets/nav/Route.js +102 -102
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
import { getAccessor } from "../../data/getAccessor";
|
|
2
|
-
import { isArray } from "../../util/isArray";
|
|
3
|
-
import { ArrayAdapter } from "./ArrayAdapter";
|
|
4
|
-
|
|
5
|
-
export class TreeAdapter extends ArrayAdapter {
|
|
6
|
-
init() {
|
|
7
|
-
super.init();
|
|
8
|
-
this.childrenAccessor = getAccessor({ bind: `${this.recordName}.${this.childrenField}` });
|
|
9
|
-
|
|
10
|
-
if (this.restoreExpandedNodesOnLoad) {
|
|
11
|
-
if (!this.keyField)
|
|
12
|
-
throw new Error(
|
|
13
|
-
"Stateful tree adapter requires keyField property to be specified on either Grid or data adapter.",
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
this.expandedState = {
|
|
17
|
-
next: new Set(),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
mapRecords(context, instance, data, parentStore, recordsAccessor) {
|
|
23
|
-
let nodes = super.mapRecords(context, instance, data, parentStore, recordsAccessor);
|
|
24
|
-
let result = [];
|
|
25
|
-
|
|
26
|
-
if (this.restoreExpandedNodesOnLoad) {
|
|
27
|
-
this.expandedState = {
|
|
28
|
-
current: this.expandedState.next,
|
|
29
|
-
next: new Set(),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
this.processList(context, instance, 0, "", nodes, result);
|
|
34
|
-
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
processList(context, instance, level, parentKey, nodes, result) {
|
|
39
|
-
nodes.forEach((record) => {
|
|
40
|
-
record.key = parentKey + record.key;
|
|
41
|
-
this.processNode(context, instance, level, result, record);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
processNode(context, instance, level, result, record) {
|
|
46
|
-
let isHiddenRootNode = level == 0 && this.hideRootNodes;
|
|
47
|
-
if (!isHiddenRootNode) result.push(record);
|
|
48
|
-
let { data, store } = record;
|
|
49
|
-
data.$level = this.hideRootNodes ? level - 1 : level;
|
|
50
|
-
if (!data[this.leafField]) {
|
|
51
|
-
if (this.restoreExpandedNodesOnLoad && data[this.expandedField] == null)
|
|
52
|
-
data[this.expandedField] = this.expandedState.current.has(data[this.keyField]);
|
|
53
|
-
|
|
54
|
-
if (data[this.expandedField] || isHiddenRootNode) {
|
|
55
|
-
if (this.restoreExpandedNodesOnLoad) this.expandedState.next.add(data[this.keyField]);
|
|
56
|
-
|
|
57
|
-
if (data[this.childrenField]) {
|
|
58
|
-
let childNodes = super.mapRecords(
|
|
59
|
-
context,
|
|
60
|
-
instance,
|
|
61
|
-
data[this.childrenField],
|
|
62
|
-
store,
|
|
63
|
-
this.childrenAccessor,
|
|
64
|
-
);
|
|
65
|
-
this.processList(context, instance, level + 1, record.key + ":", childNodes, result);
|
|
66
|
-
} else if (this.load && !data[this.loadedField] && !data[this.loadingField]) {
|
|
67
|
-
store.set(`${this.recordName}.${this.loadingField}`, true);
|
|
68
|
-
let response = this.load(context, instance, data);
|
|
69
|
-
Promise.resolve(response)
|
|
70
|
-
.then((children) => {
|
|
71
|
-
store.set(`${this.recordName}.${this.childrenField}`, children);
|
|
72
|
-
store.set(`${this.recordName}.${this.loadedField}`, true);
|
|
73
|
-
store.set(`${this.recordName}.${this.loadingField}`, false);
|
|
74
|
-
})
|
|
75
|
-
.catch((response) => {
|
|
76
|
-
store.set(`${this.recordName}.${this.loadingField}`, false);
|
|
77
|
-
if (this.onLoadError) this.onLoadError(response);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
} else data[this.expandedField] = false;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
sort(sorters) {
|
|
85
|
-
if (this.foldersFirst) {
|
|
86
|
-
if (!sorters || !isArray(sorters)) sorters = [];
|
|
87
|
-
sorters = [{ field: this.leafField, direction: "ASC" }, ...sorters];
|
|
88
|
-
}
|
|
89
|
-
super.sort(sorters);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
TreeAdapter.prototype.childrenField = "$children";
|
|
94
|
-
TreeAdapter.prototype.expandedField = "$expanded";
|
|
95
|
-
TreeAdapter.prototype.leafField = "$leaf";
|
|
96
|
-
TreeAdapter.prototype.loadingField = "$loading";
|
|
97
|
-
TreeAdapter.prototype.loadedField = "$loaded";
|
|
98
|
-
TreeAdapter.prototype.foldersFirst = true;
|
|
99
|
-
TreeAdapter.prototype.isTreeAdapter = true;
|
|
100
|
-
TreeAdapter.prototype.hideRootNodes = false;
|
|
101
|
-
TreeAdapter.prototype.cacheByKeyField = false;
|
|
1
|
+
import { getAccessor } from "../../data/getAccessor";
|
|
2
|
+
import { isArray } from "../../util/isArray";
|
|
3
|
+
import { ArrayAdapter } from "./ArrayAdapter";
|
|
4
|
+
|
|
5
|
+
export class TreeAdapter extends ArrayAdapter {
|
|
6
|
+
init() {
|
|
7
|
+
super.init();
|
|
8
|
+
this.childrenAccessor = getAccessor({ bind: `${this.recordName}.${this.childrenField}` });
|
|
9
|
+
|
|
10
|
+
if (this.restoreExpandedNodesOnLoad) {
|
|
11
|
+
if (!this.keyField)
|
|
12
|
+
throw new Error(
|
|
13
|
+
"Stateful tree adapter requires keyField property to be specified on either Grid or data adapter.",
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
this.expandedState = {
|
|
17
|
+
next: new Set(),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
mapRecords(context, instance, data, parentStore, recordsAccessor) {
|
|
23
|
+
let nodes = super.mapRecords(context, instance, data, parentStore, recordsAccessor);
|
|
24
|
+
let result = [];
|
|
25
|
+
|
|
26
|
+
if (this.restoreExpandedNodesOnLoad) {
|
|
27
|
+
this.expandedState = {
|
|
28
|
+
current: this.expandedState.next,
|
|
29
|
+
next: new Set(),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.processList(context, instance, 0, "", nodes, result);
|
|
34
|
+
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
processList(context, instance, level, parentKey, nodes, result) {
|
|
39
|
+
nodes.forEach((record) => {
|
|
40
|
+
record.key = parentKey + record.key;
|
|
41
|
+
this.processNode(context, instance, level, result, record);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
processNode(context, instance, level, result, record) {
|
|
46
|
+
let isHiddenRootNode = level == 0 && this.hideRootNodes;
|
|
47
|
+
if (!isHiddenRootNode) result.push(record);
|
|
48
|
+
let { data, store } = record;
|
|
49
|
+
data.$level = this.hideRootNodes ? level - 1 : level;
|
|
50
|
+
if (!data[this.leafField]) {
|
|
51
|
+
if (this.restoreExpandedNodesOnLoad && data[this.expandedField] == null)
|
|
52
|
+
data[this.expandedField] = this.expandedState.current.has(data[this.keyField]);
|
|
53
|
+
|
|
54
|
+
if (data[this.expandedField] || isHiddenRootNode) {
|
|
55
|
+
if (this.restoreExpandedNodesOnLoad) this.expandedState.next.add(data[this.keyField]);
|
|
56
|
+
|
|
57
|
+
if (data[this.childrenField]) {
|
|
58
|
+
let childNodes = super.mapRecords(
|
|
59
|
+
context,
|
|
60
|
+
instance,
|
|
61
|
+
data[this.childrenField],
|
|
62
|
+
store,
|
|
63
|
+
this.childrenAccessor,
|
|
64
|
+
);
|
|
65
|
+
this.processList(context, instance, level + 1, record.key + ":", childNodes, result);
|
|
66
|
+
} else if (this.load && !data[this.loadedField] && !data[this.loadingField]) {
|
|
67
|
+
store.set(`${this.recordName}.${this.loadingField}`, true);
|
|
68
|
+
let response = this.load(context, instance, data);
|
|
69
|
+
Promise.resolve(response)
|
|
70
|
+
.then((children) => {
|
|
71
|
+
store.set(`${this.recordName}.${this.childrenField}`, children);
|
|
72
|
+
store.set(`${this.recordName}.${this.loadedField}`, true);
|
|
73
|
+
store.set(`${this.recordName}.${this.loadingField}`, false);
|
|
74
|
+
})
|
|
75
|
+
.catch((response) => {
|
|
76
|
+
store.set(`${this.recordName}.${this.loadingField}`, false);
|
|
77
|
+
if (this.onLoadError) this.onLoadError(response);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
} else data[this.expandedField] = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
sort(sorters) {
|
|
85
|
+
if (this.foldersFirst) {
|
|
86
|
+
if (!sorters || !isArray(sorters)) sorters = [];
|
|
87
|
+
sorters = [{ field: this.leafField, direction: "ASC" }, ...sorters];
|
|
88
|
+
}
|
|
89
|
+
super.sort(sorters);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
TreeAdapter.prototype.childrenField = "$children";
|
|
94
|
+
TreeAdapter.prototype.expandedField = "$expanded";
|
|
95
|
+
TreeAdapter.prototype.leafField = "$leaf";
|
|
96
|
+
TreeAdapter.prototype.loadingField = "$loading";
|
|
97
|
+
TreeAdapter.prototype.loadedField = "$loaded";
|
|
98
|
+
TreeAdapter.prototype.foldersFirst = true;
|
|
99
|
+
TreeAdapter.prototype.isTreeAdapter = true;
|
|
100
|
+
TreeAdapter.prototype.hideRootNodes = false;
|
|
101
|
+
TreeAdapter.prototype.cacheByKeyField = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function createFunctionalComponent<T, X>(factory: (props: T) => X): (props: T) => X;
|
|
1
|
+
export function createFunctionalComponent<T, X>(factory: (props: T) => X): (props: T) => X;
|
package/src/ui/index.d.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
export * from "./Controller";
|
|
2
|
-
export * from "./Widget";
|
|
3
|
-
export * from "./Container";
|
|
4
|
-
export * from "./PureContainer";
|
|
5
|
-
export * from "./Repeater";
|
|
6
|
-
export * from "./Rescope";
|
|
7
|
-
export * from "./StaticText";
|
|
8
|
-
export * from "./Text";
|
|
9
|
-
export * from "./CSS";
|
|
10
|
-
export * from "./CSSHelper";
|
|
11
|
-
export * from "./FocusManager";
|
|
12
|
-
export * from "./ResizeManager";
|
|
13
|
-
export * from "./ZIndexManager";
|
|
14
|
-
export * from "./Format";
|
|
15
|
-
export * from "./Culture";
|
|
16
|
-
export * from "./Localization";
|
|
17
|
-
export * from "./Cx";
|
|
18
|
-
export * from "./Instance";
|
|
19
|
-
export * from "./RenderingContext";
|
|
20
|
-
export * from "./ContentResolver";
|
|
21
|
-
export * from "./batchUpdates";
|
|
22
|
-
export * from "./IsolatedScope";
|
|
23
|
-
export * from "./DetachedScope";
|
|
24
|
-
export * from "./Restate";
|
|
25
|
-
export * from "./DataProxy";
|
|
26
|
-
export * from "./keyboardShortcuts";
|
|
27
|
-
export * from "./createFunctionalComponent";
|
|
28
|
-
export * from "./StructuredInstanceDataAccessor";
|
|
29
|
-
export * from "./HoverSync";
|
|
30
|
-
|
|
31
|
-
export * from "./selection/index";
|
|
32
|
-
export * from "./layout/index";
|
|
33
|
-
export * from "./app/index";
|
|
34
|
-
export * from "./adapter/index";
|
|
35
|
-
|
|
36
|
-
export * from "./bind";
|
|
37
|
-
export * from "./tpl";
|
|
38
|
-
export * from "./expr";
|
|
39
|
-
|
|
40
|
-
//re-export computable here
|
|
41
|
-
import { computable } from "../data/computable";
|
|
42
|
-
export { computable };
|
|
1
|
+
export * from "./Controller";
|
|
2
|
+
export * from "./Widget";
|
|
3
|
+
export * from "./Container";
|
|
4
|
+
export * from "./PureContainer";
|
|
5
|
+
export * from "./Repeater";
|
|
6
|
+
export * from "./Rescope";
|
|
7
|
+
export * from "./StaticText";
|
|
8
|
+
export * from "./Text";
|
|
9
|
+
export * from "./CSS";
|
|
10
|
+
export * from "./CSSHelper";
|
|
11
|
+
export * from "./FocusManager";
|
|
12
|
+
export * from "./ResizeManager";
|
|
13
|
+
export * from "./ZIndexManager";
|
|
14
|
+
export * from "./Format";
|
|
15
|
+
export * from "./Culture";
|
|
16
|
+
export * from "./Localization";
|
|
17
|
+
export * from "./Cx";
|
|
18
|
+
export * from "./Instance";
|
|
19
|
+
export * from "./RenderingContext";
|
|
20
|
+
export * from "./ContentResolver";
|
|
21
|
+
export * from "./batchUpdates";
|
|
22
|
+
export * from "./IsolatedScope";
|
|
23
|
+
export * from "./DetachedScope";
|
|
24
|
+
export * from "./Restate";
|
|
25
|
+
export * from "./DataProxy";
|
|
26
|
+
export * from "./keyboardShortcuts";
|
|
27
|
+
export * from "./createFunctionalComponent";
|
|
28
|
+
export * from "./StructuredInstanceDataAccessor";
|
|
29
|
+
export * from "./HoverSync";
|
|
30
|
+
|
|
31
|
+
export * from "./selection/index";
|
|
32
|
+
export * from "./layout/index";
|
|
33
|
+
export * from "./app/index";
|
|
34
|
+
export * from "./adapter/index";
|
|
35
|
+
|
|
36
|
+
export * from "./bind";
|
|
37
|
+
export * from "./tpl";
|
|
38
|
+
export * from "./expr";
|
|
39
|
+
|
|
40
|
+
//re-export computable here
|
|
41
|
+
import { computable } from "../data/computable";
|
|
42
|
+
export { computable };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { View } from "../../data/View";
|
|
2
|
-
import { Instance } from "../Instance";
|
|
3
|
-
import { RenderingContext } from "../RenderingContext";
|
|
4
|
-
|
|
5
|
-
export function exploreChildren(
|
|
6
|
-
context: RenderingContext,
|
|
7
|
-
instance: Instance,
|
|
8
|
-
children: Instance[],
|
|
9
|
-
previousResult: Instance[],
|
|
10
|
-
key?: string,
|
|
11
|
-
store?: View,
|
|
12
|
-
): Instance[];
|
|
1
|
+
import { View } from "../../data/View";
|
|
2
|
+
import { Instance } from "../Instance";
|
|
3
|
+
import { RenderingContext } from "../RenderingContext";
|
|
4
|
+
|
|
5
|
+
export function exploreChildren(
|
|
6
|
+
context: RenderingContext,
|
|
7
|
+
instance: Instance,
|
|
8
|
+
children: Instance[],
|
|
9
|
+
previousResult: Instance[],
|
|
10
|
+
key?: string,
|
|
11
|
+
store?: View,
|
|
12
|
+
): Instance[];
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export function exploreChildren(context, instance, children, previousResult, key, store) {
|
|
2
|
-
let newChildren = previousResult || [];
|
|
3
|
-
let oldChildren = previousResult || newChildren;
|
|
4
|
-
let identical = previousResult ? 0 : -1;
|
|
5
|
-
|
|
6
|
-
for (let c = 0; c < children.length; c++) {
|
|
7
|
-
let cell = instance.getChild(context, children[c], key, store);
|
|
8
|
-
|
|
9
|
-
if (cell.checkVisible(context)) {
|
|
10
|
-
if (identical >= 0) {
|
|
11
|
-
if (cell == oldChildren[identical]) identical++;
|
|
12
|
-
else {
|
|
13
|
-
newChildren = newChildren.slice(0, identical);
|
|
14
|
-
identical = -1;
|
|
15
|
-
newChildren.push(cell);
|
|
16
|
-
}
|
|
17
|
-
} else newChildren.push(cell);
|
|
18
|
-
|
|
19
|
-
context.exploreStack.push(cell);
|
|
20
|
-
if (cell.needsExploreCleanup) context.exploreStack.push(cell);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (identical >= 0 && identical != newChildren.length) newChildren = newChildren.slice(0, identical);
|
|
25
|
-
|
|
26
|
-
return newChildren;
|
|
27
|
-
}
|
|
1
|
+
export function exploreChildren(context, instance, children, previousResult, key, store) {
|
|
2
|
+
let newChildren = previousResult || [];
|
|
3
|
+
let oldChildren = previousResult || newChildren;
|
|
4
|
+
let identical = previousResult ? 0 : -1;
|
|
5
|
+
|
|
6
|
+
for (let c = 0; c < children.length; c++) {
|
|
7
|
+
let cell = instance.getChild(context, children[c], key, store);
|
|
8
|
+
|
|
9
|
+
if (cell.checkVisible(context)) {
|
|
10
|
+
if (identical >= 0) {
|
|
11
|
+
if (cell == oldChildren[identical]) identical++;
|
|
12
|
+
else {
|
|
13
|
+
newChildren = newChildren.slice(0, identical);
|
|
14
|
+
identical = -1;
|
|
15
|
+
newChildren.push(cell);
|
|
16
|
+
}
|
|
17
|
+
} else newChildren.push(cell);
|
|
18
|
+
|
|
19
|
+
context.exploreStack.push(cell);
|
|
20
|
+
if (cell.needsExploreCleanup) context.exploreStack.push(cell);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (identical >= 0 && identical != newChildren.length) newChildren = newChildren.slice(0, identical);
|
|
25
|
+
|
|
26
|
+
return newChildren;
|
|
27
|
+
}
|
package/src/util/debounce.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export function debounce(callback, delay) {
|
|
2
|
-
let timer;
|
|
3
|
-
|
|
4
|
-
let result = function (...args) {
|
|
5
|
-
let context = this;
|
|
6
|
-
clearTimeout(timer);
|
|
7
|
-
timer = setTimeout(function () {
|
|
8
|
-
callback.apply(context, args);
|
|
9
|
-
}, delay);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
result.reset = function reset(...args) {
|
|
13
|
-
clearTimeout(timer);
|
|
14
|
-
callback.apply(this, args);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
1
|
+
export function debounce(callback, delay) {
|
|
2
|
+
let timer;
|
|
3
|
+
|
|
4
|
+
let result = function (...args) {
|
|
5
|
+
let context = this;
|
|
6
|
+
clearTimeout(timer);
|
|
7
|
+
timer = setTimeout(function () {
|
|
8
|
+
callback.apply(context, args);
|
|
9
|
+
}, delay);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
result.reset = function reset(...args) {
|
|
13
|
+
clearTimeout(timer);
|
|
14
|
+
callback.apply(this, args);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export function validatedDebounce(callback, valueGetter, delay) {
|
|
2
|
-
let timer;
|
|
3
|
-
let result = function (...args) {
|
|
4
|
-
clearTimeout(timer);
|
|
5
|
-
let prev = valueGetter();
|
|
6
|
-
timer = setTimeout(function () {
|
|
7
|
-
let now = valueGetter();
|
|
8
|
-
if (prev !== now) return;
|
|
9
|
-
callback(...args);
|
|
10
|
-
}, delay);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
result.reset = function reset(...args) {
|
|
14
|
-
clearTimeout(timer);
|
|
15
|
-
callback(...args);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
1
|
+
export function validatedDebounce(callback, valueGetter, delay) {
|
|
2
|
+
let timer;
|
|
3
|
+
let result = function (...args) {
|
|
4
|
+
clearTimeout(timer);
|
|
5
|
+
let prev = valueGetter();
|
|
6
|
+
timer = setTimeout(function () {
|
|
7
|
+
let now = valueGetter();
|
|
8
|
+
if (prev !== now) return;
|
|
9
|
+
callback(...args);
|
|
10
|
+
}, delay);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
result.reset = function reset(...args) {
|
|
14
|
+
clearTimeout(timer);
|
|
15
|
+
callback(...args);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return result;
|
|
19
|
+
}
|