@oscarpalmer/mora 0.10.0 → 0.11.1
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/computed.cjs +15 -40
- package/dist/computed.js +13 -38
- package/dist/index.cjs +1 -0
- package/dist/index.js +2 -1
- package/dist/is.cjs +4 -0
- package/dist/is.js +4 -0
- package/dist/mora.full.js +53 -69
- package/dist/reactive.cjs +39 -0
- package/dist/reactive.js +39 -0
- package/dist/signal.cjs +6 -36
- package/dist/signal.js +4 -34
- package/package.json +1 -1
- package/src/batch.ts +1 -1
- package/src/computed.ts +20 -60
- package/src/index.ts +1 -1
- package/src/is.ts +5 -0
- package/src/reactive.ts +53 -0
- package/src/signal.ts +7 -54
- package/src/subscription.ts +12 -10
- package/types/batch.d.cts +15 -17
- package/types/batch.d.ts +1 -1
- package/types/computed.d.cts +22 -19
- package/types/computed.d.ts +8 -24
- package/types/index.d.cts +25 -21
- package/types/index.d.ts +1 -1
- package/types/is.d.cts +23 -19
- package/types/is.d.ts +2 -0
- package/types/reactive.d.cts +49 -0
- package/types/reactive.d.ts +25 -0
- package/types/signal.d.cts +18 -34
- package/types/signal.d.ts +2 -25
- package/types/subscription.d.cts +16 -18
- package/types/subscription.d.ts +9 -7
package/types/is.d.cts
CHANGED
|
@@ -6,14 +6,17 @@ declare class Effect {
|
|
|
6
6
|
private readonly state;
|
|
7
7
|
constructor(callback: GenericCallback);
|
|
8
8
|
}
|
|
9
|
-
declare class Computed<Value> {
|
|
10
|
-
private readonly
|
|
11
|
-
private readonly state;
|
|
9
|
+
declare class Computed<Value> extends Reactive<Value> {
|
|
10
|
+
private readonly effect;
|
|
12
11
|
constructor(callback: () => Value);
|
|
13
12
|
/**
|
|
14
13
|
* Get the value
|
|
15
14
|
*/
|
|
16
15
|
get(): Value;
|
|
16
|
+
}
|
|
17
|
+
declare abstract class Reactive<Value> {
|
|
18
|
+
protected readonly state: ReactiveState<Value>;
|
|
19
|
+
constructor(name: string, value: Value);
|
|
17
20
|
/**
|
|
18
21
|
* Get the value _(without reactivity)_
|
|
19
22
|
*/
|
|
@@ -27,36 +30,36 @@ declare class Computed<Value> {
|
|
|
27
30
|
*/
|
|
28
31
|
unsubscribe(callback: (value: Value) => void): void;
|
|
29
32
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
export type ReactiveState<Value> = {
|
|
34
|
+
computeds: Set<Computed<unknown>>;
|
|
35
|
+
effects: Set<Effect>;
|
|
36
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
37
|
+
value: Value;
|
|
38
|
+
};
|
|
39
|
+
declare class Subscription<Value> {
|
|
40
|
+
state: ReactiveState<Value>;
|
|
41
|
+
callback: GenericCallback;
|
|
42
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Unsubscribe from changes
|
|
46
|
+
*/
|
|
47
|
+
export type Unsubscribe = () => void;
|
|
48
|
+
declare class Signal<Value> extends Reactive<Value> {
|
|
33
49
|
constructor(value: Value);
|
|
34
50
|
/**
|
|
35
51
|
* Get the value
|
|
36
52
|
*/
|
|
37
53
|
get(): Value;
|
|
38
|
-
/**
|
|
39
|
-
* Get the value _(without reactivity)_
|
|
40
|
-
*/
|
|
41
|
-
peek(): Value;
|
|
42
54
|
/**
|
|
43
55
|
* Set the value
|
|
44
56
|
*/
|
|
45
57
|
set(value: Value): void;
|
|
46
|
-
/**
|
|
47
|
-
* Subscribe to changes
|
|
48
|
-
*/
|
|
49
|
-
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
50
|
-
/**
|
|
51
|
-
* Unsubscribe from changes
|
|
52
|
-
*/
|
|
53
|
-
unsubscribe(callback: (value: Value) => void): void;
|
|
54
58
|
/**
|
|
55
59
|
* Update the value
|
|
56
60
|
*/
|
|
57
61
|
update(callback: (value: Value) => Value): void;
|
|
58
62
|
}
|
|
59
|
-
export type Unsubscribe = () => void;
|
|
60
63
|
/**
|
|
61
64
|
* Is the value a computed signal?
|
|
62
65
|
*/
|
|
@@ -65,6 +68,7 @@ export declare function isComputed(value: unknown): value is Computed<unknown>;
|
|
|
65
68
|
* Is the value an effect?
|
|
66
69
|
*/
|
|
67
70
|
export declare function isEffect(value: unknown): value is Effect;
|
|
71
|
+
export declare function isReactive(value: unknown): value is Reactive<unknown>;
|
|
68
72
|
/**
|
|
69
73
|
* Is the value a signal?
|
|
70
74
|
*/
|
package/types/is.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Computed } from './computed';
|
|
2
2
|
import type { Effect } from './effect';
|
|
3
|
+
import type { Reactive } from './reactive';
|
|
3
4
|
import type { Signal } from './signal';
|
|
4
5
|
/**
|
|
5
6
|
* Is the value a computed signal?
|
|
@@ -9,6 +10,7 @@ export declare function isComputed(value: unknown): value is Computed<unknown>;
|
|
|
9
10
|
* Is the value an effect?
|
|
10
11
|
*/
|
|
11
12
|
export declare function isEffect(value: unknown): value is Effect;
|
|
13
|
+
export declare function isReactive(value: unknown): value is Reactive<unknown>;
|
|
12
14
|
/**
|
|
13
15
|
* Is the value a signal?
|
|
14
16
|
*/
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
export type GenericCallback = (...args: any[]) => any;
|
|
4
|
+
declare class Effect {
|
|
5
|
+
private readonly $mora;
|
|
6
|
+
private readonly state;
|
|
7
|
+
constructor(callback: GenericCallback);
|
|
8
|
+
}
|
|
9
|
+
declare class Computed<Value> extends Reactive<Value> {
|
|
10
|
+
private readonly effect;
|
|
11
|
+
constructor(callback: () => Value);
|
|
12
|
+
/**
|
|
13
|
+
* Get the value
|
|
14
|
+
*/
|
|
15
|
+
get(): Value;
|
|
16
|
+
}
|
|
17
|
+
export declare abstract class Reactive<Value> {
|
|
18
|
+
protected readonly state: ReactiveState<Value>;
|
|
19
|
+
constructor(name: string, value: Value);
|
|
20
|
+
/**
|
|
21
|
+
* Get the value _(without reactivity)_
|
|
22
|
+
*/
|
|
23
|
+
peek(): Value;
|
|
24
|
+
/**
|
|
25
|
+
* Subscribe to changes
|
|
26
|
+
*/
|
|
27
|
+
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
28
|
+
/**
|
|
29
|
+
* Unsubscribe from changes
|
|
30
|
+
*/
|
|
31
|
+
unsubscribe(callback: (value: Value) => void): void;
|
|
32
|
+
}
|
|
33
|
+
export type ReactiveState<Value> = {
|
|
34
|
+
computeds: Set<Computed<unknown>>;
|
|
35
|
+
effects: Set<Effect>;
|
|
36
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
37
|
+
value: Value;
|
|
38
|
+
};
|
|
39
|
+
declare class Subscription<Value> {
|
|
40
|
+
state: ReactiveState<Value>;
|
|
41
|
+
callback: GenericCallback;
|
|
42
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Unsubscribe from changes
|
|
46
|
+
*/
|
|
47
|
+
export type Unsubscribe = () => void;
|
|
48
|
+
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Computed } from './computed';
|
|
2
|
+
import type { Effect } from './effect';
|
|
3
|
+
import { type Subscription, type Unsubscribe } from './subscription';
|
|
4
|
+
export declare abstract class Reactive<Value> {
|
|
5
|
+
protected readonly state: ReactiveState<Value>;
|
|
6
|
+
constructor(name: string, value: Value);
|
|
7
|
+
/**
|
|
8
|
+
* Get the value _(without reactivity)_
|
|
9
|
+
*/
|
|
10
|
+
peek(): Value;
|
|
11
|
+
/**
|
|
12
|
+
* Subscribe to changes
|
|
13
|
+
*/
|
|
14
|
+
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
15
|
+
/**
|
|
16
|
+
* Unsubscribe from changes
|
|
17
|
+
*/
|
|
18
|
+
unsubscribe(callback: (value: Value) => void): void;
|
|
19
|
+
}
|
|
20
|
+
export type ReactiveState<Value> = {
|
|
21
|
+
computeds: Set<Computed<unknown>>;
|
|
22
|
+
effects: Set<Effect>;
|
|
23
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
24
|
+
value: Value;
|
|
25
|
+
};
|
package/types/signal.d.cts
CHANGED
|
@@ -6,22 +6,17 @@ declare class Effect {
|
|
|
6
6
|
private readonly state;
|
|
7
7
|
constructor(callback: GenericCallback);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
dirty: boolean;
|
|
12
|
-
effect: Effect;
|
|
13
|
-
effects: Set<Effect>;
|
|
14
|
-
subscriptions: Map<GenericCallback, Subscription>;
|
|
15
|
-
value: Value;
|
|
16
|
-
};
|
|
17
|
-
declare class Computed<Value> {
|
|
18
|
-
private readonly $mora;
|
|
19
|
-
private readonly state;
|
|
9
|
+
declare class Computed<Value> extends Reactive<Value> {
|
|
10
|
+
private readonly effect;
|
|
20
11
|
constructor(callback: () => Value);
|
|
21
12
|
/**
|
|
22
13
|
* Get the value
|
|
23
14
|
*/
|
|
24
15
|
get(): Value;
|
|
16
|
+
}
|
|
17
|
+
declare abstract class Reactive<Value> {
|
|
18
|
+
protected readonly state: ReactiveState<Value>;
|
|
19
|
+
constructor(name: string, value: Value);
|
|
25
20
|
/**
|
|
26
21
|
* Get the value _(without reactivity)_
|
|
27
22
|
*/
|
|
@@ -35,47 +30,36 @@ declare class Computed<Value> {
|
|
|
35
30
|
*/
|
|
36
31
|
unsubscribe(callback: (value: Value) => void): void;
|
|
37
32
|
}
|
|
38
|
-
export type
|
|
33
|
+
export type ReactiveState<Value> = {
|
|
39
34
|
computeds: Set<Computed<unknown>>;
|
|
40
35
|
effects: Set<Effect>;
|
|
41
|
-
subscriptions: Map<
|
|
36
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
42
37
|
value: Value;
|
|
43
38
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
declare class Subscription<Value> {
|
|
40
|
+
state: ReactiveState<Value>;
|
|
41
|
+
callback: GenericCallback;
|
|
42
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Unsubscribe from changes
|
|
46
|
+
*/
|
|
47
|
+
export type Unsubscribe = () => void;
|
|
48
|
+
export declare class Signal<Value> extends Reactive<Value> {
|
|
47
49
|
constructor(value: Value);
|
|
48
50
|
/**
|
|
49
51
|
* Get the value
|
|
50
52
|
*/
|
|
51
53
|
get(): Value;
|
|
52
|
-
/**
|
|
53
|
-
* Get the value _(without reactivity)_
|
|
54
|
-
*/
|
|
55
|
-
peek(): Value;
|
|
56
54
|
/**
|
|
57
55
|
* Set the value
|
|
58
56
|
*/
|
|
59
57
|
set(value: Value): void;
|
|
60
|
-
/**
|
|
61
|
-
* Subscribe to changes
|
|
62
|
-
*/
|
|
63
|
-
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
64
|
-
/**
|
|
65
|
-
* Unsubscribe from changes
|
|
66
|
-
*/
|
|
67
|
-
unsubscribe(callback: (value: Value) => void): void;
|
|
68
58
|
/**
|
|
69
59
|
* Update the value
|
|
70
60
|
*/
|
|
71
61
|
update(callback: (value: Value) => Value): void;
|
|
72
62
|
}
|
|
73
63
|
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
74
|
-
declare class Subscription {
|
|
75
|
-
state: ComputedState<unknown> | SignalState<unknown>;
|
|
76
|
-
callback: GenericCallback;
|
|
77
|
-
constructor(state: ComputedState<unknown> | SignalState<unknown>, callback: GenericCallback);
|
|
78
|
-
}
|
|
79
|
-
export type Unsubscribe = () => void;
|
|
80
64
|
|
|
81
65
|
export {};
|
package/types/signal.d.ts
CHANGED
|
@@ -1,37 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { type Effect } from './effect';
|
|
4
|
-
import { type Subscription, type Unsubscribe } from './subscription';
|
|
5
|
-
export type SignalState<Value> = {
|
|
6
|
-
computeds: Set<Computed<unknown>>;
|
|
7
|
-
effects: Set<Effect>;
|
|
8
|
-
subscriptions: Map<GenericCallback, Subscription>;
|
|
9
|
-
value: Value;
|
|
10
|
-
};
|
|
11
|
-
export declare class Signal<Value> {
|
|
12
|
-
private readonly $mora;
|
|
13
|
-
private readonly state;
|
|
1
|
+
import { Reactive } from './reactive';
|
|
2
|
+
export declare class Signal<Value> extends Reactive<Value> {
|
|
14
3
|
constructor(value: Value);
|
|
15
4
|
/**
|
|
16
5
|
* Get the value
|
|
17
6
|
*/
|
|
18
7
|
get(): Value;
|
|
19
|
-
/**
|
|
20
|
-
* Get the value _(without reactivity)_
|
|
21
|
-
*/
|
|
22
|
-
peek(): Value;
|
|
23
8
|
/**
|
|
24
9
|
* Set the value
|
|
25
10
|
*/
|
|
26
11
|
set(value: Value): void;
|
|
27
|
-
/**
|
|
28
|
-
* Subscribe to changes
|
|
29
|
-
*/
|
|
30
|
-
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
31
|
-
/**
|
|
32
|
-
* Unsubscribe from changes
|
|
33
|
-
*/
|
|
34
|
-
unsubscribe(callback: (value: Value) => void): void;
|
|
35
12
|
/**
|
|
36
13
|
* Update the value
|
|
37
14
|
*/
|
package/types/subscription.d.cts
CHANGED
|
@@ -6,22 +6,17 @@ declare class Effect {
|
|
|
6
6
|
private readonly state;
|
|
7
7
|
constructor(callback: GenericCallback);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
dirty: boolean;
|
|
12
|
-
effect: Effect;
|
|
13
|
-
effects: Set<Effect>;
|
|
14
|
-
subscriptions: Map<GenericCallback, Subscription>;
|
|
15
|
-
value: Value;
|
|
16
|
-
};
|
|
17
|
-
declare class Computed<Value> {
|
|
18
|
-
private readonly $mora;
|
|
19
|
-
private readonly state;
|
|
9
|
+
declare class Computed<Value> extends Reactive<Value> {
|
|
10
|
+
private readonly effect;
|
|
20
11
|
constructor(callback: () => Value);
|
|
21
12
|
/**
|
|
22
13
|
* Get the value
|
|
23
14
|
*/
|
|
24
15
|
get(): Value;
|
|
16
|
+
}
|
|
17
|
+
declare abstract class Reactive<Value> {
|
|
18
|
+
protected readonly state: ReactiveState<Value>;
|
|
19
|
+
constructor(name: string, value: Value);
|
|
25
20
|
/**
|
|
26
21
|
* Get the value _(without reactivity)_
|
|
27
22
|
*/
|
|
@@ -35,20 +30,23 @@ declare class Computed<Value> {
|
|
|
35
30
|
*/
|
|
36
31
|
unsubscribe(callback: (value: Value) => void): void;
|
|
37
32
|
}
|
|
38
|
-
export type
|
|
33
|
+
export type ReactiveState<Value> = {
|
|
39
34
|
computeds: Set<Computed<unknown>>;
|
|
40
35
|
effects: Set<Effect>;
|
|
41
|
-
subscriptions: Map<
|
|
36
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
42
37
|
value: Value;
|
|
43
38
|
};
|
|
44
|
-
export declare class Subscription {
|
|
45
|
-
state:
|
|
39
|
+
export declare class Subscription<Value> {
|
|
40
|
+
state: ReactiveState<Value>;
|
|
46
41
|
callback: GenericCallback;
|
|
47
|
-
constructor(state:
|
|
42
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
48
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Unsubscribe from changes
|
|
46
|
+
*/
|
|
49
47
|
export type Unsubscribe = () => void;
|
|
50
48
|
export declare function noop(): void;
|
|
51
|
-
export declare function subscribe(state:
|
|
52
|
-
export declare function unsubscribe(state:
|
|
49
|
+
export declare function subscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): Unsubscribe;
|
|
50
|
+
export declare function unsubscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): void;
|
|
53
51
|
|
|
54
52
|
export {};
|
package/types/subscription.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { GenericCallback } from '@oscarpalmer/atoms/models';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
state: ComputedState<unknown> | SignalState<unknown>;
|
|
2
|
+
import type { ReactiveState } from './reactive';
|
|
3
|
+
export declare class Subscription<Value> {
|
|
4
|
+
state: ReactiveState<Value>;
|
|
6
5
|
callback: GenericCallback;
|
|
7
|
-
constructor(state:
|
|
6
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
8
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Unsubscribe from changes
|
|
10
|
+
*/
|
|
9
11
|
export type Unsubscribe = () => void;
|
|
10
12
|
export declare function noop(): void;
|
|
11
|
-
export declare function subscribe(state:
|
|
12
|
-
export declare function unsubscribe(state:
|
|
13
|
+
export declare function subscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): Unsubscribe;
|
|
14
|
+
export declare function unsubscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): void;
|