@oscarpalmer/mora 0.13.0 → 0.15.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 +200 -140
- package/dist/value/array.cjs +161 -0
- package/dist/{array.js → value/array.js} +62 -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} +75 -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} +85 -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 +74 -38
- package/types/index.d.ts +5 -5
- package/types/subscription.d.cts +12 -12
- package/types/subscription.d.ts +1 -1
- package/types/{array.d.cts → value/array.d.cts} +41 -9
- package/types/value/array.d.ts +74 -0
- package/types/{computed.d.ts → value/computed.d.ts} +1 -1
- package/types/{reactive.d.ts → value/reactive.d.ts} +2 -2
- package/dist/array.cjs +0 -130
- 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/array.d.ts +0 -41
- package/types/is.d.ts +0 -17
- 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
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {Effect} from './effect';
|
|
1
|
+
import type {Effect} from '../effect';
|
|
3
2
|
import {
|
|
4
3
|
type Subscription,
|
|
5
4
|
type Unsubscribe,
|
|
6
5
|
subscribe,
|
|
7
6
|
unsubscribe,
|
|
8
|
-
} from '
|
|
7
|
+
} from '../subscription';
|
|
8
|
+
import type {Computed} from './computed';
|
|
9
9
|
|
|
10
10
|
export abstract class Reactive<Value> {
|
|
11
11
|
protected readonly state: ReactiveState<Value> = {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import {signalName} from '../helpers/is';
|
|
2
|
+
import {getValue, setValue} from '../helpers/value';
|
|
1
3
|
import {Reactive} from './reactive';
|
|
2
|
-
import {getValue, setValue} from './value';
|
|
3
4
|
|
|
4
5
|
export class Signal<Value> extends Reactive<Value> {
|
|
5
6
|
constructor(value: Value) {
|
|
6
|
-
super(
|
|
7
|
+
super(signalName, value);
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
/**
|
package/types/batch.d.cts
CHANGED
|
@@ -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 function flushEffects(): void;
|
|
61
61
|
/**
|
|
62
62
|
* Start batching effects _(use `stopBatch` to flush and run batched effects)_
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
* @inheritdoc
|
|
14
|
+
*/
|
|
15
|
+
get(): Value;
|
|
16
|
+
}
|
|
17
|
+
declare abstract class Reactive<Value> {
|
|
18
|
+
protected readonly state: ReactiveState<Value>;
|
|
19
|
+
constructor(name: string, value: Value);
|
|
20
|
+
/**
|
|
21
|
+
* Get the value
|
|
22
|
+
*/
|
|
23
|
+
abstract get(): Value;
|
|
24
|
+
/**
|
|
25
|
+
* Get the value _(without reactivity)_
|
|
26
|
+
*/
|
|
27
|
+
peek(): Value;
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe to changes
|
|
30
|
+
*/
|
|
31
|
+
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
32
|
+
/**
|
|
33
|
+
* JSON representation of the value
|
|
34
|
+
*/
|
|
35
|
+
toJSON(): Value;
|
|
36
|
+
/**
|
|
37
|
+
* String representation of the value
|
|
38
|
+
*/
|
|
39
|
+
toString(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Unsubscribe from changes
|
|
42
|
+
*/
|
|
43
|
+
unsubscribe(callback: (value: Value) => void): void;
|
|
44
|
+
}
|
|
45
|
+
export type ReactiveState<Value> = {
|
|
46
|
+
computeds: Set<Computed<unknown>>;
|
|
47
|
+
effects: Set<Effect>;
|
|
48
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
49
|
+
value: Value;
|
|
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
|
+
export declare function emitArrayChanges(first: unknown[], second: unknown[]): boolean;
|
|
61
|
+
export declare function emitValue<Value>(state: ReactiveState<Value>): void;
|
|
62
|
+
|
|
63
|
+
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,83 @@ 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
|
+
declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
61
|
+
#private;
|
|
62
|
+
/**
|
|
63
|
+
* The length of the array
|
|
64
|
+
*/
|
|
65
|
+
get length(): number;
|
|
66
|
+
/**
|
|
67
|
+
* Set the length of the array
|
|
68
|
+
*/
|
|
69
|
+
set length(value: number);
|
|
70
|
+
constructor(value: Item[]);
|
|
71
|
+
/**
|
|
72
|
+
* Get an indexed item
|
|
73
|
+
*/
|
|
74
|
+
at(index: number): Item | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* @inheritdoc
|
|
77
|
+
*/
|
|
78
|
+
get(): Item[];
|
|
79
|
+
/**
|
|
80
|
+
* Create a computed, filtered array
|
|
81
|
+
*/
|
|
82
|
+
filter(callback: (item: Item, index: number, array: Item[]) => boolean): Computed<Item[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Create a computed, mapped array
|
|
85
|
+
*/
|
|
86
|
+
map<Mapped>(callback: (item: Item, index: number, array: Item[]) => Mapped): Computed<Mapped[]>;
|
|
87
|
+
/**
|
|
88
|
+
* @inheritdoc
|
|
89
|
+
*/
|
|
90
|
+
peek(): Item[];
|
|
91
|
+
/**
|
|
92
|
+
* Get the length of the array _(without reactivity)_
|
|
93
|
+
*/
|
|
94
|
+
peek(length: true): number;
|
|
95
|
+
/**
|
|
96
|
+
* Remove and return the last item of the array
|
|
97
|
+
*/
|
|
98
|
+
pop(): Item | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Add items to the end of the array
|
|
101
|
+
*/
|
|
102
|
+
push(...items: Item[]): number;
|
|
103
|
+
/**
|
|
104
|
+
* Set the value
|
|
105
|
+
*/
|
|
106
|
+
set(value: Item[]): void;
|
|
107
|
+
/**
|
|
108
|
+
* Set the value at an index
|
|
109
|
+
*/
|
|
110
|
+
set(index: number, value: Item): void;
|
|
111
|
+
/**
|
|
112
|
+
* Set the length of the array
|
|
113
|
+
*/
|
|
114
|
+
set(property: "length", value: number): void;
|
|
115
|
+
/**
|
|
116
|
+
* Remove and return the first item of the array
|
|
117
|
+
*/
|
|
118
|
+
shift(): Item | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* Remove and return items from the array _(and optionally add new items)_
|
|
121
|
+
*/
|
|
122
|
+
splice(from: number, to?: number, ...items: Item[]): Item[];
|
|
123
|
+
/**
|
|
124
|
+
* Add items to the beginning of the array
|
|
125
|
+
*/
|
|
126
|
+
unshift(...items: Item[]): number;
|
|
127
|
+
}
|
|
60
128
|
declare class Signal<Value> extends Reactive<Value> {
|
|
61
129
|
constructor(value: Value);
|
|
62
130
|
/**
|
|
@@ -72,6 +140,10 @@ declare class Signal<Value> extends Reactive<Value> {
|
|
|
72
140
|
*/
|
|
73
141
|
update(callback: (value: Value) => Value): void;
|
|
74
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Is the value a reactive array?
|
|
145
|
+
*/
|
|
146
|
+
export declare function isArray(value: unknown): value is ReactiveArray<unknown>;
|
|
75
147
|
/**
|
|
76
148
|
* Is the value a computed signal?
|
|
77
149
|
*/
|
|
@@ -85,5 +157,9 @@ export declare function isReactive(value: unknown): value is Reactive<unknown>;
|
|
|
85
157
|
* Is the value a signal?
|
|
86
158
|
*/
|
|
87
159
|
export declare function isSignal(value: unknown): value is Signal<unknown>;
|
|
160
|
+
export declare const arrayName = "array";
|
|
161
|
+
export declare const computedName = "computed";
|
|
162
|
+
export declare const effectName = "effect";
|
|
163
|
+
export declare const signalName = "signal";
|
|
88
164
|
|
|
89
165
|
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Effect } from '../effect';
|
|
2
|
+
import type { ReactiveArray } from '../value/array';
|
|
3
|
+
import type { Computed } from '../value/computed';
|
|
4
|
+
import type { Reactive } from '../value/reactive';
|
|
5
|
+
import { type Signal } from '../value/signal';
|
|
6
|
+
/**
|
|
7
|
+
* Is the value a reactive array?
|
|
8
|
+
*/
|
|
9
|
+
export declare function isArray(value: unknown): value is ReactiveArray<unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Is the value a computed signal?
|
|
12
|
+
*/
|
|
13
|
+
export declare function isComputed(value: unknown): value is Computed<unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Is the value an effect?
|
|
16
|
+
*/
|
|
17
|
+
export declare function isEffect(value: unknown): value is Effect;
|
|
18
|
+
export declare function isReactive(value: unknown): value is Reactive<unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Is the value a signal?
|
|
21
|
+
*/
|
|
22
|
+
export declare function isSignal(value: unknown): value is Signal<unknown>;
|
|
23
|
+
export declare const arrayName = "array";
|
|
24
|
+
export declare const computedName = "computed";
|
|
25
|
+
export declare const effectName = "effect";
|
|
26
|
+
export declare const signalName = "signal";
|
|
@@ -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,7 +48,15 @@ export type ReactiveState<Value> = {
|
|
|
57
48
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
58
49
|
value: Value;
|
|
59
50
|
};
|
|
60
|
-
|
|
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;
|
|
61
60
|
export declare function getValue<Value>(state: ReactiveState<Value>): Value;
|
|
62
61
|
export declare function setValue<Value>(state: ReactiveState<Value>, value: Value): void;
|
|
63
62
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ReactiveState } from '
|
|
2
|
-
export declare function emitValue<Value>(state: ReactiveState<Value>): void;
|
|
1
|
+
import type { ReactiveState } from '../value/reactive';
|
|
3
2
|
export declare function getValue<Value>(state: ReactiveState<Value>): Value;
|
|
4
3
|
export declare function setValue<Value>(state: ReactiveState<Value>, value: Value): void;
|
package/types/index.d.cts
CHANGED
|
@@ -22,15 +22,6 @@ export declare class Computed<Value> extends Reactive<Value> {
|
|
|
22
22
|
* Create a computed value
|
|
23
23
|
*/
|
|
24
24
|
export declare function computed<Value>(callback: () => Value): Computed<Value>;
|
|
25
|
-
declare class Subscription<Value> {
|
|
26
|
-
state: ReactiveState<Value>;
|
|
27
|
-
callback: GenericCallback;
|
|
28
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Unsubscribe from changes
|
|
32
|
-
*/
|
|
33
|
-
export type Unsubscribe = () => void;
|
|
34
25
|
export declare abstract class Reactive<Value> {
|
|
35
26
|
protected readonly state: ReactiveState<Value>;
|
|
36
27
|
constructor(name: string, value: Value);
|
|
@@ -65,38 +56,23 @@ export type ReactiveState<Value> = {
|
|
|
65
56
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
66
57
|
value: Value;
|
|
67
58
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*/
|
|
73
|
-
get(): Value;
|
|
74
|
-
/**
|
|
75
|
-
* Set the value
|
|
76
|
-
*/
|
|
77
|
-
set(value: Value): void;
|
|
78
|
-
/**
|
|
79
|
-
* Update the value
|
|
80
|
-
*/
|
|
81
|
-
update(callback: (value: Value) => Value): void;
|
|
59
|
+
declare class Subscription<Value> {
|
|
60
|
+
state: ReactiveState<Value>;
|
|
61
|
+
callback: GenericCallback;
|
|
62
|
+
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
82
63
|
}
|
|
83
64
|
/**
|
|
84
|
-
*
|
|
85
|
-
*/
|
|
86
|
-
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
87
|
-
/**
|
|
88
|
-
* Is the value a computed signal?
|
|
65
|
+
* Unsubscribe from changes
|
|
89
66
|
*/
|
|
90
|
-
export
|
|
67
|
+
export type Unsubscribe = () => void;
|
|
91
68
|
/**
|
|
92
|
-
*
|
|
69
|
+
* Start batching effects _(use `stopBatch` to flush and run batched effects)_
|
|
93
70
|
*/
|
|
94
|
-
export declare function
|
|
95
|
-
export declare function isReactive(value: unknown): value is Reactive<unknown>;
|
|
71
|
+
export declare function startBatch(): void;
|
|
96
72
|
/**
|
|
97
|
-
*
|
|
73
|
+
* Stop batching effects and flush _(run)_ them
|
|
98
74
|
*/
|
|
99
|
-
export declare function
|
|
75
|
+
export declare function stopBatch(): void;
|
|
100
76
|
export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
101
77
|
#private;
|
|
102
78
|
/**
|
|
@@ -108,10 +84,22 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
108
84
|
*/
|
|
109
85
|
set length(value: number);
|
|
110
86
|
constructor(value: Item[]);
|
|
87
|
+
/**
|
|
88
|
+
* Get an indexed item
|
|
89
|
+
*/
|
|
90
|
+
at(index: number): Item | undefined;
|
|
111
91
|
/**
|
|
112
92
|
* @inheritdoc
|
|
113
93
|
*/
|
|
114
94
|
get(): Item[];
|
|
95
|
+
/**
|
|
96
|
+
* Create a computed, filtered array
|
|
97
|
+
*/
|
|
98
|
+
filter(callback: (item: Item, index: number, array: Item[]) => boolean): Computed<Item[]>;
|
|
99
|
+
/**
|
|
100
|
+
* Create a computed, mapped array
|
|
101
|
+
*/
|
|
102
|
+
map<Mapped>(callback: (item: Item, index: number, array: Item[]) => Mapped): Computed<Mapped[]>;
|
|
115
103
|
/**
|
|
116
104
|
* @inheritdoc
|
|
117
105
|
*/
|
|
@@ -120,6 +108,14 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
120
108
|
* Get the length of the array _(without reactivity)_
|
|
121
109
|
*/
|
|
122
110
|
peek(length: true): number;
|
|
111
|
+
/**
|
|
112
|
+
* Remove and return the last item of the array
|
|
113
|
+
*/
|
|
114
|
+
pop(): Item | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* Add items to the end of the array
|
|
117
|
+
*/
|
|
118
|
+
push(...items: Item[]): number;
|
|
123
119
|
/**
|
|
124
120
|
* Set the value
|
|
125
121
|
*/
|
|
@@ -132,18 +128,58 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
132
128
|
* Set the length of the array
|
|
133
129
|
*/
|
|
134
130
|
set(property: "length", value: number): void;
|
|
131
|
+
/**
|
|
132
|
+
* Remove and return the first item of the array
|
|
133
|
+
*/
|
|
134
|
+
shift(): Item | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Remove and return items from the array _(and optionally add new items)_
|
|
137
|
+
*/
|
|
138
|
+
splice(from: number, to?: number, ...items: Item[]): Item[];
|
|
139
|
+
/**
|
|
140
|
+
* Add items to the beginning of the array
|
|
141
|
+
*/
|
|
142
|
+
unshift(...items: Item[]): number;
|
|
135
143
|
}
|
|
136
144
|
/**
|
|
137
145
|
* Create a reactive array
|
|
138
146
|
*/
|
|
139
147
|
export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
|
|
148
|
+
export declare class Signal<Value> extends Reactive<Value> {
|
|
149
|
+
constructor(value: Value);
|
|
150
|
+
/**
|
|
151
|
+
* @inheritdoc
|
|
152
|
+
*/
|
|
153
|
+
get(): Value;
|
|
154
|
+
/**
|
|
155
|
+
* Set the value
|
|
156
|
+
*/
|
|
157
|
+
set(value: Value): void;
|
|
158
|
+
/**
|
|
159
|
+
* Update the value
|
|
160
|
+
*/
|
|
161
|
+
update(callback: (value: Value) => Value): void;
|
|
162
|
+
}
|
|
140
163
|
/**
|
|
141
|
-
*
|
|
164
|
+
* Create a reactive value
|
|
142
165
|
*/
|
|
143
|
-
export declare function
|
|
166
|
+
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
144
167
|
/**
|
|
145
|
-
*
|
|
168
|
+
* Is the value a reactive array?
|
|
146
169
|
*/
|
|
147
|
-
export declare function
|
|
170
|
+
export declare function isArray(value: unknown): value is ReactiveArray<unknown>;
|
|
171
|
+
/**
|
|
172
|
+
* Is the value a computed signal?
|
|
173
|
+
*/
|
|
174
|
+
export declare function isComputed(value: unknown): value is Computed<unknown>;
|
|
175
|
+
/**
|
|
176
|
+
* Is the value an effect?
|
|
177
|
+
*/
|
|
178
|
+
export declare function isEffect(value: unknown): value is Effect;
|
|
179
|
+
export declare function isReactive(value: unknown): value is Reactive<unknown>;
|
|
180
|
+
/**
|
|
181
|
+
* Is the value a signal?
|
|
182
|
+
*/
|
|
183
|
+
export declare function isSignal(value: unknown): value is Signal<unknown>;
|
|
148
184
|
|
|
149
185
|
export {};
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { array, type ReactiveArray } from './array';
|
|
2
1
|
export { startBatch, stopBatch } from './batch';
|
|
3
|
-
export { computed, type Computed } from './computed';
|
|
4
2
|
export { effect, type Effect } from './effect';
|
|
5
|
-
export { isComputed, isEffect, isReactive, isSignal } from './is';
|
|
6
|
-
export type
|
|
7
|
-
export {
|
|
3
|
+
export { isArray, isComputed, isEffect, isReactive, isSignal, } from './helpers/is';
|
|
4
|
+
export { array, type ReactiveArray } from './value/array';
|
|
5
|
+
export { computed, type Computed } from './value/computed';
|
|
6
|
+
export type { Reactive } from './value/reactive';
|
|
7
|
+
export { signal, type Signal } from './value/signal';
|
package/types/subscription.d.cts
CHANGED
|
@@ -14,18 +14,6 @@ declare class Computed<Value> extends Reactive<Value> {
|
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
-
export 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
|
-
export declare function noop(): void;
|
|
27
|
-
export declare function subscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): Unsubscribe;
|
|
28
|
-
export declare function unsubscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): void;
|
|
29
17
|
declare abstract class Reactive<Value> {
|
|
30
18
|
protected readonly state: ReactiveState<Value>;
|
|
31
19
|
constructor(name: string, value: Value);
|
|
@@ -60,5 +48,17 @@ export type ReactiveState<Value> = {
|
|
|
60
48
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
61
49
|
value: Value;
|
|
62
50
|
};
|
|
51
|
+
export 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
|
+
export declare function noop(): void;
|
|
61
|
+
export declare function subscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): Unsubscribe;
|
|
62
|
+
export declare function unsubscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): void;
|
|
63
63
|
|
|
64
64
|
export {};
|
package/types/subscription.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GenericCallback } from '@oscarpalmer/atoms/models';
|
|
2
|
-
import type { ReactiveState } from './reactive';
|
|
2
|
+
import type { ReactiveState } from './value/reactive';
|
|
3
3
|
export declare class Subscription<Value> {
|
|
4
4
|
state: ReactiveState<Value>;
|
|
5
5
|
callback: GenericCallback;
|
|
@@ -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
|
/**
|
|
@@ -68,10 +68,22 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
68
68
|
*/
|
|
69
69
|
set length(value: number);
|
|
70
70
|
constructor(value: Item[]);
|
|
71
|
+
/**
|
|
72
|
+
* Get an indexed item
|
|
73
|
+
*/
|
|
74
|
+
at(index: number): Item | undefined;
|
|
71
75
|
/**
|
|
72
76
|
* @inheritdoc
|
|
73
77
|
*/
|
|
74
78
|
get(): Item[];
|
|
79
|
+
/**
|
|
80
|
+
* Create a computed, filtered array
|
|
81
|
+
*/
|
|
82
|
+
filter(callback: (item: Item, index: number, array: Item[]) => boolean): Computed<Item[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Create a computed, mapped array
|
|
85
|
+
*/
|
|
86
|
+
map<Mapped>(callback: (item: Item, index: number, array: Item[]) => Mapped): Computed<Mapped[]>;
|
|
75
87
|
/**
|
|
76
88
|
* @inheritdoc
|
|
77
89
|
*/
|
|
@@ -80,6 +92,14 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
80
92
|
* Get the length of the array _(without reactivity)_
|
|
81
93
|
*/
|
|
82
94
|
peek(length: true): number;
|
|
95
|
+
/**
|
|
96
|
+
* Remove and return the last item of the array
|
|
97
|
+
*/
|
|
98
|
+
pop(): Item | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Add items to the end of the array
|
|
101
|
+
*/
|
|
102
|
+
push(...items: Item[]): number;
|
|
83
103
|
/**
|
|
84
104
|
* Set the value
|
|
85
105
|
*/
|
|
@@ -92,6 +112,18 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
|
|
|
92
112
|
* Set the length of the array
|
|
93
113
|
*/
|
|
94
114
|
set(property: "length", value: number): void;
|
|
115
|
+
/**
|
|
116
|
+
* Remove and return the first item of the array
|
|
117
|
+
*/
|
|
118
|
+
shift(): Item | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* Remove and return items from the array _(and optionally add new items)_
|
|
121
|
+
*/
|
|
122
|
+
splice(from: number, to?: number, ...items: Item[]): Item[];
|
|
123
|
+
/**
|
|
124
|
+
* Add items to the beginning of the array
|
|
125
|
+
*/
|
|
126
|
+
unshift(...items: Item[]): number;
|
|
95
127
|
}
|
|
96
128
|
/**
|
|
97
129
|
* Create a reactive array
|