@oscarpalmer/mora 0.37.0 → 0.38.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/batch.mjs +1 -0
- package/dist/constants.d.mts +4 -6
- package/dist/effect.d.mts +0 -1
- package/dist/effect.mjs +1 -0
- package/dist/helpers/proxy.mjs +1 -0
- package/dist/helpers/value.mjs +3 -1
- package/dist/models.d.mts +2 -3
- package/dist/mora.full.mjs +125 -73
- package/dist/value/array.d.mts +0 -1
- package/dist/value/array.mjs +1 -1
- package/dist/value/computed.d.mts +0 -1
- package/dist/value/signal.d.mts +0 -1
- package/dist/value/store.d.mts +0 -1
- package/package.json +12 -8
- package/src/batch.ts +1 -0
- package/src/constants.ts +8 -7
- package/src/effect.ts +2 -1
- package/src/helpers/proxy.ts +1 -0
- package/src/helpers/value.ts +3 -1
- package/src/models.ts +2 -2
- package/src/value/array.ts +3 -3
- package/src/value/computed.ts +1 -1
- package/src/value/readonly.ts +1 -1
- package/src/value/signal.ts +1 -1
- package/src/value/store.ts +2 -2
package/dist/batch.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BATCH } from "./constants.mjs";
|
|
2
2
|
import { runEffect } from "./effect.mjs";
|
|
3
3
|
import { getFrozenValue, peekSignalValue } from "./helpers/value.mjs";
|
|
4
|
+
import "@oscarpalmer/atoms/result";
|
|
4
5
|
//#region src/batch.ts
|
|
5
6
|
function flushHandlers() {
|
|
6
7
|
if (BATCH.flushing) return;
|
package/dist/constants.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Active, Batch, SubscriptionType } from "./models.mjs";
|
|
2
|
+
import { SubscriptionProperty } from "@oscarpalmer/atoms/subscription";
|
|
2
3
|
//#region src/constants.d.ts
|
|
3
4
|
export declare const ACTIVE: Active;
|
|
4
5
|
export declare const ARRAY_THRESHOLD = 100;
|
|
@@ -17,12 +18,9 @@ export declare const NAME_STORE = "store";
|
|
|
17
18
|
export declare const NAME_SUBSCRIPTION = "subscription";
|
|
18
19
|
export declare const NAME_ALL: Set<string>;
|
|
19
20
|
export declare const PROPERTY_LENGTH = "length";
|
|
20
|
-
export declare const SYMBOL_EFFECT:
|
|
21
|
-
export declare const SYMBOL_STATE:
|
|
22
|
-
export declare const SUBSCRIPTION_PROPERTY:
|
|
23
|
-
key: string;
|
|
24
|
-
value: string;
|
|
25
|
-
};
|
|
21
|
+
export declare const SYMBOL_EFFECT: symbol;
|
|
22
|
+
export declare const SYMBOL_STATE: symbol;
|
|
23
|
+
export declare const SUBSCRIPTION_PROPERTY: SubscriptionProperty;
|
|
26
24
|
export declare const SUBSCRIPTION_TYPE_COPY: SubscriptionType;
|
|
27
25
|
export declare const SUBSCRIPTION_TYPE_FROZEN: SubscriptionType;
|
|
28
26
|
export declare const SUBSCRIPTION_TYPE_ORIGINAL: SubscriptionType;
|
package/dist/effect.d.mts
CHANGED
package/dist/effect.mjs
CHANGED
package/dist/helpers/proxy.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { SYMBOL_EFFECT, SYMBOL_STATE } from "../constants.mjs";
|
|
|
2
2
|
import { emitValue, getSignalValue, peekSignalValue } from "./value.mjs";
|
|
3
3
|
import { startBatch, stopBatch } from "../batch.mjs";
|
|
4
4
|
import { internalComputed } from "../value/computed.mjs";
|
|
5
|
+
import "@oscarpalmer/atoms/result";
|
|
5
6
|
import { isKey, isPlainObject } from "@oscarpalmer/atoms/is";
|
|
6
7
|
//#region src/helpers/proxy.ts
|
|
7
8
|
function getReactiveValueInProxy(instance, key) {
|
package/dist/helpers/value.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ACTIVE, BATCH, SUBSCRIPTION_TYPES, SUBSCRIPTION_TYPES_COPY, SUBSCRIPTION_TYPE_FROZEN, SYMBOL_EFFECT, SYMBOL_STATE } from "../constants.mjs";
|
|
2
2
|
import { flushHandlers } from "../batch.mjs";
|
|
3
|
+
import "@oscarpalmer/atoms/result";
|
|
3
4
|
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
5
|
+
import { round } from "@oscarpalmer/atoms/math";
|
|
4
6
|
//#region src/helpers/value.ts
|
|
5
7
|
function emitValue(instance, notify) {
|
|
6
8
|
const state = instance[SYMBOL_STATE];
|
|
@@ -31,7 +33,7 @@ function equalArrays(first, second, equal) {
|
|
|
31
33
|
const eq = equal ?? Object.is;
|
|
32
34
|
let offset = 0;
|
|
33
35
|
if (length >= 100) {
|
|
34
|
-
offset =
|
|
36
|
+
offset = round(length / 10);
|
|
35
37
|
offset = offset > 25 ? 25 : offset;
|
|
36
38
|
for (let index = 0; index < offset; index += 1) if (!(eq(first[index], second[index]) && eq(first[length - index - 1], second[length - index - 1]))) return false;
|
|
37
39
|
}
|
package/dist/models.d.mts
CHANGED
|
@@ -26,8 +26,7 @@ export type InternalArray = {
|
|
|
26
26
|
} & ReactiveArray<unknown>;
|
|
27
27
|
export type InternalComputed = {
|
|
28
28
|
[SYMBOL_EFFECT]: ComputedEffect;
|
|
29
|
-
|
|
30
|
-
} & Computed<unknown>;
|
|
29
|
+
} & Computed<unknown> & InternalStateful;
|
|
31
30
|
export type InternalReadonly = {
|
|
32
31
|
frozen: boolean;
|
|
33
32
|
} & InternalStateful & ReadonlySignal<unknown>;
|
|
@@ -447,5 +446,5 @@ export type StoredSubscription = {
|
|
|
447
446
|
state: SignalState;
|
|
448
447
|
};
|
|
449
448
|
export type Subscriber<Value> = (value: Value, subscription: Subscription) => void;
|
|
450
|
-
export type SubscriptionType =
|
|
449
|
+
export type SubscriptionType = "copy" | "frozen" | "original" | "readonly";
|
|
451
450
|
//#endregion
|
package/dist/mora.full.mjs
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
1
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/is.mjs
|
|
2
|
+
/**
|
|
3
|
+
* Is the value a _Key_?
|
|
4
|
+
*
|
|
5
|
+
* @param value Value to check
|
|
6
|
+
* @returns `true` if the value is a _Key_ _(`number` or `string`)_, otherwise `false`
|
|
7
|
+
*/
|
|
8
|
+
function isKey(value) {
|
|
9
|
+
return typeof value === "number" || typeof value === "string";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Is the value a plain object?
|
|
13
|
+
*
|
|
14
|
+
* @param value Value to check
|
|
15
|
+
* @returns `true` if the value is a plain object, otherwise `false`
|
|
16
|
+
*/
|
|
17
|
+
function isPlainObject(value) {
|
|
18
|
+
if (value === null || typeof value !== "object") return false;
|
|
19
|
+
if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
|
|
20
|
+
const prototype = Object.getPrototypeOf(value);
|
|
21
|
+
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/result/misc.mjs
|
|
25
|
+
function error(value, original) {
|
|
26
|
+
return getError(value, original);
|
|
27
|
+
}
|
|
28
|
+
function getError(value, original) {
|
|
29
|
+
const errorResult = {
|
|
30
|
+
error: value,
|
|
31
|
+
ok: false
|
|
32
|
+
};
|
|
33
|
+
if (original instanceof Error) errorResult.original = original;
|
|
34
|
+
return errorResult;
|
|
35
|
+
}
|
|
36
|
+
function isError(value, extended) {
|
|
37
|
+
return isResultValue(value, false) && (extended === true ? value.original instanceof Error : true);
|
|
38
|
+
}
|
|
39
|
+
function isOk(value) {
|
|
40
|
+
return isResultValue(value, true);
|
|
41
|
+
}
|
|
42
|
+
function isResultValue(value, okValue) {
|
|
43
|
+
return isPlainObject(value) && value.ok === okValue && (okValue ? RESULT_PROPERTY_VALUE : RESULT_PROPERTY_ERROR) in value;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates an ok result
|
|
47
|
+
*
|
|
48
|
+
* @param value Value
|
|
49
|
+
* @returns Ok result
|
|
50
|
+
*/
|
|
51
|
+
function ok(value) {
|
|
52
|
+
return {
|
|
53
|
+
ok: true,
|
|
54
|
+
value
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const RESULT_PROPERTY_ERROR = "error";
|
|
58
|
+
const RESULT_PROPERTY_VALUE = "value";
|
|
59
|
+
error.is = isError;
|
|
60
|
+
ok.is = isOk;
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region node_modules/@oscarpalmer/atoms/dist/result/index.mjs
|
|
63
|
+
async function asyncAttempt(value, err) {
|
|
64
|
+
try {
|
|
65
|
+
let result;
|
|
66
|
+
if (typeof value === "function") result = value();
|
|
67
|
+
else result = value;
|
|
68
|
+
if (result instanceof Promise) result = await result;
|
|
69
|
+
return ok(result);
|
|
70
|
+
} catch (thrown) {
|
|
71
|
+
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function attempt(callback, err) {
|
|
75
|
+
try {
|
|
76
|
+
return ok(callback());
|
|
77
|
+
} catch (thrown) {
|
|
78
|
+
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
attempt.async = asyncAttempt;
|
|
82
|
+
//#endregion
|
|
1
83
|
//#region src/constants.ts
|
|
2
84
|
const ACTIVE = {};
|
|
3
85
|
const BATCH = {
|
|
@@ -84,28 +166,41 @@ function runEffect(state) {
|
|
|
84
166
|
ACTIVE.effect = previousEffect;
|
|
85
167
|
}
|
|
86
168
|
}
|
|
169
|
+
function getAbsoluteValue(condition, aggregation, value, notNumber, item) {
|
|
170
|
+
if (notNumber || condition(aggregation, value)) {
|
|
171
|
+
if (aggregation.array) {
|
|
172
|
+
aggregation.items ??= {};
|
|
173
|
+
aggregation.items[value] ??= [];
|
|
174
|
+
aggregation.items[value].push(item);
|
|
175
|
+
}
|
|
176
|
+
return value;
|
|
177
|
+
}
|
|
178
|
+
return aggregation.value;
|
|
179
|
+
}
|
|
180
|
+
function isMaxValue(aggregation, value) {
|
|
181
|
+
return aggregation.array ? value >= aggregation.value : value > aggregation.value;
|
|
182
|
+
}
|
|
183
|
+
function isMinValue(aggregation, value) {
|
|
184
|
+
return aggregation.array ? value <= aggregation.value : value < aggregation.value;
|
|
185
|
+
}
|
|
186
|
+
getAbsoluteValue.bind(void 0, isMaxValue), getAbsoluteValue.bind(void 0, isMinValue);
|
|
87
187
|
//#endregion
|
|
88
|
-
//#region node_modules/@oscarpalmer/atoms/dist/internal/
|
|
188
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/math/misc.mjs
|
|
89
189
|
/**
|
|
90
|
-
*
|
|
190
|
+
* Round a number
|
|
91
191
|
*
|
|
92
|
-
* @param value
|
|
93
|
-
* @
|
|
192
|
+
* @param value Number to round
|
|
193
|
+
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
194
|
+
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
94
195
|
*/
|
|
95
|
-
function
|
|
96
|
-
return
|
|
196
|
+
function round(value, decimals) {
|
|
197
|
+
return roundNumber(Math.round, value, decimals);
|
|
97
198
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*/
|
|
104
|
-
function isPlainObject(value) {
|
|
105
|
-
if (value === null || typeof value !== "object") return false;
|
|
106
|
-
if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
|
|
107
|
-
const prototype = Object.getPrototypeOf(value);
|
|
108
|
-
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
199
|
+
function roundNumber(callback, value, decimals) {
|
|
200
|
+
if (typeof value !== "number") return NaN;
|
|
201
|
+
if (typeof decimals !== "number" || decimals < 1) return callback(value);
|
|
202
|
+
const mod = 10 ** decimals;
|
|
203
|
+
return callback((value + Number.EPSILON) * mod) / mod;
|
|
109
204
|
}
|
|
110
205
|
//#endregion
|
|
111
206
|
//#region src/helpers/value.ts
|
|
@@ -138,7 +233,7 @@ function equalArrays(first, second, equal) {
|
|
|
138
233
|
const eq = equal ?? Object.is;
|
|
139
234
|
let offset = 0;
|
|
140
235
|
if (length >= 100) {
|
|
141
|
-
offset =
|
|
236
|
+
offset = round(length / 10);
|
|
142
237
|
offset = offset > 25 ? 25 : offset;
|
|
143
238
|
for (let index = 0; index < offset; index += 1) if (!(eq(first[index], second[index]) && eq(first[length - index - 1], second[length - index - 1]))) return false;
|
|
144
239
|
}
|
|
@@ -331,29 +426,6 @@ function createFindParameters(original) {
|
|
|
331
426
|
value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
|
|
332
427
|
};
|
|
333
428
|
}
|
|
334
|
-
function findValue(type, array, parameters, reversed) {
|
|
335
|
-
const findIndex = type === FIND_VALUE_INDEX;
|
|
336
|
-
if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
|
|
337
|
-
const { bool, key, value } = createFindParameters(parameters);
|
|
338
|
-
const callbacks = getArrayCallbacks(bool, key);
|
|
339
|
-
if (callbacks?.bool == null && callbacks?.keyed == null) {
|
|
340
|
-
if (findIndex) return reversed ? array.lastIndexOf(value) : array.indexOf(value);
|
|
341
|
-
return reversed ? array.findLast((item) => Object.is(item, value)) : array.find((item) => Object.is(item, value));
|
|
342
|
-
}
|
|
343
|
-
if (callbacks.bool != null) {
|
|
344
|
-
const index = reversed ? array.findLastIndex(callbacks.bool) : array.findIndex(callbacks.bool);
|
|
345
|
-
return findIndex ? index : array[index];
|
|
346
|
-
}
|
|
347
|
-
return findValueInArray(array, callbacks.keyed, value, findIndex, reversed);
|
|
348
|
-
}
|
|
349
|
-
function findValueInArray(array, callback, value, findIndex, reversed) {
|
|
350
|
-
const { length } = array;
|
|
351
|
-
for (let index = 0; index < length; index += 1) {
|
|
352
|
-
const item = reversed ? array.at(-(index + 1)) : array[index];
|
|
353
|
-
if (Object.is(callback?.(item, index, array), value)) return findIndex ? index : item;
|
|
354
|
-
}
|
|
355
|
-
return findIndex ? -1 : void 0;
|
|
356
|
-
}
|
|
357
429
|
function findValues(type, array, parameters, mapper) {
|
|
358
430
|
const result = {
|
|
359
431
|
matched: [],
|
|
@@ -400,54 +472,34 @@ function findValues(type, array, parameters, mapper) {
|
|
|
400
472
|
}
|
|
401
473
|
return result;
|
|
402
474
|
}
|
|
403
|
-
const FIND_VALUE_INDEX = "index";
|
|
404
|
-
const FIND_VALUE_ITEM = "item";
|
|
405
475
|
const FIND_UNIQUE_THRESHOLD = 100;
|
|
406
476
|
//#endregion
|
|
407
|
-
//#region node_modules/@oscarpalmer/atoms/dist/
|
|
408
|
-
function
|
|
409
|
-
return
|
|
410
|
-
}
|
|
411
|
-
function lastIndexOf(array, ...parameters) {
|
|
412
|
-
return findValue(FIND_VALUE_INDEX, array, parameters, true);
|
|
413
|
-
}
|
|
414
|
-
indexOf.last = lastIndexOf;
|
|
415
|
-
//#endregion
|
|
416
|
-
//#region node_modules/@oscarpalmer/atoms/dist/array/find.mjs
|
|
417
|
-
function find(array, ...parameters) {
|
|
418
|
-
return findValue(FIND_VALUE_ITEM, array, parameters, false);
|
|
477
|
+
//#region node_modules/@oscarpalmer/atoms/dist/array/filter.mjs
|
|
478
|
+
function exclude(array, ...parameters) {
|
|
479
|
+
return findValues("all", array, parameters).notMatched;
|
|
419
480
|
}
|
|
420
|
-
function
|
|
421
|
-
return
|
|
481
|
+
function filter(array, ...parameters) {
|
|
482
|
+
return findValues("all", array, parameters).matched;
|
|
422
483
|
}
|
|
423
|
-
|
|
484
|
+
filter.remove = exclude;
|
|
424
485
|
//#endregion
|
|
425
486
|
//#region node_modules/@oscarpalmer/atoms/dist/array/select.mjs
|
|
426
|
-
function
|
|
487
|
+
function filterAndMap(array, ...parameters) {
|
|
488
|
+
return selectValues(array, parameters);
|
|
489
|
+
}
|
|
490
|
+
function mapAndFilter(array, ...parameters) {
|
|
427
491
|
return findValues("all", array, parameters, {
|
|
428
492
|
callback: parameters.shift(),
|
|
429
493
|
reverse: true
|
|
430
494
|
}).matched;
|
|
431
495
|
}
|
|
432
|
-
function select(array, ...parameters) {
|
|
433
|
-
return selectValues(array, parameters);
|
|
434
|
-
}
|
|
435
496
|
function selectValues(array, parameters) {
|
|
436
497
|
return findValues("all", array, parameters, {
|
|
437
498
|
callback: parameters.pop(),
|
|
438
499
|
reverse: false
|
|
439
500
|
}).matched;
|
|
440
501
|
}
|
|
441
|
-
|
|
442
|
-
//#endregion
|
|
443
|
-
//#region node_modules/@oscarpalmer/atoms/dist/array/filter.mjs
|
|
444
|
-
function exclude(array, ...parameters) {
|
|
445
|
-
return findValues("all", array, parameters).notMatched;
|
|
446
|
-
}
|
|
447
|
-
function filter(array, ...parameters) {
|
|
448
|
-
return findValues("all", array, parameters).matched;
|
|
449
|
-
}
|
|
450
|
-
filter.remove = exclude;
|
|
502
|
+
filterAndMap.reverse = mapAndFilter;
|
|
451
503
|
//#endregion
|
|
452
504
|
//#region src/helpers/misc.ts
|
|
453
505
|
function getState(value, options) {
|
|
@@ -1029,7 +1081,7 @@ function pushArrayValues(...items) {
|
|
|
1029
1081
|
return this[SYMBOL_STATE].value.push(...items);
|
|
1030
1082
|
}
|
|
1031
1083
|
function selectArrayValues(filter, map) {
|
|
1032
|
-
return computed(() =>
|
|
1084
|
+
return computed(() => filterAndMap(getArrayValues.call(this), filter, map));
|
|
1033
1085
|
}
|
|
1034
1086
|
function setArrayLength(value) {
|
|
1035
1087
|
const values = this[SYMBOL_STATE].value;
|
package/dist/value/array.d.mts
CHANGED
package/dist/value/array.mjs
CHANGED
|
@@ -6,8 +6,8 @@ import { computed } from "./computed.mjs";
|
|
|
6
6
|
import { getValueInProxy, notifyProxyValue, peekValueInProxy, setProxyValue, setValueInProxy, updateProxyValue } from "../helpers/proxy.mjs";
|
|
7
7
|
import { getReadonlySignal } from "./readonly.mjs";
|
|
8
8
|
import { signal } from "./signal.mjs";
|
|
9
|
-
import { select } from "@oscarpalmer/atoms/array";
|
|
10
9
|
import { filter } from "@oscarpalmer/atoms/array/filter";
|
|
10
|
+
import { select } from "@oscarpalmer/atoms/array/select";
|
|
11
11
|
//#region src/value/array.ts
|
|
12
12
|
function ReactiveArray(value, options) {
|
|
13
13
|
this[SYMBOL_STATE] = {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Computed, InternalComputed, ReactiveOptions } from "../models.mjs";
|
|
2
2
|
import { GenericCallback } from "@oscarpalmer/atoms/models";
|
|
3
3
|
//#region src/value/computed.d.ts
|
|
4
|
-
declare function Computed(this: any, callback: GenericCallback, options?: ReactiveOptions<unknown>): void;
|
|
5
4
|
/**
|
|
6
5
|
* Create a computed value
|
|
7
6
|
*
|
package/dist/value/signal.d.mts
CHANGED
package/dist/value/store.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ReactiveOptions, ReactiveStore } from "../models.mjs";
|
|
2
2
|
import { PlainObject } from "@oscarpalmer/atoms/models";
|
|
3
3
|
//#region src/value/store.d.ts
|
|
4
|
-
declare function ReactiveStore(this: any, value: never, options?: ReactiveOptions<unknown>): void;
|
|
5
4
|
/**
|
|
6
5
|
* Create a reactive store from a function result
|
|
7
6
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/mora",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "Signals and stuff…",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"reactive",
|
|
@@ -39,17 +39,21 @@
|
|
|
39
39
|
"test:leak": "vpx vp test run --detect-async-leaks --coverage"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@oscarpalmer/atoms": "^0.
|
|
42
|
+
"@oscarpalmer/atoms": "^0.205"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@types/node": "^26.
|
|
46
|
-
"@vitest/coverage-istanbul": "
|
|
45
|
+
"@types/node": "^26.6",
|
|
46
|
+
"@vitest/coverage-istanbul": "5.0.1",
|
|
47
47
|
"jsdom": "^30.1",
|
|
48
48
|
"tsdown": "^0.23",
|
|
49
|
-
"typescript": "^
|
|
50
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@
|
|
51
|
-
"vite-plus": "
|
|
52
|
-
"vitest": "
|
|
49
|
+
"typescript": "^7",
|
|
50
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.0.0",
|
|
51
|
+
"vite-plus": "1.0.0",
|
|
52
|
+
"vitest": "5.0.1"
|
|
53
|
+
},
|
|
54
|
+
"overrides": {
|
|
55
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.0.0",
|
|
56
|
+
"vitest": "5.0.1"
|
|
53
57
|
},
|
|
54
58
|
"packageManager": "npm@11.19.0"
|
|
55
59
|
}
|
package/src/batch.ts
CHANGED
package/src/constants.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {SubscriptionProperty} from '@oscarpalmer/atoms/subscription';
|
|
1
2
|
import type {Active, Batch, SubscriptionType} from './models';
|
|
2
3
|
|
|
3
4
|
// #region Variables
|
|
@@ -16,14 +17,14 @@ export const BATCH: Batch = {
|
|
|
16
17
|
handlers: new Map(),
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
export const METHODS_AFFECTING_LENGTH
|
|
20
|
+
export const METHODS_AFFECTING_LENGTH: Set<string | symbol> = new Set([
|
|
20
21
|
'pop',
|
|
21
22
|
'push',
|
|
22
23
|
'shift',
|
|
23
24
|
'unshift',
|
|
24
25
|
]);
|
|
25
26
|
|
|
26
|
-
export const METHODS_UPDATE
|
|
27
|
+
export const METHODS_UPDATE: Set<string | symbol> = new Set([
|
|
27
28
|
...METHODS_AFFECTING_LENGTH,
|
|
28
29
|
'copyWithin',
|
|
29
30
|
'fill',
|
|
@@ -48,7 +49,7 @@ export const NAME_STORE = 'store';
|
|
|
48
49
|
|
|
49
50
|
export const NAME_SUBSCRIPTION = 'subscription';
|
|
50
51
|
|
|
51
|
-
export const NAME_ALL = new Set([
|
|
52
|
+
export const NAME_ALL: Set<string> = new Set([
|
|
52
53
|
NAME_ARRAY,
|
|
53
54
|
NAME_COMPUTED,
|
|
54
55
|
NAME_READONLY,
|
|
@@ -58,11 +59,11 @@ export const NAME_ALL = new Set([
|
|
|
58
59
|
|
|
59
60
|
export const PROPERTY_LENGTH = 'length';
|
|
60
61
|
|
|
61
|
-
export const SYMBOL_EFFECT = Symbol('effect');
|
|
62
|
+
export const SYMBOL_EFFECT: symbol = Symbol('effect');
|
|
62
63
|
|
|
63
|
-
export const SYMBOL_STATE = Symbol('state');
|
|
64
|
+
export const SYMBOL_STATE: symbol = Symbol('state');
|
|
64
65
|
|
|
65
|
-
export const SUBSCRIPTION_PROPERTY = {
|
|
66
|
+
export const SUBSCRIPTION_PROPERTY: SubscriptionProperty = {
|
|
66
67
|
key: NAME_MORA,
|
|
67
68
|
value: NAME_SUBSCRIPTION,
|
|
68
69
|
};
|
|
@@ -75,7 +76,7 @@ export const SUBSCRIPTION_TYPE_ORIGINAL: SubscriptionType = 'original';
|
|
|
75
76
|
|
|
76
77
|
export const SUBSCRIPTION_TYPE_READONLY: SubscriptionType = 'readonly';
|
|
77
78
|
|
|
78
|
-
export const SUBSCRIPTION_TYPES_COPY = new Set
|
|
79
|
+
export const SUBSCRIPTION_TYPES_COPY: Set<SubscriptionType> = new Set([
|
|
79
80
|
SUBSCRIPTION_TYPE_COPY,
|
|
80
81
|
SUBSCRIPTION_TYPE_READONLY,
|
|
81
82
|
]);
|
package/src/effect.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type {GenericCallback} from '@oscarpalmer/atoms/models';
|
|
2
|
+
import {attempt} from '@oscarpalmer/atoms/result';
|
|
2
3
|
import {ACTIVE, NAME_EFFECT, NAME_MORA, SYMBOL_STATE} from './constants';
|
|
3
4
|
import type {Effect, EffectState} from './models';
|
|
4
5
|
|
|
5
6
|
// #region Instance
|
|
6
7
|
|
|
7
|
-
function Effect(this: any, callback: GenericCallback) {
|
|
8
|
+
function Effect(this: any, callback: GenericCallback): void {
|
|
8
9
|
this[SYMBOL_STATE] = {callback};
|
|
9
10
|
|
|
10
11
|
runEffect(this[SYMBOL_STATE]);
|
package/src/helpers/proxy.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
Key,
|
|
6
6
|
PlainObject,
|
|
7
7
|
} from '@oscarpalmer/atoms/models';
|
|
8
|
+
import {attempt} from '@oscarpalmer/atoms/result';
|
|
8
9
|
import {startBatch, stopBatch} from '../batch';
|
|
9
10
|
import {PROPERTY_LENGTH, SYMBOL_EFFECT, SYMBOL_STATE} from '../constants';
|
|
10
11
|
import type {InternalArray, InternalComputed, InternalStore, ReactiveProxyState} from '../models';
|
package/src/helpers/value.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import {isPlainObject} from '@oscarpalmer/atoms/is';
|
|
2
|
+
import {round} from '@oscarpalmer/atoms/math';
|
|
3
|
+
import {attempt} from '@oscarpalmer/atoms/result';
|
|
2
4
|
import {flushHandlers} from '../batch';
|
|
3
5
|
import {
|
|
4
6
|
ACTIVE,
|
|
@@ -86,7 +88,7 @@ export function equalArrays(
|
|
|
86
88
|
let offset = 0;
|
|
87
89
|
|
|
88
90
|
if (length >= ARRAY_THRESHOLD) {
|
|
89
|
-
offset =
|
|
91
|
+
offset = round(length / ARRAY_PEEK);
|
|
90
92
|
offset = offset > ARRAY_OFFSET ? ARRAY_OFFSET : offset;
|
|
91
93
|
|
|
92
94
|
for (let index = 0; index < offset; index += 1) {
|
package/src/models.ts
CHANGED
|
@@ -35,8 +35,8 @@ export type InternalArray = {
|
|
|
35
35
|
|
|
36
36
|
export type InternalComputed = {
|
|
37
37
|
[SYMBOL_EFFECT]: ComputedEffect;
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
} & Computed<unknown> &
|
|
39
|
+
InternalStateful;
|
|
40
40
|
|
|
41
41
|
export type InternalReadonly = {
|
|
42
42
|
frozen: boolean;
|
package/src/value/array.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {select} from '@oscarpalmer/atoms/array';
|
|
2
1
|
import {filter} from '@oscarpalmer/atoms/array/filter';
|
|
2
|
+
import {select} from '@oscarpalmer/atoms/array/select';
|
|
3
3
|
import {
|
|
4
4
|
METHODS_AFFECTING_LENGTH,
|
|
5
5
|
METHODS_UPDATE,
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
} from '../constants';
|
|
11
11
|
import {getState} from '../helpers/misc';
|
|
12
12
|
import {
|
|
13
|
-
notifyProxyValue,
|
|
14
13
|
getValueInProxy,
|
|
14
|
+
notifyProxyValue,
|
|
15
15
|
peekValueInProxy,
|
|
16
16
|
setProxyValue,
|
|
17
17
|
setValueInProxy,
|
|
@@ -26,7 +26,7 @@ import {signal} from './signal';
|
|
|
26
26
|
|
|
27
27
|
// #region Instance
|
|
28
28
|
|
|
29
|
-
function ReactiveArray(this: any, value: unknown, options?: ReactiveOptions<unknown>) {
|
|
29
|
+
function ReactiveArray(this: any, value: unknown, options?: ReactiveOptions<unknown>): void {
|
|
30
30
|
this[SYMBOL_STATE] = {
|
|
31
31
|
...getState(undefined, options),
|
|
32
32
|
isArray: true,
|
package/src/value/computed.ts
CHANGED
|
@@ -25,7 +25,7 @@ import type {
|
|
|
25
25
|
|
|
26
26
|
// #region Instance
|
|
27
27
|
|
|
28
|
-
function Computed(this: any, callback: GenericCallback, options?: ReactiveOptions<unknown>) {
|
|
28
|
+
function Computed(this: any, callback: GenericCallback, options?: ReactiveOptions<unknown>): void {
|
|
29
29
|
this[SYMBOL_STATE] = getState(undefined, options);
|
|
30
30
|
this[SYMBOL_EFFECT] = getComputedEffect(this, callback);
|
|
31
31
|
}
|
package/src/value/readonly.ts
CHANGED
|
@@ -25,7 +25,7 @@ type InternalReadonly = {
|
|
|
25
25
|
|
|
26
26
|
// #region Instance
|
|
27
27
|
|
|
28
|
-
function Readonly(this: any, state: SignalState, frozen: boolean) {
|
|
28
|
+
function Readonly(this: any, state: SignalState, frozen: boolean): void {
|
|
29
29
|
this[SUBSCRIPTION_TYPE_FROZEN] = frozen;
|
|
30
30
|
this[SYMBOL_STATE] = state;
|
|
31
31
|
}
|
package/src/value/signal.ts
CHANGED
|
@@ -15,7 +15,7 @@ import {getReadonlySignal} from './readonly';
|
|
|
15
15
|
|
|
16
16
|
// #region Instance
|
|
17
17
|
|
|
18
|
-
function Signal(this: any, value: unknown, options?: ReactiveOptions<unknown>) {
|
|
18
|
+
function Signal(this: any, value: unknown, options?: ReactiveOptions<unknown>): void {
|
|
19
19
|
this[SYMBOL_STATE] = getState(undefined, options);
|
|
20
20
|
|
|
21
21
|
handleSignal(this, value, setAndEmit);
|
package/src/value/store.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type {PlainObject} from '@oscarpalmer/atoms/models';
|
|
|
2
2
|
import {NAME_MORA, NAME_STORE, SYMBOL_STATE} from '../constants';
|
|
3
3
|
import {getState} from '../helpers/misc';
|
|
4
4
|
import {
|
|
5
|
-
notifyProxyValue,
|
|
6
5
|
getValueInProxy,
|
|
6
|
+
notifyProxyValue,
|
|
7
7
|
peekValueInProxy,
|
|
8
8
|
setProxyValue,
|
|
9
9
|
setValueInProxy,
|
|
@@ -16,7 +16,7 @@ import {getReadonlySignal} from './readonly';
|
|
|
16
16
|
|
|
17
17
|
// #region Instance
|
|
18
18
|
|
|
19
|
-
function ReactiveStore(this: any, value: never, options?: ReactiveOptions<unknown>) {
|
|
19
|
+
function ReactiveStore(this: any, value: never, options?: ReactiveOptions<unknown>): void {
|
|
20
20
|
this[SYMBOL_STATE] = {
|
|
21
21
|
...getState(undefined, options),
|
|
22
22
|
isArray: false,
|