@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.
Files changed (62) hide show
  1. package/dist/batch.cjs +2 -2
  2. package/dist/batch.js +1 -1
  3. package/dist/effect.cjs +2 -1
  4. package/dist/effect.js +2 -1
  5. package/dist/helpers/emit.cjs +42 -0
  6. package/dist/helpers/emit.js +42 -0
  7. package/dist/helpers/is.cjs +34 -0
  8. package/dist/helpers/is.js +34 -0
  9. package/dist/helpers/value.cjs +22 -0
  10. package/dist/helpers/value.js +22 -0
  11. package/dist/index.cjs +12 -11
  12. package/dist/index.js +5 -4
  13. package/dist/mora.full.js +200 -140
  14. package/dist/value/array.cjs +161 -0
  15. package/dist/{array.js → value/array.js} +62 -31
  16. package/dist/{computed.cjs → value/computed.cjs} +6 -5
  17. package/dist/{computed.js → value/computed.js} +4 -3
  18. package/dist/{reactive.cjs → value/reactive.cjs} +1 -1
  19. package/dist/{reactive.js → value/reactive.js} +1 -1
  20. package/dist/value/signal.cjs +33 -0
  21. package/dist/{signal.js → value/signal.js} +3 -2
  22. package/package.json +1 -1
  23. package/src/batch.ts +1 -1
  24. package/src/effect.ts +12 -11
  25. package/src/helpers/emit.ts +52 -0
  26. package/src/helpers/is.ts +56 -0
  27. package/src/helpers/value.ts +27 -0
  28. package/src/index.ts +11 -5
  29. package/src/subscription.ts +1 -1
  30. package/src/{array.ts → value/array.ts} +75 -41
  31. package/src/{computed.ts → value/computed.ts} +4 -3
  32. package/src/{reactive.ts → value/reactive.ts} +3 -3
  33. package/src/{signal.ts → value/signal.ts} +3 -2
  34. package/types/batch.d.cts +9 -9
  35. package/types/helpers/emit.d.cts +63 -0
  36. package/types/helpers/emit.d.ts +3 -0
  37. package/types/{is.d.cts → helpers/is.d.cts} +85 -9
  38. package/types/helpers/is.d.ts +26 -0
  39. package/types/{value.d.cts → helpers/value.d.cts} +9 -10
  40. package/types/{value.d.ts → helpers/value.d.ts} +1 -2
  41. package/types/index.d.cts +74 -38
  42. package/types/index.d.ts +5 -5
  43. package/types/subscription.d.cts +12 -12
  44. package/types/subscription.d.ts +1 -1
  45. package/types/{array.d.cts → value/array.d.cts} +41 -9
  46. package/types/value/array.d.ts +74 -0
  47. package/types/{computed.d.ts → value/computed.d.ts} +1 -1
  48. package/types/{reactive.d.ts → value/reactive.d.ts} +2 -2
  49. package/dist/array.cjs +0 -130
  50. package/dist/is.cjs +0 -21
  51. package/dist/is.js +0 -21
  52. package/dist/signal.cjs +0 -32
  53. package/dist/value.cjs +0 -38
  54. package/dist/value.js +0 -38
  55. package/src/is.ts +0 -39
  56. package/src/value.ts +0 -47
  57. package/types/array.d.ts +0 -41
  58. package/types/is.d.ts +0 -17
  59. package/types/{computed.d.cts → value/computed.d.cts} +9 -9
  60. package/types/{reactive.d.cts → value/reactive.d.cts} +9 -9
  61. package/types/{signal.d.cts → value/signal.d.cts} +9 -9
  62. /package/types/{signal.d.ts → value/signal.d.ts} +0 -0
@@ -1,11 +1,11 @@
1
- import type {Computed} from './computed';
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 './subscription';
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('signal', value);
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 {};
@@ -0,0 +1,3 @@
1
+ import type { ReactiveState } from '../value/reactive';
2
+ export declare function emitArrayChanges(first: unknown[], second: unknown[]): boolean;
3
+ export declare function emitValue<Value>(state: ReactiveState<Value>): void;
@@ -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
- export declare function emitValue<Value>(state: ReactiveState<Value>): void;
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 './reactive';
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
- export declare class Signal<Value> extends Reactive<Value> {
69
- constructor(value: Value);
70
- /**
71
- * @inheritdoc
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
- * Create a reactive value
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 declare function isComputed(value: unknown): value is Computed<unknown>;
67
+ export type Unsubscribe = () => void;
91
68
  /**
92
- * Is the value an effect?
69
+ * Start batching effects _(use `stopBatch` to flush and run batched effects)_
93
70
  */
94
- export declare function isEffect(value: unknown): value is Effect;
95
- export declare function isReactive(value: unknown): value is Reactive<unknown>;
71
+ export declare function startBatch(): void;
96
72
  /**
97
- * Is the value a signal?
73
+ * Stop batching effects and flush _(run)_ them
98
74
  */
99
- export declare function isSignal(value: unknown): value is Signal<unknown>;
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
- * Start batching effects _(use `stopBatch` to flush and run batched effects)_
164
+ * Create a reactive value
142
165
  */
143
- export declare function startBatch(): void;
166
+ export declare function signal<Value>(value: Value): Signal<Value>;
144
167
  /**
145
- * Stop batching effects and flush _(run)_ them
168
+ * Is the value a reactive array?
146
169
  */
147
- export declare function stopBatch(): void;
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 { Reactive } from './reactive';
7
- export { signal, type Signal } from './signal';
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';
@@ -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 {};
@@ -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