valdres 0.2.0-alpha.1 → 0.2.0-alpha.3
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/index.d.ts +4 -0
- package/dist/index.js +118 -118
- package/dist/src/atom.d.ts +3 -3
- package/dist/src/atomFamily.d.ts +3 -1
- package/dist/src/lib/createStoreData.d.ts +2 -0
- package/dist/src/lib/initSelector.d.ts +1 -1
- package/dist/src/lib/storeFromStoreData.d.ts +3 -0
- package/dist/src/lib/subscribe.d.ts +2 -1
- package/dist/src/lib/unsubscribe.d.ts +1 -1
- package/dist/src/lib/updateSelectorSubscribers.d.ts +1 -1
- package/dist/src/selector.d.ts +2 -4
- package/dist/src/selectorFamily.d.ts +2 -4
- package/dist/src/types/Atom.d.ts +4 -1
- package/dist/src/types/AtomFamily.d.ts +1 -1
- package/dist/src/types/Family.d.ts +1 -1
- package/dist/src/types/GetValue.d.ts +1 -1
- package/dist/src/types/ResetAtom.d.ts +1 -1
- package/dist/src/types/Selector.d.ts +6 -2
- package/dist/src/types/SelectorFamily.d.ts +5 -1
- package/dist/src/types/SetAtom.d.ts +1 -1
- package/dist/src/types/StoreData.d.ts +3 -1
- package/dist/src/types/SubscribeFn.d.ts +1 -1
- package/dist/src/utils/isAtom.d.ts +2 -2
- package/dist/src/utils/isPromiseLike.d.ts +1 -1
- package/dist/src/utils/isSelector.d.ts +1 -2
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ export { isSelector } from "./src/utils/isSelector";
|
|
|
9
9
|
export { isFamily } from "./src/utils/isFamily";
|
|
10
10
|
export { isPromiseLike } from "./src/utils/isPromiseLike";
|
|
11
11
|
export type { Atom } from "./src/types/Atom";
|
|
12
|
+
export type { AtomFamily } from "./src/types/AtomFamily";
|
|
13
|
+
export type { GetValue } from "./src/types/GetValue";
|
|
12
14
|
export type { Selector } from "./src/types/Selector";
|
|
15
|
+
export type { SelectorFamily } from "./src/types/SelectorFamily";
|
|
13
16
|
export type { State } from "./src/types/State";
|
|
14
17
|
export type { Store } from "./src/types/Store";
|
|
18
|
+
export type { StoreData } from "./src/types/StoreData";
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,9 @@ var atom = (defaultValue, options) => {
|
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
// src/utils/isPromiseLike.ts
|
|
11
|
-
var isPromiseLike = (object) =>
|
|
11
|
+
var isPromiseLike = (object) => {
|
|
12
|
+
return object && object.then && typeof object.then === "function";
|
|
13
|
+
};
|
|
12
14
|
|
|
13
15
|
// src/lib/stableStringify.ts
|
|
14
16
|
var stableStringifyRecurse = (x, key) => {
|
|
@@ -65,24 +67,15 @@ var stableStringify = (x) => {
|
|
|
65
67
|
};
|
|
66
68
|
|
|
67
69
|
// src/atomFamily.ts
|
|
68
|
-
var handleDefaultValue = (defaultValue, override, key) => {
|
|
69
|
-
if (override) {
|
|
70
|
-
return typeof override === "function" ? () => typeof defaultValue === "function" ? override(defaultValue(key)) : override(defaultValue) : override;
|
|
71
|
-
} else {
|
|
72
|
-
return typeof defaultValue === "function" ? () => defaultValue(key) : defaultValue;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
70
|
var atomFamily = (defaultValue, debugLabel) => {
|
|
76
71
|
const map = new Map;
|
|
77
72
|
const atomFamily2 = (key, defaultOverride) => {
|
|
78
73
|
const keyStringified = stableStringify(key);
|
|
79
74
|
if (map.has(keyStringified)) {
|
|
80
|
-
if (defaultOverride)
|
|
81
|
-
throw new Error("defaultOverride is only allowed first time an atom is initiaizlied");
|
|
82
75
|
return map.get(keyStringified);
|
|
83
76
|
}
|
|
84
77
|
const atomDebugLabel = debugLabel && debugLabel + "_" + keyStringified;
|
|
85
|
-
const newAtom = atom(
|
|
78
|
+
const newAtom = atom(typeof defaultValue === "function" ? () => defaultValue(key) : defaultValue, {
|
|
86
79
|
label: atomDebugLabel
|
|
87
80
|
});
|
|
88
81
|
newAtom.family = atomFamily2;
|
|
@@ -93,19 +86,37 @@ var atomFamily = (defaultValue, debugLabel) => {
|
|
|
93
86
|
atomFamily2._map = map;
|
|
94
87
|
return atomFamily2;
|
|
95
88
|
};
|
|
89
|
+
// src/lib/createStoreData.ts
|
|
90
|
+
var generateId = () => (Math.random() + 1).toString(36).substring(7);
|
|
91
|
+
var createStoreData = (id = generateId()) => ({
|
|
92
|
+
id,
|
|
93
|
+
values: new WeakMap,
|
|
94
|
+
expiredValues: new WeakMap,
|
|
95
|
+
subscriptions: new WeakMap,
|
|
96
|
+
subscriptionsRequireEqualCheck: new WeakMap,
|
|
97
|
+
stateConsumers: new WeakMap,
|
|
98
|
+
stateDependencies: new WeakMap
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// src/utils/isAtom.ts
|
|
102
|
+
var isAtom = (state) => Object.hasOwn(state, "defaultValue");
|
|
103
|
+
|
|
104
|
+
// src/utils/isSelector.ts
|
|
105
|
+
var isSelector = (state) => Object.hasOwn(state, "get");
|
|
106
|
+
|
|
96
107
|
// src/lib/updateStateSubscribers.ts
|
|
97
|
-
var updateStateSubscribers = (
|
|
98
|
-
const subscribtions = data.subscriptions.get(
|
|
108
|
+
var updateStateSubscribers = (state, data) => {
|
|
109
|
+
const subscribtions = data.subscriptions.get(state);
|
|
99
110
|
if (subscribtions?.size) {
|
|
100
111
|
for (const subscribtion of subscribtions) {
|
|
101
112
|
subscribtion.callback();
|
|
102
113
|
}
|
|
103
114
|
}
|
|
104
|
-
if (
|
|
105
|
-
const familySubscriptions = data.subscriptions.get(
|
|
115
|
+
if (state.family) {
|
|
116
|
+
const familySubscriptions = data.subscriptions.get(state.family);
|
|
106
117
|
if (familySubscriptions?.size) {
|
|
107
118
|
for (const subscribtion of familySubscriptions) {
|
|
108
|
-
subscribtion.callback(
|
|
119
|
+
subscribtion.callback(state.familyKey);
|
|
109
120
|
}
|
|
110
121
|
}
|
|
111
122
|
}
|
|
@@ -123,12 +134,12 @@ class SuspendAndWaitForResolveError extends Error {
|
|
|
123
134
|
this.promise = promise;
|
|
124
135
|
}
|
|
125
136
|
}
|
|
126
|
-
var getOrInitConsumersSet = (
|
|
127
|
-
const set = data.stateConsumers.get(
|
|
137
|
+
var getOrInitConsumersSet = (state, data) => {
|
|
138
|
+
const set = data.stateConsumers.get(state);
|
|
128
139
|
if (set)
|
|
129
140
|
return set;
|
|
130
141
|
const newSet = new Set;
|
|
131
|
-
data.stateConsumers.set(
|
|
142
|
+
data.stateConsumers.set(state, newSet);
|
|
132
143
|
return newSet;
|
|
133
144
|
};
|
|
134
145
|
var evaluateSelector = (selector, data) => {
|
|
@@ -136,9 +147,9 @@ var evaluateSelector = (selector, data) => {
|
|
|
136
147
|
const updatedDependencies = new Set;
|
|
137
148
|
let result;
|
|
138
149
|
try {
|
|
139
|
-
result = selector.get((
|
|
140
|
-
const value = getState2(
|
|
141
|
-
updatedDependencies.add(
|
|
150
|
+
result = selector.get((state) => {
|
|
151
|
+
const value = getState2(state, data);
|
|
152
|
+
updatedDependencies.add(state);
|
|
142
153
|
if (isPromiseLike(value))
|
|
143
154
|
throw new SuspendAndWaitForResolveError(value);
|
|
144
155
|
return value;
|
|
@@ -152,12 +163,12 @@ var evaluateSelector = (selector, data) => {
|
|
|
152
163
|
}
|
|
153
164
|
const added = updatedDependencies?.difference(currentDependencies);
|
|
154
165
|
const removed = currentDependencies?.difference(updatedDependencies);
|
|
155
|
-
for (const
|
|
156
|
-
const set = getOrInitConsumersSet(
|
|
166
|
+
for (const state of added) {
|
|
167
|
+
const set = getOrInitConsumersSet(state, data);
|
|
157
168
|
set.add(selector);
|
|
158
169
|
}
|
|
159
|
-
for (const
|
|
160
|
-
const set = getOrInitConsumersSet(
|
|
170
|
+
for (const state of removed) {
|
|
171
|
+
const set = getOrInitConsumersSet(state, data);
|
|
161
172
|
set.delete(selector);
|
|
162
173
|
}
|
|
163
174
|
data.stateDependencies.set(selector, updatedDependencies);
|
|
@@ -214,7 +225,7 @@ var updateSelectorSubscribers = (selector, data) => {
|
|
|
214
225
|
}
|
|
215
226
|
if (familySubscriptions?.size) {
|
|
216
227
|
for (const subscribtion of familySubscriptions) {
|
|
217
|
-
subscribtion.callback(
|
|
228
|
+
subscribtion.callback(selector.familyKey);
|
|
218
229
|
}
|
|
219
230
|
}
|
|
220
231
|
};
|
|
@@ -306,26 +317,20 @@ var initAtom = (atom3, data) => {
|
|
|
306
317
|
return value;
|
|
307
318
|
};
|
|
308
319
|
|
|
309
|
-
// src/utils/isAtom.ts
|
|
310
|
-
var isAtom = (state2) => Object.hasOwn(state2, "defaultValue");
|
|
311
|
-
|
|
312
|
-
// src/utils/isSelector.ts
|
|
313
|
-
var isSelector = (state2) => Object.hasOwn(state2, "get");
|
|
314
|
-
|
|
315
320
|
// src/utils/isFamily.ts
|
|
316
|
-
var isFamily = (
|
|
321
|
+
var isFamily = (state) => Object.hasOwn(state, "_map");
|
|
317
322
|
|
|
318
323
|
// src/lib/getState.ts
|
|
319
|
-
var getState2 = (
|
|
320
|
-
if (data.values.has(
|
|
321
|
-
return data.values.get(
|
|
322
|
-
if (isAtom(
|
|
323
|
-
return initAtom(
|
|
324
|
-
if (isSelector(
|
|
325
|
-
return initSelector(
|
|
326
|
-
if (isFamily(
|
|
324
|
+
var getState2 = (state, data) => {
|
|
325
|
+
if (data.values.has(state))
|
|
326
|
+
return data.values.get(state);
|
|
327
|
+
if (isAtom(state))
|
|
328
|
+
return initAtom(state, data);
|
|
329
|
+
if (isSelector(state))
|
|
330
|
+
return initSelector(state, data);
|
|
331
|
+
if (isFamily(state)) {
|
|
327
332
|
const res = [];
|
|
328
|
-
for (const atom3 of
|
|
333
|
+
for (const atom3 of state._map.values()) {
|
|
329
334
|
res.push([atom3.familyKey, getState2(atom3, data)]);
|
|
330
335
|
}
|
|
331
336
|
return res;
|
|
@@ -333,12 +338,21 @@ var getState2 = (state2, data) => {
|
|
|
333
338
|
throw new Error("Invalid object passed to get");
|
|
334
339
|
};
|
|
335
340
|
|
|
341
|
+
// src/lib/resetAtom.ts
|
|
342
|
+
var resetAtom = (atom3, data) => {
|
|
343
|
+
const res = initAtom(atom3, data);
|
|
344
|
+
if (!isPromiseLike(res)) {
|
|
345
|
+
propagateUpdatedAtoms([atom3], data);
|
|
346
|
+
}
|
|
347
|
+
return res;
|
|
348
|
+
};
|
|
349
|
+
|
|
336
350
|
// src/lib/unsubscribe.ts
|
|
337
|
-
var unsubscribe = (
|
|
338
|
-
const subscribers = data.subscriptions.get(
|
|
351
|
+
var unsubscribe = (state, subscription, data, mount) => {
|
|
352
|
+
const subscribers = data.subscriptions.get(state);
|
|
339
353
|
if (subscribers) {
|
|
340
354
|
subscribers.delete(subscription);
|
|
341
|
-
if (data.subscriptionsRequireEqualCheck.get(
|
|
355
|
+
if (data.subscriptionsRequireEqualCheck.get(state)) {
|
|
342
356
|
let remove = true;
|
|
343
357
|
for (const subscriber of subscribers) {
|
|
344
358
|
if (subscriber.requireDeepEqualCheckBeforeCallback) {
|
|
@@ -347,33 +361,35 @@ var unsubscribe = (state2, subscription, data, mountRes) => {
|
|
|
347
361
|
}
|
|
348
362
|
}
|
|
349
363
|
if (remove) {
|
|
350
|
-
data.subscriptionsRequireEqualCheck.delete(
|
|
364
|
+
data.subscriptionsRequireEqualCheck.delete(state);
|
|
351
365
|
}
|
|
352
366
|
}
|
|
353
|
-
if (
|
|
354
|
-
if (
|
|
355
|
-
|
|
367
|
+
if (mount) {
|
|
368
|
+
if (subscribers.size === mount.mountSubscriptions.size) {
|
|
369
|
+
if (state.onUnmount) {
|
|
370
|
+
state.onUnmount(mount.onMountRes);
|
|
371
|
+
}
|
|
356
372
|
}
|
|
357
373
|
}
|
|
358
374
|
}
|
|
359
375
|
};
|
|
360
376
|
|
|
361
377
|
// src/lib/subscribe.ts
|
|
362
|
-
var initSubscribers = (
|
|
378
|
+
var initSubscribers = (state, data) => {
|
|
363
379
|
const set = new Set;
|
|
364
|
-
data.subscriptions.set(
|
|
380
|
+
data.subscriptions.set(state, set);
|
|
365
381
|
return set;
|
|
366
382
|
};
|
|
367
|
-
var subscribe = (
|
|
368
|
-
const subscribers = data.subscriptions.get(
|
|
369
|
-
if (isSelector(
|
|
370
|
-
initSelector(
|
|
383
|
+
var subscribe = (state, callback, requireDeepEqualCheckBeforeCallback, data) => {
|
|
384
|
+
const subscribers = data.subscriptions.get(state) || initSubscribers(state, data);
|
|
385
|
+
if (isSelector(state) && !data.values.has(state)) {
|
|
386
|
+
initSelector(state, data);
|
|
371
387
|
}
|
|
372
388
|
let subscription;
|
|
373
|
-
if (isFamily(
|
|
389
|
+
if (isFamily(state)) {
|
|
374
390
|
subscription = {
|
|
375
391
|
callback,
|
|
376
|
-
state
|
|
392
|
+
state,
|
|
377
393
|
requireDeepEqualCheckBeforeCallback
|
|
378
394
|
};
|
|
379
395
|
} else {
|
|
@@ -382,17 +398,25 @@ var subscribe = (state2, callback, requireDeepEqualCheckBeforeCallback, data) =>
|
|
|
382
398
|
requireDeepEqualCheckBeforeCallback
|
|
383
399
|
};
|
|
384
400
|
}
|
|
385
|
-
let mountRes;
|
|
386
|
-
if (subscribers.size === 0 && state2.onMount) {
|
|
387
|
-
mountRes = state2.onMount((value) => {
|
|
388
|
-
setAtom(state2, value, data);
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
401
|
subscribers.add(subscription);
|
|
392
|
-
|
|
393
|
-
|
|
402
|
+
let mount;
|
|
403
|
+
if (subscribers.size === 1 && state.onMount) {
|
|
404
|
+
const store = storeFromStoreData2(data);
|
|
405
|
+
const mountSubscriptions = new Set;
|
|
406
|
+
const originalSub = store.sub;
|
|
407
|
+
store.sub = (state2, callback2) => {
|
|
408
|
+
mountSubscriptions.add(callback2);
|
|
409
|
+
return originalSub(state2, callback2);
|
|
410
|
+
};
|
|
411
|
+
mount = {
|
|
412
|
+
onMountRes: state.onMount(store, state),
|
|
413
|
+
mountSubscriptions
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
if (requireDeepEqualCheckBeforeCallback && data.subscriptionsRequireEqualCheck.get(state) !== true) {
|
|
417
|
+
data.subscriptionsRequireEqualCheck.set(state, true);
|
|
394
418
|
}
|
|
395
|
-
return () => unsubscribe(
|
|
419
|
+
return () => unsubscribe(state, subscription, data, mount);
|
|
396
420
|
};
|
|
397
421
|
|
|
398
422
|
// src/lib/setAtoms.ts
|
|
@@ -410,8 +434,8 @@ var setAtoms = (pairs, data) => {
|
|
|
410
434
|
};
|
|
411
435
|
|
|
412
436
|
// src/lib/transaction.ts
|
|
413
|
-
var findDependencies = (
|
|
414
|
-
const consumers = data.stateConsumers.get(
|
|
437
|
+
var findDependencies = (state, data, result = new Set) => {
|
|
438
|
+
const consumers = data.stateConsumers.get(state);
|
|
415
439
|
if (consumers?.size) {
|
|
416
440
|
for (const consumer of consumers) {
|
|
417
441
|
if (!result.has(consumer)) {
|
|
@@ -426,18 +450,18 @@ var transaction = (callback, data) => {
|
|
|
426
450
|
let txnAtomMap = new Map;
|
|
427
451
|
let txnSelectorCache = new Map;
|
|
428
452
|
let dirtySelectors = new Set;
|
|
429
|
-
const txnGet = (
|
|
430
|
-
if (isAtom(
|
|
431
|
-
return txnAtomMap.has(
|
|
453
|
+
const txnGet = (state) => {
|
|
454
|
+
if (isAtom(state)) {
|
|
455
|
+
return txnAtomMap.has(state) ? txnAtomMap.get(state) : getState2(state, data);
|
|
432
456
|
} else {
|
|
433
|
-
if (txnSelectorCache.has(
|
|
434
|
-
return txnSelectorCache.get(
|
|
435
|
-
} else if (dirtySelectors.has(
|
|
436
|
-
const res =
|
|
437
|
-
txnSelectorCache.set(
|
|
457
|
+
if (txnSelectorCache.has(state)) {
|
|
458
|
+
return txnSelectorCache.get(state);
|
|
459
|
+
} else if (dirtySelectors.has(state)) {
|
|
460
|
+
const res = state.get(txnGet);
|
|
461
|
+
txnSelectorCache.set(state, res);
|
|
438
462
|
return res;
|
|
439
463
|
} else {
|
|
440
|
-
return getState2(
|
|
464
|
+
return getState2(state, data);
|
|
441
465
|
}
|
|
442
466
|
}
|
|
443
467
|
};
|
|
@@ -468,45 +492,16 @@ var transaction = (callback, data) => {
|
|
|
468
492
|
return result;
|
|
469
493
|
};
|
|
470
494
|
|
|
471
|
-
// src/lib/
|
|
472
|
-
var
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
return res;
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
// src/createStore.ts
|
|
481
|
-
var generateId = () => (Math.random() + 1).toString(36).substring(7);
|
|
482
|
-
var createStore = (id) => {
|
|
483
|
-
const data = {
|
|
484
|
-
id: id ?? generateId(),
|
|
485
|
-
values: new WeakMap,
|
|
486
|
-
expiredValues: new WeakMap,
|
|
487
|
-
subscriptions: new WeakMap,
|
|
488
|
-
subscriptionsRequireEqualCheck: new WeakMap,
|
|
489
|
-
stateConsumers: new WeakMap,
|
|
490
|
-
stateDependencies: new WeakMap
|
|
491
|
-
};
|
|
492
|
-
const get = (state2) => getState2(state2, data);
|
|
493
|
-
const getWithDefault = (atom3, defaultValue) => {
|
|
494
|
-
if (!isAtom(atom3))
|
|
495
|
-
throw new Error("Only atom allowed");
|
|
496
|
-
if (data.values.has(atom3)) {
|
|
497
|
-
return data.values.get(atom3);
|
|
498
|
-
} else {
|
|
499
|
-
data.values.set(atom3, defaultValue);
|
|
500
|
-
return defaultValue;
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
const set = (state2, value) => {
|
|
504
|
-
if (isAtom(state2)) {
|
|
505
|
-
return setAtom(state2, value, data);
|
|
495
|
+
// src/lib/storeFromStoreData.ts
|
|
496
|
+
var storeFromStoreData2 = (data) => {
|
|
497
|
+
const get = (state) => getState2(state, data);
|
|
498
|
+
const set = (state, value) => {
|
|
499
|
+
if (isAtom(state)) {
|
|
500
|
+
return setAtom(state, value, data);
|
|
506
501
|
} else {
|
|
507
|
-
if (isSelector(
|
|
508
|
-
if (
|
|
509
|
-
txn((set2, get2) =>
|
|
502
|
+
if (isSelector(state)) {
|
|
503
|
+
if (state.set) {
|
|
504
|
+
txn((set2, get2) => state.set({ get: get2, set: set2 }, value));
|
|
510
505
|
return;
|
|
511
506
|
} else {
|
|
512
507
|
throw new Error("set on selector is not supported");
|
|
@@ -516,11 +511,10 @@ var createStore = (id) => {
|
|
|
516
511
|
}
|
|
517
512
|
};
|
|
518
513
|
const reset = (atom3) => resetAtom(atom3, data);
|
|
519
|
-
const sub = (
|
|
514
|
+
const sub = (state, callback, deepEqualCheckBeforeCallback = true) => subscribe(state, callback, deepEqualCheckBeforeCallback, data);
|
|
520
515
|
const txn = (callback) => transaction(callback, data);
|
|
521
516
|
return {
|
|
522
517
|
get,
|
|
523
|
-
getWithDefault,
|
|
524
518
|
set,
|
|
525
519
|
sub,
|
|
526
520
|
txn,
|
|
@@ -528,6 +522,12 @@ var createStore = (id) => {
|
|
|
528
522
|
data
|
|
529
523
|
};
|
|
530
524
|
};
|
|
525
|
+
|
|
526
|
+
// src/createStore.ts
|
|
527
|
+
var createStore = (id) => {
|
|
528
|
+
const data = createStoreData(id);
|
|
529
|
+
return storeFromStoreData2(data);
|
|
530
|
+
};
|
|
531
531
|
// src/getDefaultStore.ts
|
|
532
532
|
if (!globalThis._valdresStore) {
|
|
533
533
|
globalThis._valdresStore = createStore("default");
|
package/dist/src/atom.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Atom } from "./types/Atom";
|
|
2
|
-
type AtomOptions<
|
|
2
|
+
type AtomOptions<MountRes = undefined> = {
|
|
3
3
|
label?: string;
|
|
4
4
|
onInit?: () => void;
|
|
5
|
-
onMount?: () =>
|
|
6
|
-
onUnmount?: (mountRes?:
|
|
5
|
+
onMount?: () => MountRes;
|
|
6
|
+
onUnmount?: (mountRes?: MountRes) => void;
|
|
7
7
|
};
|
|
8
8
|
export declare const atom: <Value, FamilyKey = undefined, MountReturnValue = undefined>(defaultValue?: Value | (() => Value | Promise<Value>), options?: AtomOptions<MountReturnValue>) => Atom<Value, FamilyKey>;
|
|
9
9
|
export {};
|
package/dist/src/atomFamily.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import type { AtomFamily } from "./types/AtomFamily";
|
|
2
|
-
|
|
2
|
+
type DefaultValueCallback<Key, Value> = (arg: Key) => Value | Promise<Value>;
|
|
3
|
+
export declare const atomFamily: <Value, Key>(defaultValue?: Value | DefaultValueCallback<Key, Value>, debugLabel?: string) => AtomFamily<Value, Key>;
|
|
4
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { StoreData } from "../types/StoreData";
|
|
2
2
|
import type { Selector } from "../types/Selector";
|
|
3
3
|
export declare const reEvaluateSelector: <V>(selector: Selector<V>, data: StoreData) => void;
|
|
4
|
-
export declare const initSelector: <V>(selector: Selector<V>, data: StoreData) => V
|
|
4
|
+
export declare const initSelector: <V>(selector: Selector<V>, data: StoreData) => V | Promise<V>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Family } from "../types/Family";
|
|
1
2
|
import type { State } from "../types/State";
|
|
2
3
|
import type { StoreData } from "../types/StoreData";
|
|
3
|
-
export declare const subscribe: <V>(state: State<V>, callback: any, data: StoreData) => () => void;
|
|
4
|
+
export declare const subscribe: <V>(state: State<V> | Family<V>, callback: any, requireDeepEqualCheckBeforeCallback: boolean, data: StoreData) => () => void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { State } from "../types/State";
|
|
2
2
|
import type { StoreData } from "../types/StoreData";
|
|
3
|
-
export declare const unsubscribe: <V>(state: State<V>, subscription: any,
|
|
3
|
+
export declare const unsubscribe: <V>(state: State<V>, subscription: any, data: StoreData, mount?: any) => void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Selector } from "../types/Selector";
|
|
2
2
|
import type { StoreData } from "../types/StoreData";
|
|
3
|
-
export declare const updateSelectorSubscribers: (selector: Selector, data: StoreData
|
|
3
|
+
export declare const updateSelectorSubscribers: (selector: Selector, data: StoreData) => void;
|
package/dist/src/selector.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { GetValue } from "./types/GetValue";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
debugLabel: string;
|
|
5
|
-
};
|
|
2
|
+
import type { Selector } from "./types/Selector";
|
|
3
|
+
export declare const selector: <Value, FamilyKey = undefined>(get: (get: GetValue) => Value, debugLabel?: string) => Selector<Value, FamilyKey>;
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
_map: Map<any, any>;
|
|
4
|
-
};
|
|
1
|
+
import type { SelectorFamily } from "./types/SelectorFamily";
|
|
2
|
+
export declare const selectorFamily: <Value, Key>(get: any, debugLabel?: string) => SelectorFamily<Value, Key>;
|
package/dist/src/types/Atom.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { AtomFamily } from "./AtomFamily";
|
|
2
|
-
export type Atom<Value = unknown, FamilyKey = undefined> = {
|
|
2
|
+
export type Atom<Value = unknown, FamilyKey = undefined, MountRes = undefined> = {
|
|
3
3
|
defaultValue?: Value | (() => Value | Promise<Value>);
|
|
4
4
|
label?: string;
|
|
5
5
|
family?: AtomFamily<Value, FamilyKey>;
|
|
6
6
|
familyKey?: FamilyKey;
|
|
7
|
+
onInit?: () => void;
|
|
8
|
+
onMount?: () => MountRes;
|
|
9
|
+
onUnmount?: (mountRes?: MountRes) => void;
|
|
7
10
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { State } from "./State";
|
|
2
|
-
export type GetValue = <V>(state: State<V>) => V
|
|
2
|
+
export type GetValue = <V>(state: State<V>) => V | Promise<V>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Atom } from "./Atom";
|
|
2
|
-
export type ResetAtom = <V>(state: Atom<V>) => V
|
|
2
|
+
export type ResetAtom = <V>(state: Atom<V>) => V | Promise<V>;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { GetValue } from "./GetValue";
|
|
2
|
+
import type { SelectorFamily } from "./SelectorFamily";
|
|
3
|
+
export type Selector<Value = any, FamilyKey = undefined> = {
|
|
4
|
+
get: (get: GetValue) => Value;
|
|
3
5
|
debugLabel?: string;
|
|
6
|
+
family?: SelectorFamily<Value, FamilyKey>;
|
|
7
|
+
familyKey?: FamilyKey;
|
|
4
8
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Atom } from "./Atom";
|
|
2
|
-
export type SetAtom = <V>(atom: Atom<V>, value: V) => void;
|
|
2
|
+
export type SetAtom = <V>(atom: Atom<V>, value: V | ((current: V) => V)) => void;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export type StoreData = {
|
|
2
2
|
id: string;
|
|
3
3
|
values: WeakMap<WeakKey, any>;
|
|
4
|
-
|
|
4
|
+
expiredValues: WeakMap<WeakKey, any>;
|
|
5
|
+
subscriptions: WeakMap<WeakKey, Set<any>>;
|
|
6
|
+
subscriptionsRequireEqualCheck: WeakMap<WeakKey, boolean>;
|
|
5
7
|
stateConsumers: WeakMap<WeakKey, any>;
|
|
6
8
|
stateDependencies: WeakMap<WeakKey, any>;
|
|
7
9
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { State } from "./State";
|
|
2
|
-
export type SubscribeFn = <V>(state: State<V>, callback: () => void) => () => void;
|
|
2
|
+
export type SubscribeFn = <V>(state: State<V>, callback: () => void, requireDeepEqualCheckBeforeCallback?: boolean) => () => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const isAtom: (state:
|
|
1
|
+
import type { Atom } from "../types/Atom";
|
|
2
|
+
export declare const isAtom: (state: any) => state is Atom;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isPromiseLike: (object: any) =>
|
|
1
|
+
export declare const isPromiseLike: <T>(object: any) => object is Promise<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valdres",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Eigil Sagafos"
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "NODE_ENV=production bun scripts/build.ts",
|
|
18
|
-
"build:types": "tsc
|
|
17
|
+
"build": "rm -rf dist && NODE_ENV=production bun scripts/build.ts",
|
|
18
|
+
"build:types": "tsc",
|
|
19
19
|
"test": "bun test"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"access": "public",
|
|
35
35
|
"registry": "https://registry.npmjs.org/"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "8fc679bd330552fdc8db39c02cbf4a650d1d2615"
|
|
38
38
|
}
|