cross-state 0.6.7 → 0.6.9
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/cjs/hash.cjs +712 -0
- package/dist/cjs/hash.cjs.map +1 -0
- package/dist/cjs/immer.cjs +7 -2
- package/dist/cjs/immer.cjs.map +1 -1
- package/dist/cjs/index.cjs +341 -19
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/react.cjs +289 -11
- package/dist/cjs/react.cjs.map +1 -1
- package/dist/es/hash.mjs +713 -0
- package/dist/es/hash.mjs.map +1 -0
- package/dist/es/{immer/immerActions.js → immer.mjs} +1 -1
- package/dist/es/immer.mjs.map +1 -0
- package/dist/es/{core/cache.js → index.mjs} +126 -8
- package/dist/es/index.mjs.map +1 -0
- package/dist/es/react.mjs +292 -0
- package/dist/es/react.mjs.map +1 -0
- package/package.json +8 -8
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.development.cjs +0 -103
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.development.cjs.map +0 -1
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.development2.cjs +0 -5
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.development2.cjs.map +0 -1
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min.cjs +0 -71
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min.cjs.map +0 -1
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min2.cjs +0 -5
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min2.cjs.map +0 -1
- package/dist/cjs/_virtual/with-selector.cjs +0 -12
- package/dist/cjs/_virtual/with-selector.cjs.map +0 -1
- package/dist/cjs/_virtual/with-selector2.cjs +0 -13
- package/dist/cjs/_virtual/with-selector2.cjs.map +0 -1
- package/dist/cjs/core/cache.cjs +0 -227
- package/dist/cjs/core/cache.cjs.map +0 -1
- package/dist/cjs/core/resourceGroup.cjs +0 -53
- package/dist/cjs/core/resourceGroup.cjs.map +0 -1
- package/dist/cjs/core/store.cjs +0 -259
- package/dist/cjs/core/store.cjs.map +0 -1
- package/dist/cjs/immer/immerActions.cjs +0 -10
- package/dist/cjs/immer/immerActions.cjs.map +0 -1
- package/dist/cjs/lib/calcDuration.cjs +0 -9
- package/dist/cjs/lib/calcDuration.cjs.map +0 -1
- package/dist/cjs/lib/calculationHelper.cjs +0 -140
- package/dist/cjs/lib/calculationHelper.cjs.map +0 -1
- package/dist/cjs/lib/callable.cjs +0 -11
- package/dist/cjs/lib/callable.cjs.map +0 -1
- package/dist/cjs/lib/clone.cjs +0 -19
- package/dist/cjs/lib/clone.cjs.map +0 -1
- package/dist/cjs/lib/debounce.cjs +0 -28
- package/dist/cjs/lib/debounce.cjs.map +0 -1
- package/dist/cjs/lib/equals.cjs +0 -5
- package/dist/cjs/lib/equals.cjs.map +0 -1
- package/dist/cjs/lib/forwardError.cjs +0 -9
- package/dist/cjs/lib/forwardError.cjs.map +0 -1
- package/dist/cjs/lib/hash.cjs +0 -19
- package/dist/cjs/lib/hash.cjs.map +0 -1
- package/dist/cjs/lib/instanceCache.cjs +0 -68
- package/dist/cjs/lib/instanceCache.cjs.map +0 -1
- package/dist/cjs/lib/makeSelector.cjs +0 -14
- package/dist/cjs/lib/makeSelector.cjs.map +0 -1
- package/dist/cjs/lib/propAccess.cjs +0 -66
- package/dist/cjs/lib/propAccess.cjs.map +0 -1
- package/dist/cjs/lib/queue.cjs +0 -61
- package/dist/cjs/lib/queue.cjs.map +0 -1
- package/dist/cjs/lib/standardMethods.cjs +0 -78
- package/dist/cjs/lib/standardMethods.cjs.map +0 -1
- package/dist/cjs/lib/throttle.cjs +0 -25
- package/dist/cjs/lib/throttle.cjs.map +0 -1
- package/dist/cjs/lib/trackingProxy.cjs +0 -39
- package/dist/cjs/lib/trackingProxy.cjs.map +0 -1
- package/dist/cjs/react/read.cjs +0 -15
- package/dist/cjs/react/read.cjs.map +0 -1
- package/dist/cjs/react/storeScope.cjs +0 -31
- package/dist/cjs/react/storeScope.cjs.map +0 -1
- package/dist/cjs/react/useCache.cjs +0 -31
- package/dist/cjs/react/useCache.cjs.map +0 -1
- package/dist/cjs/react/useProp.cjs +0 -9
- package/dist/cjs/react/useProp.cjs.map +0 -1
- package/dist/cjs/react/useStore.cjs +0 -51
- package/dist/cjs/react/useStore.cjs.map +0 -1
- package/dist/es/_virtual/use-sync-external-store-with-selector.development.js +0 -103
- package/dist/es/_virtual/use-sync-external-store-with-selector.development.js.map +0 -1
- package/dist/es/_virtual/use-sync-external-store-with-selector.development2.js +0 -5
- package/dist/es/_virtual/use-sync-external-store-with-selector.development2.js.map +0 -1
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min.js +0 -71
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min.js.map +0 -1
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min2.js +0 -5
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min2.js.map +0 -1
- package/dist/es/_virtual/with-selector.js +0 -11
- package/dist/es/_virtual/with-selector.js.map +0 -1
- package/dist/es/_virtual/with-selector2.js +0 -14
- package/dist/es/_virtual/with-selector2.js.map +0 -1
- package/dist/es/core/cache.js.map +0 -1
- package/dist/es/core/resourceGroup.js +0 -53
- package/dist/es/core/resourceGroup.js.map +0 -1
- package/dist/es/core/store.js +0 -259
- package/dist/es/core/store.js.map +0 -1
- package/dist/es/immer/immerActions.js.map +0 -1
- package/dist/es/immer.js +0 -5
- package/dist/es/immer.js.map +0 -1
- package/dist/es/index.js +0 -22
- package/dist/es/index.js.map +0 -1
- package/dist/es/lib/calcDuration.js +0 -9
- package/dist/es/lib/calcDuration.js.map +0 -1
- package/dist/es/lib/calculationHelper.js +0 -140
- package/dist/es/lib/calculationHelper.js.map +0 -1
- package/dist/es/lib/callable.js +0 -11
- package/dist/es/lib/callable.js.map +0 -1
- package/dist/es/lib/clone.js +0 -19
- package/dist/es/lib/clone.js.map +0 -1
- package/dist/es/lib/debounce.js +0 -28
- package/dist/es/lib/debounce.js.map +0 -1
- package/dist/es/lib/equals.js +0 -5
- package/dist/es/lib/equals.js.map +0 -1
- package/dist/es/lib/forwardError.js +0 -9
- package/dist/es/lib/forwardError.js.map +0 -1
- package/dist/es/lib/hash.js +0 -19
- package/dist/es/lib/hash.js.map +0 -1
- package/dist/es/lib/instanceCache.js +0 -68
- package/dist/es/lib/instanceCache.js.map +0 -1
- package/dist/es/lib/makeSelector.js +0 -14
- package/dist/es/lib/makeSelector.js.map +0 -1
- package/dist/es/lib/propAccess.js +0 -66
- package/dist/es/lib/propAccess.js.map +0 -1
- package/dist/es/lib/queue.js +0 -61
- package/dist/es/lib/queue.js.map +0 -1
- package/dist/es/lib/standardMethods.js +0 -78
- package/dist/es/lib/standardMethods.js.map +0 -1
- package/dist/es/lib/throttle.js +0 -25
- package/dist/es/lib/throttle.js.map +0 -1
- package/dist/es/lib/trackingProxy.js +0 -39
- package/dist/es/lib/trackingProxy.js.map +0 -1
- package/dist/es/react/read.js +0 -15
- package/dist/es/react/read.js.map +0 -1
- package/dist/es/react/storeScope.js +0 -31
- package/dist/es/react/storeScope.js.map +0 -1
- package/dist/es/react/useCache.js +0 -31
- package/dist/es/react/useCache.js.map +0 -1
- package/dist/es/react/useProp.js +0 -9
- package/dist/es/react/useProp.js.map +0 -1
- package/dist/es/react/useStore.js +0 -51
- package/dist/es/react/useStore.js.map +0 -1
- package/dist/es/react.js +0 -14
- package/dist/es/react.js.map +0 -1
package/dist/cjs/core/store.cjs
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const calcDuration = require("../lib/calcDuration.cjs");
|
|
4
|
-
const calculationHelper = require("../lib/calculationHelper.cjs");
|
|
5
|
-
const callable = require("../lib/callable.cjs");
|
|
6
|
-
const debounce = require("../lib/debounce.cjs");
|
|
7
|
-
const equals = require("../lib/equals.cjs");
|
|
8
|
-
const forwardError = require("../lib/forwardError.cjs");
|
|
9
|
-
const makeSelector = require("../lib/makeSelector.cjs");
|
|
10
|
-
const propAccess = require("../lib/propAccess.cjs");
|
|
11
|
-
const standardMethods = require("../lib/standardMethods.cjs");
|
|
12
|
-
const throttle = require("../lib/throttle.cjs");
|
|
13
|
-
const noop = () => void 0;
|
|
14
|
-
class Store extends callable.Callable {
|
|
15
|
-
constructor(getter, options = {}, derivedFrom, _call = () => void 0) {
|
|
16
|
-
super(_call);
|
|
17
|
-
this.getter = getter;
|
|
18
|
-
this.options = options;
|
|
19
|
-
this.derivedFrom = derivedFrom;
|
|
20
|
-
this._call = _call;
|
|
21
|
-
this.listeners = /* @__PURE__ */ new Map();
|
|
22
|
-
this.effects = /* @__PURE__ */ new Map();
|
|
23
|
-
this.notifyId = {};
|
|
24
|
-
this.calculationHelper = new calculationHelper.CalculationHelper({
|
|
25
|
-
calculate: ({ use }) => {
|
|
26
|
-
if (this.getter instanceof Function) {
|
|
27
|
-
const value = this.getter.apply({ use }, [{ use }]);
|
|
28
|
-
this._value = { v: value };
|
|
29
|
-
this.notify();
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
addEffect: this.addEffect.bind(this),
|
|
33
|
-
onInvalidate: this.reset.bind(this)
|
|
34
|
-
});
|
|
35
|
-
this.get = this.get.bind(this);
|
|
36
|
-
this.set = this.set.bind(this);
|
|
37
|
-
this.sub = this.sub.bind(this);
|
|
38
|
-
this.once = this.once.bind(this);
|
|
39
|
-
this.map = this.map.bind(this);
|
|
40
|
-
this.addEffect = this.addEffect.bind(this);
|
|
41
|
-
this.isActive = this.isActive.bind(this);
|
|
42
|
-
if (!(getter instanceof Function)) {
|
|
43
|
-
this._value = { v: getter };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
get() {
|
|
47
|
-
this.calculationHelper.check();
|
|
48
|
-
if (!this._value) {
|
|
49
|
-
this.calculationHelper.execute();
|
|
50
|
-
return this.get();
|
|
51
|
-
}
|
|
52
|
-
return this._value.v;
|
|
53
|
-
}
|
|
54
|
-
set(...args) {
|
|
55
|
-
const path = args.length > 1 ? args[0] : [];
|
|
56
|
-
let update = args.length > 1 ? args[1] : args[0];
|
|
57
|
-
if (update instanceof Function) {
|
|
58
|
-
const before = this.get();
|
|
59
|
-
const valueBefore = propAccess.get(before, path);
|
|
60
|
-
const valueAfter = update(valueBefore);
|
|
61
|
-
update = propAccess.set(before, path, valueAfter);
|
|
62
|
-
} else if (path.length > 0) {
|
|
63
|
-
update = propAccess.set(this.get(), path, update);
|
|
64
|
-
}
|
|
65
|
-
if (this.derivedFrom && this.derivedFrom.selectors.every((selector) => typeof selector === "string")) {
|
|
66
|
-
const derivationPath = this.derivedFrom.selectors.join(".");
|
|
67
|
-
this.derivedFrom.store.set((before) => propAccess.set(before, derivationPath, update));
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (this.derivedFrom) {
|
|
71
|
-
throw new TypeError(
|
|
72
|
-
"Can only updated computed stores that are derived from other stores using string selectors"
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
this._value = { v: update };
|
|
76
|
-
this.notify();
|
|
77
|
-
}
|
|
78
|
-
reset() {
|
|
79
|
-
this._value = void 0;
|
|
80
|
-
if (this.isActive()) {
|
|
81
|
-
this.calculationHelper.execute();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
sub(listener, options) {
|
|
85
|
-
var _a;
|
|
86
|
-
const {
|
|
87
|
-
passive,
|
|
88
|
-
runNow = true,
|
|
89
|
-
throttle: throttleOption,
|
|
90
|
-
debounce: debounceOption,
|
|
91
|
-
equals: equals$1 = equals.defaultEquals
|
|
92
|
-
} = options ?? {};
|
|
93
|
-
let compareToValue = (_a = this._value) == null ? void 0 : _a.v;
|
|
94
|
-
let previousValue;
|
|
95
|
-
let hasRun = false;
|
|
96
|
-
let innerListener = (force) => {
|
|
97
|
-
if (!this._value) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const value = this._value.v;
|
|
101
|
-
if (!force && equals$1(value, compareToValue)) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
compareToValue = value;
|
|
105
|
-
const _previousValue = previousValue;
|
|
106
|
-
previousValue = value;
|
|
107
|
-
hasRun = true;
|
|
108
|
-
try {
|
|
109
|
-
listener(value, _previousValue);
|
|
110
|
-
} catch (error) {
|
|
111
|
-
forwardError.forwardError(error);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
if (throttleOption) {
|
|
115
|
-
innerListener = throttle.throttle(innerListener, throttleOption);
|
|
116
|
-
} else if (debounceOption) {
|
|
117
|
-
innerListener = debounce.debounce(innerListener, debounceOption);
|
|
118
|
-
}
|
|
119
|
-
this.listeners.set(innerListener, !passive);
|
|
120
|
-
if (!passive) {
|
|
121
|
-
this.onSubscribe();
|
|
122
|
-
}
|
|
123
|
-
if (runNow && !hasRun) {
|
|
124
|
-
innerListener(true);
|
|
125
|
-
}
|
|
126
|
-
return () => {
|
|
127
|
-
this.listeners.delete(innerListener);
|
|
128
|
-
if (!passive) {
|
|
129
|
-
this.onUnsubscribe();
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
once(condition = (value) => !!value) {
|
|
134
|
-
return new Promise((resolve) => {
|
|
135
|
-
let stopped = false;
|
|
136
|
-
const cancel = this.sub(
|
|
137
|
-
(value) => {
|
|
138
|
-
if (stopped || condition && !condition(value)) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
resolve(value);
|
|
142
|
-
stopped = true;
|
|
143
|
-
setTimeout(() => cancel());
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
runNow: !!condition
|
|
147
|
-
}
|
|
148
|
-
);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
map(_selector, options) {
|
|
152
|
-
const selector = makeSelector.makeSelector(_selector);
|
|
153
|
-
const derivedFrom = {
|
|
154
|
-
store: this.derivedFrom ? this.derivedFrom.store : this,
|
|
155
|
-
selectors: this.derivedFrom ? [...this.derivedFrom.selectors, _selector] : [_selector]
|
|
156
|
-
};
|
|
157
|
-
return new Store(
|
|
158
|
-
({ use }) => {
|
|
159
|
-
return selector(use(this, options));
|
|
160
|
-
},
|
|
161
|
-
this.options,
|
|
162
|
-
derivedFrom
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
/** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.
|
|
166
|
-
* @param effect
|
|
167
|
-
* If there is already a subscriber, the effect will be executed immediately.
|
|
168
|
-
* Otherweise it will be executed as soon as the first subscription is created.
|
|
169
|
-
* Every time all subscriptions are removed and the first is created again, the effect will be executed again.
|
|
170
|
-
* @param retain
|
|
171
|
-
* If provided, delay tearing down effects when the last subscriber is removed. This is useful if a short gap in subscriber coverage is supposed to be ignored. E.g. when switching pages, the old page might unsubscribe, while the new page subscribes immediately after.
|
|
172
|
-
* @returns
|
|
173
|
-
* The effect can return a teardown callback, which will be executed when the last subscription is removed and potentially the ratain time has passed.
|
|
174
|
-
*/
|
|
175
|
-
addEffect(effect, retain) {
|
|
176
|
-
this.effects.set(effect, {
|
|
177
|
-
handle: this.isActive() ? effect() ?? noop : void 0,
|
|
178
|
-
retain: retain !== void 0 ? calcDuration.calcDuration(retain) : void 0
|
|
179
|
-
});
|
|
180
|
-
return () => {
|
|
181
|
-
const { handle, timeout } = this.effects.get(effect) ?? {};
|
|
182
|
-
handle == null ? void 0 : handle();
|
|
183
|
-
if (timeout !== void 0) {
|
|
184
|
-
clearTimeout(timeout);
|
|
185
|
-
}
|
|
186
|
-
this.effects.delete(effect);
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
/** Return whether the store is currently active, which means whether it has at least one subscriber. */
|
|
190
|
-
isActive() {
|
|
191
|
-
return [...this.listeners.values()].some(Boolean);
|
|
192
|
-
}
|
|
193
|
-
onSubscribe() {
|
|
194
|
-
if ([...this.listeners.values()].filter(Boolean).length > 1)
|
|
195
|
-
return;
|
|
196
|
-
for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {
|
|
197
|
-
if (timeout !== void 0) {
|
|
198
|
-
clearTimeout(timeout);
|
|
199
|
-
}
|
|
200
|
-
this.effects.set(effect, {
|
|
201
|
-
handle: handle ?? effect() ?? noop,
|
|
202
|
-
retain,
|
|
203
|
-
timeout: void 0
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
onUnsubscribe() {
|
|
208
|
-
if ([...this.listeners.values()].some(Boolean))
|
|
209
|
-
return;
|
|
210
|
-
for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {
|
|
211
|
-
if (!retain) {
|
|
212
|
-
handle == null ? void 0 : handle();
|
|
213
|
-
}
|
|
214
|
-
if (timeout !== void 0) {
|
|
215
|
-
clearTimeout(timeout);
|
|
216
|
-
}
|
|
217
|
-
this.effects.set(effect, {
|
|
218
|
-
handle: retain ? handle : void 0,
|
|
219
|
-
retain,
|
|
220
|
-
timeout: retain && handle ? setTimeout(handle, retain) : void 0
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
notify() {
|
|
225
|
-
const n = {};
|
|
226
|
-
this.notifyId = n;
|
|
227
|
-
const snapshot = [...this.listeners.keys()];
|
|
228
|
-
for (const listener of snapshot) {
|
|
229
|
-
listener();
|
|
230
|
-
if (n !== this.notifyId)
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
const defaultOptions = {};
|
|
236
|
-
function create(initialState, options) {
|
|
237
|
-
const store = new Store(initialState, options);
|
|
238
|
-
if (initialState instanceof Function) {
|
|
239
|
-
return store;
|
|
240
|
-
}
|
|
241
|
-
let methods = options == null ? void 0 : options.methods;
|
|
242
|
-
if (initialState instanceof Map) {
|
|
243
|
-
methods = { ...standardMethods.mapMethods, ...methods };
|
|
244
|
-
} else if (initialState instanceof Set) {
|
|
245
|
-
methods = { ...standardMethods.setMethods, ...methods };
|
|
246
|
-
} else if (Array.isArray(initialState)) {
|
|
247
|
-
methods = { ...standardMethods.arrayMethods, ...methods };
|
|
248
|
-
} else if (initialState instanceof Object) {
|
|
249
|
-
methods = { ...standardMethods.recordMethods, ...methods };
|
|
250
|
-
}
|
|
251
|
-
const boundMethods = Object.fromEntries(
|
|
252
|
-
Object.entries(methods ?? {}).filter(([name]) => !(name in store)).map(([name, action]) => [name, action.bind(store)])
|
|
253
|
-
);
|
|
254
|
-
return Object.assign(store, boundMethods);
|
|
255
|
-
}
|
|
256
|
-
const createStore = Object.assign(create, { defaultOptions });
|
|
257
|
-
exports.Store = Store;
|
|
258
|
-
exports.createStore = createStore;
|
|
259
|
-
//# sourceMappingURL=store.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.cjs","sources":["../../../src/core/store.ts"],"sourcesContent":["import type {\n Cancel,\n Duration,\n Effect,\n Listener,\n Selector,\n SubscribeOptions,\n Update,\n Use,\n UseOptions,\n} from './commonTypes';\nimport { calcDuration } from '@lib/calcDuration';\nimport { CalculationHelper } from '@lib/calculationHelper';\nimport { Callable } from '@lib/callable';\nimport { debounce } from '@lib/debounce';\nimport { defaultEquals } from '@lib/equals';\nimport { forwardError } from '@lib/forwardError';\nimport { makeSelector } from '@lib/makeSelector';\nimport type { Path, Value } from '@lib/path';\nimport { get, set } from '@lib/propAccess';\nimport { arrayMethods, mapMethods, recordMethods, setMethods } from '@lib/standardMethods';\nimport { throttle } from '@lib/throttle';\n\nexport type StoreMethods = Record<string, (...args: any[]) => any>;\n\nexport type BoundStoreMethods<T, Methods extends StoreMethods> = Methods &\n ThisType<Store<T> & Methods>;\n\nexport interface StoreOptions {\n retain?: number;\n}\n\nexport interface StoreOptionsWithMethods<T, Methods extends StoreMethods> extends StoreOptions {\n methods?: Methods & ThisType<Store<T> & Methods & StandardMethods<T>>;\n}\n\nexport type Calculate<T> = (this: { use: Use }, fns: { use: Use }) => T;\n\ntype StandardMethods<T> = T extends Map<any, any>\n ? typeof mapMethods\n : T extends Set<any>\n ? typeof setMethods\n : T extends Array<any>\n ? typeof arrayMethods\n : T extends Record<any, any>\n ? typeof recordMethods\n : Record<string, never>;\n\ntype StoreWithMethods<T, Methods extends StoreMethods> = Store<T> &\n Omit<BoundStoreMethods<T, Methods>, keyof Store<T>> &\n StandardMethods<T>;\n\nconst noop = () => undefined;\n\nexport class Store<T> extends Callable<any, any> {\n protected _value?: { v: T };\n\n protected listeners = new Map<Listener, boolean>();\n\n protected effects = new Map<\n Effect,\n { handle?: Cancel; retain?: number; timeout?: ReturnType<typeof setTimeout> }\n >();\n\n protected notifyId = {};\n\n protected calculationHelper = new CalculationHelper({\n calculate: ({ use }) => {\n if (this.getter instanceof Function) {\n const value = this.getter.apply({ use }, [{ use }]);\n this._value = { v: value };\n this.notify();\n }\n },\n\n addEffect: this.addEffect.bind(this),\n onInvalidate: this.reset.bind(this),\n });\n\n constructor(\n public readonly getter: T | Calculate<T>,\n public readonly options: StoreOptions = {},\n public readonly derivedFrom?: {\n store: Store<any>;\n selectors: (Selector<any, any> | Path<any>)[];\n },\n protected readonly _call: (...args: any[]) => any = () => undefined,\n ) {\n super(_call);\n this.get = this.get.bind(this);\n this.set = this.set.bind(this);\n this.sub = this.sub.bind(this);\n this.once = this.once.bind(this);\n this.map = this.map.bind(this);\n this.addEffect = this.addEffect.bind(this);\n this.isActive = this.isActive.bind(this);\n\n if (!(getter instanceof Function)) {\n this._value = { v: getter };\n }\n }\n\n get(): T {\n this.calculationHelper.check();\n\n if (!this._value) {\n this.calculationHelper.execute();\n return this.get();\n }\n\n return this._value.v;\n }\n\n set(update: Update<T>): void;\n\n set<P extends Path<T>>(path: P, update: Update<Value<T, P>>): void;\n\n set(...args: any[]): void {\n const path: any = args.length > 1 ? args[0] : [];\n let update: Update<any> = args.length > 1 ? args[1] : args[0];\n\n if (update instanceof Function) {\n const before = this.get();\n const valueBefore = get(before, path);\n const valueAfter = update(valueBefore);\n update = set(before, path, valueAfter);\n } else if (path.length > 0) {\n update = set(this.get(), path, update);\n }\n\n if (\n this.derivedFrom &&\n this.derivedFrom.selectors.every((selector) => typeof selector === 'string')\n ) {\n const derivationPath = this.derivedFrom.selectors.join('.');\n this.derivedFrom.store.set((before: any) => set<any, any>(before, derivationPath, update));\n return;\n }\n\n if (this.derivedFrom) {\n throw new TypeError(\n 'Can only updated computed stores that are derived from other stores using string selectors',\n );\n }\n\n this._value = { v: update };\n this.notify();\n }\n\n protected reset() {\n this._value = undefined;\n\n if (this.isActive()) {\n this.calculationHelper.execute();\n }\n }\n\n sub(listener: Listener<T>, options?: SubscribeOptions): Cancel {\n const {\n passive,\n runNow = true,\n throttle: throttleOption,\n debounce: debounceOption,\n equals = defaultEquals,\n } = options ?? {};\n\n let compareToValue = this._value?.v;\n let previousValue: T | undefined;\n let hasRun = false;\n\n let innerListener = (force?: boolean | void) => {\n if (!this._value) {\n return;\n }\n\n const value = this._value.v;\n\n if (!force && equals(value, compareToValue)) {\n return;\n }\n\n compareToValue = value;\n const _previousValue = previousValue;\n previousValue = value;\n hasRun = true;\n\n try {\n listener(value, _previousValue);\n } catch (error) {\n forwardError(error);\n }\n };\n\n if (throttleOption) {\n innerListener = throttle(innerListener, throttleOption);\n } else if (debounceOption) {\n innerListener = debounce(innerListener, debounceOption);\n }\n\n this.listeners.set(innerListener, !passive);\n if (!passive) {\n this.onSubscribe();\n }\n\n if (runNow && !hasRun) {\n innerListener(true);\n }\n\n return () => {\n this.listeners.delete(innerListener);\n if (!passive) {\n this.onUnsubscribe();\n }\n };\n }\n\n once<S extends T>(condition: (value: T) => value is S): Promise<S>;\n\n once(condition?: (value: T) => boolean): Promise<T>;\n\n once(condition: (value: T) => boolean = (value) => !!value): Promise<any> {\n return new Promise<T>((resolve) => {\n let stopped = false;\n const cancel = this.sub(\n (value) => {\n if (stopped || (condition && !condition(value))) {\n return;\n }\n\n resolve(value);\n stopped = true;\n setTimeout(() => cancel());\n },\n {\n runNow: !!condition,\n },\n );\n });\n }\n\n map<S>(selector: Selector<T, S>, options?: UseOptions): Store<S>;\n\n map<P extends Path<T>>(selector: P, options?: UseOptions): Store<Value<T, P>>;\n\n map(_selector: Selector<T, any> | Path<any>, options?: UseOptions): Store<any> {\n const selector = makeSelector(_selector);\n const derivedFrom = {\n store: this.derivedFrom ? this.derivedFrom.store : this,\n selectors: this.derivedFrom ? [...this.derivedFrom.selectors, _selector] : [_selector],\n };\n\n return new Store(\n ({ use }) => {\n return selector(use(this, options));\n },\n this.options,\n derivedFrom,\n );\n }\n\n /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.\n * @param effect\n * If there is already a subscriber, the effect will be executed immediately.\n * Otherweise it will be executed as soon as the first subscription is created.\n * Every time all subscriptions are removed and the first is created again, the effect will be executed again.\n * @param retain\n * If provided, delay tearing down effects when the last subscriber is removed. This is useful if a short gap in subscriber coverage is supposed to be ignored. E.g. when switching pages, the old page might unsubscribe, while the new page subscribes immediately after.\n * @returns\n * The effect can return a teardown callback, which will be executed when the last subscription is removed and potentially the ratain time has passed.\n */\n addEffect(effect: Effect, retain?: Duration) {\n this.effects.set(effect, {\n handle: this.isActive() ? effect() ?? noop : undefined,\n retain: retain !== undefined ? calcDuration(retain) : undefined,\n });\n\n return () => {\n const { handle, timeout } = this.effects.get(effect) ?? {};\n handle?.();\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.delete(effect);\n };\n }\n\n /** Return whether the store is currently active, which means whether it has at least one subscriber. */\n isActive() {\n return [...this.listeners.values()].some(Boolean);\n }\n\n protected onSubscribe() {\n if ([...this.listeners.values()].filter(Boolean).length > 1) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: handle ?? effect() ?? noop,\n retain,\n timeout: undefined,\n });\n }\n }\n\n protected onUnsubscribe() {\n if ([...this.listeners.values()].some(Boolean)) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (!retain) {\n handle?.();\n }\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: retain ? handle : undefined,\n retain,\n timeout: retain && handle ? setTimeout(handle, retain) : undefined,\n });\n }\n }\n\n protected notify() {\n const n = {};\n this.notifyId = n;\n\n const snapshot = [...this.listeners.keys()];\n for (const listener of snapshot) {\n listener();\n if (n !== this.notifyId) break;\n }\n }\n}\n\nconst defaultOptions: StoreOptions = {};\n\nfunction create<T>(\n calculate: (this: { use: Use }, fns: { use: Use }) => T,\n options?: StoreOptions,\n): Store<T>;\nfunction create<T, Methods extends StoreMethods = {}>(\n initialState: T,\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods>;\nfunction create<T, Methods extends StoreMethods>(\n initialState: T | ((this: { use: Use }, fns: { use: Use }) => T),\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods> | Store<T> {\n const store = new Store(initialState, options);\n\n if (initialState instanceof Function) {\n return store;\n }\n\n let methods: StoreMethods | undefined = options?.methods;\n\n if (initialState instanceof Map) {\n methods = { ...mapMethods, ...methods };\n } else if (initialState instanceof Set) {\n methods = { ...setMethods, ...methods };\n } else if (Array.isArray(initialState)) {\n methods = { ...arrayMethods, ...methods };\n } else if (initialState instanceof Object) {\n methods = { ...recordMethods, ...methods };\n }\n\n const boundMethods = Object.fromEntries(\n Object.entries(methods ?? ({} as BoundStoreMethods<T, any>))\n .filter(([name]) => !(name in store))\n .map(([name, action]) => [name, (action as any).bind(store)]),\n ) as BoundStoreMethods<T, any>;\n\n return Object.assign(store, boundMethods);\n}\n\nexport const createStore = Object.assign(create, { defaultOptions });\n"],"names":["Callable","CalculationHelper","get","set","equals","defaultEquals","forwardError","throttle","debounce","makeSelector","calcDuration","mapMethods","setMethods","arrayMethods","recordMethods"],"mappings":";;;;;;;;;;;;AAoDA,MAAM,OAAO,MAAM;AAEZ,MAAM,cAAiBA,SAAAA,SAAmB;AAAA,EAyB/C,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AO,QAAQ,EAAE,eAAgB,CAAA;;;"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const immer = require("immer");
|
|
4
|
-
const immerActions = {
|
|
5
|
-
immerUpdate(recipe) {
|
|
6
|
-
this.set(immer.produce(recipe));
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
exports.immerActions = immerActions;
|
|
10
|
-
//# sourceMappingURL=immerActions.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"immerActions.cjs","sources":["../../../src/immer/immerActions.ts"],"sourcesContent":["import type { Draft, nothing } from 'immer';\nimport { produce } from 'immer';\nimport type { Store } from '@core/store';\n\nexport const immerActions = {\n immerUpdate<T>(\n this: Store<T>,\n recipe: (\n draft: Draft<T>,\n ) => void | Draft<T> | (Draft<T> extends undefined ? typeof nothing : never) | undefined,\n ) {\n this.set(produce(recipe));\n },\n};\n"],"names":["produce"],"mappings":";;;AAIO,MAAM,eAAe;AAAA,EAC1B,YAEE,QAGA;AACK,SAAA,IAAIA,cAAQ,MAAM,CAAC;AAAA,EAC1B;AACF;;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const calcDuration = (t) => {
|
|
4
|
-
if (typeof t === "number")
|
|
5
|
-
return t;
|
|
6
|
-
return (t.milliseconds ?? 0) + (t.seconds ?? 0) * 1e3 + (t.minutes ?? 0) * 60 * 1e3 + (t.hours ?? 0) * 60 * 60 * 1e3 + (t.days ?? 0) * 24 * 60 * 60 * 1e3;
|
|
7
|
-
};
|
|
8
|
-
exports.calcDuration = calcDuration;
|
|
9
|
-
//# sourceMappingURL=calcDuration.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calcDuration.cjs","sources":["../../../src/lib/calcDuration.ts"],"sourcesContent":["import type { Duration } from '../core/commonTypes';\n\nexport const calcDuration = (t: Duration) => {\n if (typeof t === 'number') return t;\n return (\n (t.milliseconds ?? 0) +\n (t.seconds ?? 0) * 1000 +\n (t.minutes ?? 0) * 60 * 1000 +\n (t.hours ?? 0) * 60 * 60 * 1000 +\n (t.days ?? 0) * 24 * 60 * 60 * 1000\n );\n};\n"],"names":[],"mappings":";;AAEa,MAAA,eAAe,CAAC,MAAgB;AAC3C,MAAI,OAAO,MAAM;AAAiB,WAAA;AAE/B,UAAA,EAAE,gBAAgB,MAClB,EAAE,WAAW,KAAK,OAClB,EAAE,WAAW,KAAK,KAAK,OACvB,EAAE,SAAS,KAAK,KAAK,KAAK,OAC1B,EAAE,QAAQ,KAAK,KAAK,KAAK,KAAK;AAEnC;;"}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const queue = require("./queue.cjs");
|
|
4
|
-
const trackingProxy = require("./trackingProxy.cjs");
|
|
5
|
-
class CalculationHelper {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
this.options = options;
|
|
8
|
-
options.addEffect(() => {
|
|
9
|
-
if (this.current) {
|
|
10
|
-
this.current.check();
|
|
11
|
-
} else {
|
|
12
|
-
this.execute();
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
execute() {
|
|
17
|
-
this.stop();
|
|
18
|
-
const { calculate, addEffect, getValue, setValue, setError, onInvalidate } = this.options;
|
|
19
|
-
const checks = new Array();
|
|
20
|
-
const deps = /* @__PURE__ */ new Map();
|
|
21
|
-
const q = queue.queue();
|
|
22
|
-
let isActive = false;
|
|
23
|
-
let isCancled = false;
|
|
24
|
-
const cancelEffect = addEffect(() => {
|
|
25
|
-
isActive = true;
|
|
26
|
-
for (const dep of deps.values()) {
|
|
27
|
-
dep.on();
|
|
28
|
-
}
|
|
29
|
-
return () => {
|
|
30
|
-
isActive = false;
|
|
31
|
-
for (const dep of deps.values()) {
|
|
32
|
-
dep.off();
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
const cancel = () => {
|
|
37
|
-
isCancled = true;
|
|
38
|
-
cancelSubscription == null ? void 0 : cancelSubscription();
|
|
39
|
-
cancelEffect();
|
|
40
|
-
delete this.current;
|
|
41
|
-
};
|
|
42
|
-
const checkAll = () => {
|
|
43
|
-
if (!checks.every((check) => check())) {
|
|
44
|
-
cancel();
|
|
45
|
-
onInvalidate == null ? void 0 : onInvalidate();
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const invalidateDependencies = () => {
|
|
49
|
-
for (const dep of deps.values()) {
|
|
50
|
-
dep.invalidate();
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const use = (store, { disableProxy } = {}) => {
|
|
54
|
-
if (isCancled) {
|
|
55
|
-
return store.get();
|
|
56
|
-
}
|
|
57
|
-
let value = store.get();
|
|
58
|
-
let equals = (newValue) => {
|
|
59
|
-
return newValue === value;
|
|
60
|
-
};
|
|
61
|
-
if (!disableProxy) {
|
|
62
|
-
[value, equals] = trackingProxy.trackingProxy(value);
|
|
63
|
-
}
|
|
64
|
-
let sub;
|
|
65
|
-
const dep = {
|
|
66
|
-
on() {
|
|
67
|
-
this.off();
|
|
68
|
-
sub = store.sub(checkAll, { runNow: false });
|
|
69
|
-
},
|
|
70
|
-
off() {
|
|
71
|
-
sub == null ? void 0 : sub();
|
|
72
|
-
sub = void 0;
|
|
73
|
-
},
|
|
74
|
-
invalidate() {
|
|
75
|
-
if ("invalidate" in store && store.invalidate instanceof Function) {
|
|
76
|
-
store.invalidate();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
if (isActive) {
|
|
81
|
-
dep.on();
|
|
82
|
-
}
|
|
83
|
-
checks.push(() => equals(store.get()));
|
|
84
|
-
deps.set(store, dep);
|
|
85
|
-
return value;
|
|
86
|
-
};
|
|
87
|
-
const updateValue = (update) => q(async () => {
|
|
88
|
-
if (isCancled) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (update instanceof Function) {
|
|
92
|
-
try {
|
|
93
|
-
update = update(getValue == null ? void 0 : getValue());
|
|
94
|
-
} catch (error) {
|
|
95
|
-
setError == null ? void 0 : setError(error);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (update instanceof Promise) {
|
|
100
|
-
try {
|
|
101
|
-
update = await update;
|
|
102
|
-
} catch (error) {
|
|
103
|
-
if (!isCancled) {
|
|
104
|
-
setError == null ? void 0 : setError(error);
|
|
105
|
-
}
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (!isCancled) {
|
|
110
|
-
setValue == null ? void 0 : setValue(update);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
const updateError = (error) => q(() => {
|
|
114
|
-
if (!isCancled) {
|
|
115
|
-
setError == null ? void 0 : setError(error);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
let cancelSubscription;
|
|
119
|
-
try {
|
|
120
|
-
cancelSubscription = calculate({ use, updateValue, updateError });
|
|
121
|
-
} catch (error) {
|
|
122
|
-
setError == null ? void 0 : setError(error);
|
|
123
|
-
}
|
|
124
|
-
this.current = { cancel, check: checkAll, invalidateDependencies };
|
|
125
|
-
}
|
|
126
|
-
stop() {
|
|
127
|
-
var _a;
|
|
128
|
-
(_a = this.current) == null ? void 0 : _a.cancel();
|
|
129
|
-
}
|
|
130
|
-
check() {
|
|
131
|
-
var _a;
|
|
132
|
-
(_a = this.current) == null ? void 0 : _a.check();
|
|
133
|
-
}
|
|
134
|
-
invalidateDependencies() {
|
|
135
|
-
var _a;
|
|
136
|
-
(_a = this.current) == null ? void 0 : _a.invalidateDependencies();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.CalculationHelper = CalculationHelper;
|
|
140
|
-
//# sourceMappingURL=calculationHelper.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculationHelper.cjs","sources":["../../../src/lib/calculationHelper.ts"],"sourcesContent":["import type { MaybePromise } from './maybePromise';\nimport { queue } from './queue';\nimport { trackingProxy } from './trackingProxy';\nimport type { Store } from '@core/store';\nimport type { Cancel, UpdateFrom, Use } from '@core/commonTypes';\n\nexport class CalculationHelper<T> {\n private current?: {\n cancel: Cancel;\n check: () => void;\n invalidateDependencies: () => void;\n };\n\n constructor(\n private options: {\n calculate: (fns: {\n use: Use;\n updateValue: (update: UpdateFrom<MaybePromise<T>, [T | undefined]>) => void;\n updateError: (error: unknown) => void;\n }) => Cancel | void;\n addEffect: (effect: () => Cancel | void) => Cancel;\n getValue?: () => T | undefined;\n setValue?: (value: T) => void;\n setError?: (error: unknown) => void;\n onInvalidate?: () => void;\n },\n ) {\n options.addEffect(() => {\n if (this.current) {\n this.current.check();\n } else {\n this.execute();\n }\n });\n }\n\n execute() {\n this.stop();\n\n const { calculate, addEffect, getValue, setValue, setError, onInvalidate } = this.options;\n const checks = new Array<() => boolean>();\n const deps = new Map<Store<any>, { on: () => void; off: () => void; invalidate: () => void }>();\n const q = queue();\n let isActive = false;\n let isCancled = false;\n\n const cancelEffect = addEffect(() => {\n isActive = true;\n\n for (const dep of deps.values()) {\n dep.on();\n }\n\n return () => {\n isActive = false;\n\n for (const dep of deps.values()) {\n dep.off();\n }\n };\n });\n\n const cancel = () => {\n isCancled = true;\n cancelSubscription?.();\n cancelEffect();\n delete this.current;\n };\n\n const checkAll = () => {\n if (!checks.every((check) => check())) {\n cancel();\n onInvalidate?.();\n }\n };\n\n const invalidateDependencies = () => {\n for (const dep of deps.values()) {\n dep.invalidate();\n }\n };\n\n const use: Use = (store, { disableProxy } = {}) => {\n if (isCancled) {\n return store.get();\n }\n\n let value = store.get();\n let equals = (newValue: any) => {\n return newValue === value;\n };\n\n if (!disableProxy) {\n [value, equals] = trackingProxy(value);\n }\n\n let sub: Cancel | undefined;\n\n const dep = {\n on() {\n this.off();\n\n sub = store.sub(checkAll, { runNow: false });\n },\n off() {\n sub?.();\n sub = undefined;\n },\n invalidate() {\n if ('invalidate' in store && store.invalidate instanceof Function) {\n store.invalidate();\n }\n },\n };\n\n if (isActive) {\n dep.on();\n }\n\n checks.push(() => equals(store.get()));\n deps.set(store, dep);\n\n return value;\n };\n\n const updateValue = (update: UpdateFrom<MaybePromise<T>, [T | undefined]>) =>\n q(async () => {\n if (isCancled) {\n return;\n }\n\n if (update instanceof Function) {\n try {\n update = update(getValue?.());\n } catch (error) {\n setError?.(error);\n return;\n }\n }\n\n if (update instanceof Promise) {\n try {\n update = await update;\n } catch (error) {\n if (!isCancled) {\n setError?.(error);\n }\n return;\n }\n }\n\n if (!isCancled) {\n setValue?.(update);\n }\n });\n\n const updateError = (error: unknown) =>\n q(() => {\n if (!isCancled) {\n setError?.(error);\n }\n });\n\n let cancelSubscription: Cancel | void;\n try {\n cancelSubscription = calculate({ use, updateValue, updateError });\n } catch (error) {\n setError?.(error);\n }\n\n this.current = { cancel, check: checkAll, invalidateDependencies };\n }\n\n stop() {\n this.current?.cancel();\n }\n\n check() {\n this.current?.check();\n }\n\n invalidateDependencies() {\n this.current?.invalidateDependencies();\n }\n}\n"],"names":["queue","trackingProxy"],"mappings":";;;;AAMO,MAAM,kBAAqB;AAAA,EAOhC,YACU,SAYR;AAZQ,SAAA,UAAA;AAaR,YAAQ,UAAU,MAAM;AACtB,UAAI,KAAK,SAAS;AAChB,aAAK,QAAQ;MAAM,OACd;AACL,aAAK,QAAQ;AAAA,MACf;AAAA,IAAA,CACD;AAAA,EACH;AAAA,EAEA,UAAU;AACR,SAAK,KAAK;AAEJ,UAAA,EAAE,WAAW,WAAW,UAAU,UAAU,UAAU,aAAA,IAAiB,KAAK;AAC5E,UAAA,SAAS,IAAI;AACb,UAAA,2BAAW;AACjB,UAAM,IAAIA,MAAAA;AACV,QAAI,WAAW;AACf,Q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AAA;AAAA,IAAA;AAGT,UAAM,cAAc,CAAC,WACnB,EAAE,YAAY;AACZ,UAAI,WAAW;AACb;AAAA,MACF;AAEA,UAAI,kBAAkB,UAAU;AAC1B,YAAA;AACO,mBAAA,OAAO,sCAAY;AAAA,iBACrB;AACP,+CAAW;AACX;AAAA,QACF;AAAA,MACF;AAEA,UAAI,kBAAkB,SAAS;AACzB,YAAA;AACF,mBAAS,MAAM;AAAA,iBACR;AACP,cAAI,CAAC,WAAW;AACd,iDAAW;AAAA,UACb;AACA;AAAA,QACF;AAAA,MACF;AAEA,UAAI,CAAC,WAAW;AACd,6CAAW;AAAA,MACb;AAAA,IAAA,CACD;AAEH,UAAM,cAAc,CAAC,UACnB,EAAE,MAAM;AACN,UAAI,CAAC,WAAW;AACd,6CAAW;AAAA,MACb;AAAA,IAAA,CACD;AAEC,QAAA;AACA,QAAA;AACF,2BAAqB,UAAU,EAAE,KAAK,aAAa,YAAa,CAAA;AAAA,aACzD;AACP,2CAAW;AAAA,IACb;AAEA,SAAK,UAAU,EAAE,QAAQ,OAAO,UAAU;EAC5C;AAAA,EAEA,OAAO;;AACL,eAAK,YAAL,mBAAc;AAAA,EAChB;AAAA,EAEA,QAAQ;;AACN,eAAK,YAAL,mBAAc;AAAA,EAChB;AAAA,EAEA,yBAAyB;;AACvB,eAAK,YAAL,mBAAc;AAAA,EAChB;AACF;;"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
class Callable extends Function {
|
|
4
|
-
constructor(_call) {
|
|
5
|
-
super("...args", "return this._call(...args)");
|
|
6
|
-
this._call = _call;
|
|
7
|
-
return this.bind(this);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.Callable = Callable;
|
|
11
|
-
//# sourceMappingURL=callable.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"callable.cjs","sources":["../../../src/lib/callable.ts"],"sourcesContent":["export class Callable<Args extends any[], T> extends Function {\n constructor(protected _call: (...args: Args) => T) {\n super('...args', 'return this._call(...args)');\n\n // eslint-disable-next-line no-constructor-return\n return this.bind(this);\n }\n}\n"],"names":[],"mappings":";;AAAO,MAAM,iBAAwC,SAAS;AAAA,EAC5D,YAAsB,OAA6B;AACjD,UAAM,WAAW,4BAA4B;AADzB,SAAA,QAAA;AAIb,WAAA,KAAK,KAAK,IAAI;AAAA,EACvB;AACF;;"}
|
package/dist/cjs/lib/clone.cjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
function flatClone(object) {
|
|
4
|
-
if (object instanceof Map) {
|
|
5
|
-
return new Map(object);
|
|
6
|
-
}
|
|
7
|
-
if (object instanceof Set) {
|
|
8
|
-
return new Set(object);
|
|
9
|
-
}
|
|
10
|
-
if (Array.isArray(object)) {
|
|
11
|
-
return [...object];
|
|
12
|
-
}
|
|
13
|
-
if (object instanceof Object) {
|
|
14
|
-
return { ...object };
|
|
15
|
-
}
|
|
16
|
-
return object;
|
|
17
|
-
}
|
|
18
|
-
exports.flatClone = flatClone;
|
|
19
|
-
//# sourceMappingURL=clone.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clone.cjs","sources":["../../../src/lib/clone.ts"],"sourcesContent":["export function flatClone<T>(object: T): T {\n if (object instanceof Map) {\n return new Map(object) as any;\n }\n\n if (object instanceof Set) {\n return new Set(object) as any;\n }\n\n if (Array.isArray(object)) {\n return [...object] as any;\n }\n\n if (object instanceof Object) {\n return { ...object };\n }\n\n return object;\n}\n"],"names":[],"mappings":";;AAAO,SAAS,UAAa,QAAc;AACzC,MAAI,kBAAkB,KAAK;AAClB,WAAA,IAAI,IAAI,MAAM;AAAA,EACvB;AAEA,MAAI,kBAAkB,KAAK;AAClB,WAAA,IAAI,IAAI,MAAM;AAAA,EACvB;AAEI,MAAA,MAAM,QAAQ,MAAM,GAAG;AAClB,WAAA,CAAC,GAAG,MAAM;AAAA,EACnB;AAEA,MAAI,kBAAkB,QAAQ;AACrB,WAAA,EAAE,GAAG;EACd;AAEO,SAAA;AACT;;"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const calcDuration = require("./calcDuration.cjs");
|
|
4
|
-
function debounce(action, options) {
|
|
5
|
-
const wait = typeof options === "object" && "wait" in options ? calcDuration.calcDuration(options.wait) : calcDuration.calcDuration(options);
|
|
6
|
-
const maxWait = typeof options === "object" && "maxWait" in options && options.maxWait !== void 0 ? calcDuration.calcDuration(options.maxWait) : void 0;
|
|
7
|
-
let timeout;
|
|
8
|
-
let timeoutStarted;
|
|
9
|
-
return (...args) => {
|
|
10
|
-
const now = Date.now();
|
|
11
|
-
timeoutStarted ?? (timeoutStarted = now);
|
|
12
|
-
const deadline = Math.min(
|
|
13
|
-
//
|
|
14
|
-
now + wait,
|
|
15
|
-
timeoutStarted + (maxWait ?? Number.POSITIVE_INFINITY)
|
|
16
|
-
);
|
|
17
|
-
if (timeout !== void 0) {
|
|
18
|
-
clearTimeout(timeout);
|
|
19
|
-
}
|
|
20
|
-
timeout = setTimeout(() => {
|
|
21
|
-
timeout = void 0;
|
|
22
|
-
timeoutStarted = void 0;
|
|
23
|
-
action(...args);
|
|
24
|
-
}, deadline - now);
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
exports.debounce = debounce;
|
|
28
|
-
//# sourceMappingURL=debounce.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.cjs","sources":["../../../src/lib/debounce.ts"],"sourcesContent":["import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport type DebounceOptions =\n | Duration\n | {\n wait: Duration;\n maxWait?: Duration;\n };\n\nexport function debounce<Args extends any[]>(\n action: (...args: Args) => void,\n options: Duration | DebounceOptions,\n): (...args: Args) => void {\n const wait =\n typeof options === 'object' && 'wait' in options\n ? calcDuration(options.wait)\n : calcDuration(options);\n\n const maxWait =\n typeof options === 'object' && 'maxWait' in options && options.maxWait !== undefined\n ? calcDuration(options.maxWait)\n : undefined;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n let timeoutStarted: number | undefined;\n\n return (...args: Args) => {\n const now = Date.now();\n timeoutStarted ??= now;\n\n const deadline = Math.min(\n //\n now + wait,\n timeoutStarted + (maxWait ?? Number.POSITIVE_INFINITY),\n );\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n timeout = setTimeout(() => {\n timeout = undefined;\n timeoutStarted = undefined;\n action(...args);\n }, deadline - now);\n };\n}\n"],"names":["calcDuration"],"mappings":";;;AAUgB,SAAA,SACd,QACA,SACyB;AACnB,QAAA,OACJ,OAAO,YAAY,YAAY,UAAU,UACrCA,aAAA,aAAa,QAAQ,IAAI,IACzBA,aAAA,aAAa,OAAO;AAE1B,QAAM,UACJ,OAAO,YAAY,YAAY,aAAa,WAAW,QAAQ,YAAY,SACvEA,aAAAA,aAAa,QAAQ,OAAO,IAC5B;AAEF,MAAA;AACA,MAAA;AAEJ,SAAO,IAAI,SAAe;AAClB,UAAA,MAAM,KAAK;AACE,wCAAA;AAEnB,UAAM,WAAW,KAAK;AAAA;AAAA,MAEpB,MAAM;AAAA,MACN,kBAAkB,WAAW,OAAO;AAAA,IAAA;AAGtC,QAAI,YAAY,QAAW;AACzB,mBAAa,OAAO;AAAA,IACtB;AAEA,cAAU,WAAW,MAAM;AACf,gBAAA;AACO,uBAAA;AACjB,aAAO,GAAG,IAAI;AAAA,IAAA,GACb,WAAW,GAAG;AAAA,EAAA;AAErB;;"}
|
package/dist/cjs/lib/equals.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"equals.cjs","sources":["../../../src/lib/equals.ts"],"sourcesContent":["export const defaultEquals = (a: any, b: any) => a === b;\n\nexport const simpleShallowEquals = (a: any, b: any): boolean => {\n if (a === b) {\n return true;\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((value, i) => value === b[i]);\n }\n\n if (typeof a === 'object' && typeof b === 'object') {\n if (a === null || b === null) {\n return false;\n }\n\n const entries1 = Object.entries(a);\n const entries2 = Object.entries(b);\n return (\n entries1.length === entries2.length && entries1.every(([key, value]) => value === b[key])\n );\n }\n\n return false;\n};\n\nexport const simpleDeepEquals = (a: any, b: any): boolean => {\n if (a === b) {\n return true;\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((value, i) => simpleDeepEquals(value, b[i]));\n }\n\n if (typeof a === 'object' && typeof b === 'object') {\n if (a === null || b === null) {\n return false;\n }\n\n const entries1 = Object.entries(a);\n const entries2 = Object.entries(b);\n return (\n entries1.length === entries2.length &&\n entries1.every(([key, value]) => simpleDeepEquals(value, b[key]))\n );\n }\n\n return false;\n};\n"],"names":[],"mappings":";;AAAO,MAAM,gBAAgB,CAAC,GAAQ,MAAW,MAAM;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forwardError.cjs","sources":["../../../src/lib/forwardError.ts"],"sourcesContent":["export function forwardError(error: unknown) {\n setTimeout(() => {\n throw error;\n });\n}\n"],"names":[],"mappings":";;AAAO,SAAS,aAAa,OAAgB;AAC3C,aAAW,MAAM;AACT,UAAA;AAAA,EAAA,CACP;AACH;;"}
|
package/dist/cjs/lib/hash.cjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
function hash(value) {
|
|
4
|
-
if (value instanceof Set) {
|
|
5
|
-
return `s[${[...value].map(hash).sort().join(",")}]`;
|
|
6
|
-
}
|
|
7
|
-
if (value instanceof Map) {
|
|
8
|
-
return `m[${[...value.entries()].map(hash).sort().join(",")}]`;
|
|
9
|
-
}
|
|
10
|
-
if (Array.isArray(value)) {
|
|
11
|
-
return `[${value.map(hash).join(",")}]`;
|
|
12
|
-
}
|
|
13
|
-
if (value instanceof Object) {
|
|
14
|
-
return `o[${Object.entries(value).map(hash).sort().join(",")}]`;
|
|
15
|
-
}
|
|
16
|
-
return JSON.stringify(value);
|
|
17
|
-
}
|
|
18
|
-
exports.hash = hash;
|
|
19
|
-
//# sourceMappingURL=hash.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hash.cjs","sources":["../../../src/lib/hash.ts"],"sourcesContent":["export function hash(value: unknown): string {\n if (value instanceof Set) {\n return `s[${[...value].map(hash).sort().join(',')}]`;\n }\n\n if (value instanceof Map) {\n return `m[${[...value.entries()].map(hash).sort().join(',')}]`;\n }\n\n if (Array.isArray(value)) {\n return `[${value.map(hash).join(',')}]`;\n }\n\n if (value instanceof Object) {\n return `o[${Object.entries(value).map(hash).sort().join(',')}]`;\n }\n\n return JSON.stringify(value);\n}\n"],"names":[],"mappings":";;AAAO,SAAS,KAAK,OAAwB;AAC3C,MAAI,iBAAiB,KAAK;AACjB,WAAA,KAAK,CAAC,GAAG,KAAK,EAAE,IAAI,IAAI,EAAE,KAAO,EAAA,KAAK,GAAG;AAAA,EAClD;AAEA,MAAI,iBAAiB,KAAK;AACxB,WAAO,KAAK,CAAC,GAAG,MAAM,QAAS,CAAA,EAAE,IAAI,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG;AAAA,EAC5D;AAEI,MAAA,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,IAAI,MAAM,IAAI,IAAI,EAAE,KAAK,GAAG;AAAA,EACrC;AAEA,MAAI,iBAAiB,QAAQ;AACpB,WAAA,KAAK,OAAO,QAAQ,KAAK,EAAE,IAAI,IAAI,EAAE,KAAA,EAAO,KAAK,GAAG;AAAA,EAC7D;AAEO,SAAA,KAAK,UAAU,KAAK;AAC7B;;"}
|