@oscarpalmer/mora 0.13.0 → 0.14.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.cjs +2 -2
- package/dist/batch.js +1 -1
- package/dist/effect.cjs +2 -1
- package/dist/effect.js +2 -1
- package/dist/helpers/emit.cjs +42 -0
- package/dist/helpers/emit.js +42 -0
- package/dist/helpers/is.cjs +34 -0
- package/dist/helpers/is.js +34 -0
- package/dist/helpers/value.cjs +22 -0
- package/dist/helpers/value.js +22 -0
- package/dist/index.cjs +12 -11
- package/dist/index.js +5 -4
- package/dist/mora.full.js +152 -140
- package/dist/{array.cjs → value/array.cjs} +27 -49
- package/dist/{array.js → value/array.js} +9 -31
- package/dist/{computed.cjs → value/computed.cjs} +6 -5
- package/dist/{computed.js → value/computed.js} +4 -3
- package/dist/{reactive.cjs → value/reactive.cjs} +1 -1
- package/dist/{reactive.js → value/reactive.js} +1 -1
- package/dist/value/signal.cjs +33 -0
- package/dist/{signal.js → value/signal.js} +3 -2
- package/package.json +1 -1
- package/src/batch.ts +1 -1
- package/src/effect.ts +12 -11
- package/src/helpers/emit.ts +52 -0
- package/src/helpers/is.ts +56 -0
- package/src/helpers/value.ts +27 -0
- package/src/index.ts +11 -5
- package/src/subscription.ts +1 -1
- package/src/{array.ts → value/array.ts} +10 -41
- package/src/{computed.ts → value/computed.ts} +4 -3
- package/src/{reactive.ts → value/reactive.ts} +3 -3
- package/src/{signal.ts → value/signal.ts} +3 -2
- package/types/batch.d.cts +9 -9
- package/types/helpers/emit.d.cts +63 -0
- package/types/helpers/emit.d.ts +3 -0
- package/types/{is.d.cts → helpers/is.d.cts} +53 -9
- package/types/helpers/is.d.ts +26 -0
- package/types/{value.d.cts → helpers/value.d.cts} +9 -10
- package/types/{value.d.ts → helpers/value.d.ts} +1 -2
- package/types/index.d.cts +42 -38
- package/types/index.d.ts +5 -5
- package/types/subscription.d.cts +12 -12
- package/types/subscription.d.ts +1 -1
- package/types/{computed.d.ts → value/computed.d.ts} +1 -1
- package/types/{reactive.d.ts → value/reactive.d.ts} +2 -2
- package/dist/is.cjs +0 -21
- package/dist/is.js +0 -21
- package/dist/signal.cjs +0 -32
- package/dist/value.cjs +0 -38
- package/dist/value.js +0 -38
- package/src/is.ts +0 -39
- package/src/value.ts +0 -47
- package/types/is.d.ts +0 -17
- package/types/{array.d.cts → value/array.d.cts} +9 -9
- package/types/{array.d.ts → value/array.d.ts} +0 -0
- package/types/{computed.d.cts → value/computed.d.cts} +9 -9
- package/types/{reactive.d.cts → value/reactive.d.cts} +9 -9
- package/types/{signal.d.cts → value/signal.d.cts} +9 -9
- /package/types/{signal.d.ts → value/signal.d.ts} +0 -0
package/src/value.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {batchDepth, batchedHandlers, flushEffects} from './batch';
|
|
2
|
-
import {type InternalComputed, activeComputed} from './computed';
|
|
3
|
-
import {activeEffect} from './effect';
|
|
4
|
-
import type {ReactiveState} from './reactive';
|
|
5
|
-
|
|
6
|
-
export function emitValue<Value>(state: ReactiveState<Value>): void {
|
|
7
|
-
for (const computed of state.computeds) {
|
|
8
|
-
(computed as unknown as InternalComputed).effect.dirty = true;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
for (const effect of state.effects) {
|
|
12
|
-
batchedHandlers.add(effect);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
for (const [, subscription] of state.subscriptions) {
|
|
16
|
-
batchedHandlers.add(subscription as never);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (batchDepth === 0) {
|
|
20
|
-
flushEffects();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function getValue<Value>(state: ReactiveState<Value>): Value {
|
|
25
|
-
if (activeComputed != null) {
|
|
26
|
-
state.computeds.add(activeComputed);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (activeEffect != null) {
|
|
30
|
-
state.effects.add(activeEffect);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return state.value;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function setValue<Value>(
|
|
37
|
-
state: ReactiveState<Value>,
|
|
38
|
-
value: Value,
|
|
39
|
-
): void {
|
|
40
|
-
if (Object.is(state.value, value)) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
state.value = value;
|
|
45
|
-
|
|
46
|
-
emitValue(state);
|
|
47
|
-
}
|
package/types/is.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Computed } from './computed';
|
|
2
|
-
import type { Effect } from './effect';
|
|
3
|
-
import type { Reactive } from './reactive';
|
|
4
|
-
import type { Signal } from './signal';
|
|
5
|
-
/**
|
|
6
|
-
* Is the value a computed signal?
|
|
7
|
-
*/
|
|
8
|
-
export declare function isComputed(value: unknown): value is Computed<unknown>;
|
|
9
|
-
/**
|
|
10
|
-
* Is the value an effect?
|
|
11
|
-
*/
|
|
12
|
-
export declare function isEffect(value: unknown): value is Effect;
|
|
13
|
-
export declare function isReactive(value: unknown): value is Reactive<unknown>;
|
|
14
|
-
/**
|
|
15
|
-
* Is the value a signal?
|
|
16
|
-
*/
|
|
17
|
-
export declare function isSignal(value: unknown): value is Signal<unknown>;
|
|
@@ -14,15 +14,6 @@ declare class Computed<Value> extends Reactive<Value> {
|
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
-
declare class Subscription<Value> {
|
|
18
|
-
state: ReactiveState<Value>;
|
|
19
|
-
callback: GenericCallback;
|
|
20
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Unsubscribe from changes
|
|
24
|
-
*/
|
|
25
|
-
export type Unsubscribe = () => void;
|
|
26
17
|
declare abstract class Reactive<Value> {
|
|
27
18
|
protected readonly state: ReactiveState<Value>;
|
|
28
19
|
constructor(name: string, value: Value);
|
|
@@ -57,6 +48,15 @@ export type ReactiveState<Value> = {
|
|
|
57
48
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
58
49
|
value: Value;
|
|
59
50
|
};
|
|
51
|
+
declare class Subscription<Value> {
|
|
52
|
+
state: ReactiveState<Value>;
|
|
53
|
+
callback: GenericCallback;
|
|
54
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Unsubscribe from changes
|
|
58
|
+
*/
|
|
59
|
+
export type Unsubscribe = () => void;
|
|
60
60
|
export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
61
61
|
#private;
|
|
62
62
|
/**
|
|
File without changes
|
|
@@ -27,15 +27,6 @@ export declare class Computed<Value> extends Reactive<Value> {
|
|
|
27
27
|
* Create a computed value
|
|
28
28
|
*/
|
|
29
29
|
export declare function computed<Value>(callback: () => Value): Computed<Value>;
|
|
30
|
-
declare class Subscription<Value> {
|
|
31
|
-
state: ReactiveState<Value>;
|
|
32
|
-
callback: GenericCallback;
|
|
33
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Unsubscribe from changes
|
|
37
|
-
*/
|
|
38
|
-
export type Unsubscribe = () => void;
|
|
39
30
|
declare abstract class Reactive<Value> {
|
|
40
31
|
protected readonly state: ReactiveState<Value>;
|
|
41
32
|
constructor(name: string, value: Value);
|
|
@@ -70,5 +61,14 @@ export type ReactiveState<Value> = {
|
|
|
70
61
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
71
62
|
value: Value;
|
|
72
63
|
};
|
|
64
|
+
declare class Subscription<Value> {
|
|
65
|
+
state: ReactiveState<Value>;
|
|
66
|
+
callback: GenericCallback;
|
|
67
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Unsubscribe from changes
|
|
71
|
+
*/
|
|
72
|
+
export type Unsubscribe = () => void;
|
|
73
73
|
|
|
74
74
|
export {};
|
|
@@ -14,15 +14,6 @@ declare class Computed<Value> extends Reactive<Value> {
|
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
-
declare class Subscription<Value> {
|
|
18
|
-
state: ReactiveState<Value>;
|
|
19
|
-
callback: GenericCallback;
|
|
20
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Unsubscribe from changes
|
|
24
|
-
*/
|
|
25
|
-
export type Unsubscribe = () => void;
|
|
26
17
|
export declare abstract class Reactive<Value> {
|
|
27
18
|
protected readonly state: ReactiveState<Value>;
|
|
28
19
|
constructor(name: string, value: Value);
|
|
@@ -57,5 +48,14 @@ export type ReactiveState<Value> = {
|
|
|
57
48
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
58
49
|
value: Value;
|
|
59
50
|
};
|
|
51
|
+
declare class Subscription<Value> {
|
|
52
|
+
state: ReactiveState<Value>;
|
|
53
|
+
callback: GenericCallback;
|
|
54
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Unsubscribe from changes
|
|
58
|
+
*/
|
|
59
|
+
export type Unsubscribe = () => void;
|
|
60
60
|
|
|
61
61
|
export {};
|
|
@@ -14,15 +14,6 @@ declare class Computed<Value> extends Reactive<Value> {
|
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
-
declare class Subscription<Value> {
|
|
18
|
-
state: ReactiveState<Value>;
|
|
19
|
-
callback: GenericCallback;
|
|
20
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Unsubscribe from changes
|
|
24
|
-
*/
|
|
25
|
-
export type Unsubscribe = () => void;
|
|
26
17
|
declare abstract class Reactive<Value> {
|
|
27
18
|
protected readonly state: ReactiveState<Value>;
|
|
28
19
|
constructor(name: string, value: Value);
|
|
@@ -57,6 +48,15 @@ export type ReactiveState<Value> = {
|
|
|
57
48
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
58
49
|
value: Value;
|
|
59
50
|
};
|
|
51
|
+
declare class Subscription<Value> {
|
|
52
|
+
state: ReactiveState<Value>;
|
|
53
|
+
callback: GenericCallback;
|
|
54
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Unsubscribe from changes
|
|
58
|
+
*/
|
|
59
|
+
export type Unsubscribe = () => void;
|
|
60
60
|
export declare class Signal<Value> extends Reactive<Value> {
|
|
61
61
|
constructor(value: Value);
|
|
62
62
|
/**
|
|
File without changes
|