@oscarpalmer/mora 0.18.0 → 0.18.2
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/helpers/is.cjs +7 -1
- package/dist/helpers/is.js +8 -2
- package/dist/helpers/proxy.cjs +43 -0
- package/dist/helpers/proxy.js +43 -0
- package/dist/helpers/value.cjs +22 -26
- package/dist/helpers/value.js +22 -26
- package/dist/index.cjs +2 -0
- package/dist/index.js +3 -1
- package/dist/mora.full.js +127 -59
- package/dist/node_modules/@oscarpalmer/atoms/dist/internal/is.cjs +17 -0
- package/dist/node_modules/@oscarpalmer/atoms/dist/internal/is.js +17 -0
- package/dist/value/array.cjs +15 -20
- package/dist/value/array.js +16 -21
- package/dist/value/computed.cjs +5 -5
- package/dist/value/computed.js +5 -5
- package/dist/value/reactive.cjs +5 -1
- package/dist/value/reactive.js +5 -1
- package/dist/value/signal.cjs +5 -5
- package/dist/value/signal.js +6 -6
- package/dist/value/store.cjs +36 -0
- package/dist/value/store.js +36 -0
- package/package.json +1 -1
- package/src/helpers/is.ts +1 -1
- package/src/helpers/proxy.ts +0 -1
- package/types/batch.d.cts +14 -7
- package/types/helpers/is.d.cts +66 -10
- package/types/helpers/is.d.ts +4 -0
- package/types/helpers/proxy.d.cts +89 -0
- package/types/helpers/proxy.d.ts +5 -0
- package/types/helpers/value.d.cts +17 -11
- package/types/helpers/value.d.ts +3 -4
- package/types/index.d.cts +71 -13
- package/types/index.d.ts +1 -0
- package/types/subscription.d.cts +16 -9
- package/types/subscription.d.ts +4 -4
- package/types/value/array.d.cts +17 -10
- package/types/value/array.d.ts +4 -4
- package/types/value/computed.d.cts +16 -9
- package/types/value/computed.d.ts +4 -4
- package/types/value/reactive.d.cts +14 -7
- package/types/value/reactive.d.ts +11 -4
- package/types/value/signal.d.cts +16 -9
- package/types/value/signal.d.ts +3 -3
- package/types/value/store.d.cts +119 -0
- package/types/value/store.d.ts +45 -0
package/types/value/signal.d.cts
CHANGED
|
@@ -8,15 +8,15 @@ declare class Effect {
|
|
|
8
8
|
}
|
|
9
9
|
declare class Computed<Value> extends Reactive<Value> {
|
|
10
10
|
private readonly effect;
|
|
11
|
-
constructor(callback: () => Value);
|
|
11
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
12
12
|
/**
|
|
13
13
|
* @inheritdoc
|
|
14
14
|
*/
|
|
15
15
|
get(): Value;
|
|
16
16
|
}
|
|
17
|
-
declare abstract class Reactive<Value> {
|
|
18
|
-
protected readonly state: ReactiveState<Value>;
|
|
19
|
-
constructor(name: string, value: Value);
|
|
17
|
+
declare abstract class Reactive<Value, Equal = Value> {
|
|
18
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
19
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
20
20
|
/**
|
|
21
21
|
* Get the value
|
|
22
22
|
*/
|
|
@@ -42,23 +42,30 @@ declare abstract class Reactive<Value> {
|
|
|
42
42
|
*/
|
|
43
43
|
unsubscribe(callback: (value: Value) => void): void;
|
|
44
44
|
}
|
|
45
|
-
export type
|
|
45
|
+
export type ReactiveOptions<Value> = {
|
|
46
|
+
/**
|
|
47
|
+
* Method to compare values for equality
|
|
48
|
+
*/
|
|
49
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
50
|
+
};
|
|
51
|
+
export type ReactiveState<Value, Equal> = {
|
|
46
52
|
computeds: Set<Computed<unknown>>;
|
|
47
53
|
effects: Set<Effect>;
|
|
54
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
48
55
|
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
49
56
|
value: Value;
|
|
50
57
|
};
|
|
51
58
|
declare class Subscription<Value> {
|
|
52
|
-
state: ReactiveState<Value>;
|
|
59
|
+
state: ReactiveState<Value, never>;
|
|
53
60
|
callback: GenericCallback;
|
|
54
|
-
constructor(state: ReactiveState<Value>, callback: GenericCallback);
|
|
61
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
57
64
|
* Unsubscribe from changes
|
|
58
65
|
*/
|
|
59
66
|
export type Unsubscribe = () => void;
|
|
60
67
|
export declare class Signal<Value> extends Reactive<Value> {
|
|
61
|
-
constructor(value: Value);
|
|
68
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
62
69
|
/**
|
|
63
70
|
* @inheritdoc
|
|
64
71
|
*/
|
|
@@ -75,6 +82,6 @@ export declare class Signal<Value> extends Reactive<Value> {
|
|
|
75
82
|
/**
|
|
76
83
|
* Create a reactive value
|
|
77
84
|
*/
|
|
78
|
-
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
85
|
+
export declare function signal<Value>(value: Value, options?: ReactiveOptions<Value>): Signal<Value>;
|
|
79
86
|
|
|
80
87
|
export {};
|
package/types/value/signal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Reactive } from './reactive';
|
|
1
|
+
import { Reactive, type ReactiveOptions } from './reactive';
|
|
2
2
|
export declare class Signal<Value> extends Reactive<Value> {
|
|
3
|
-
constructor(value: Value);
|
|
3
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
4
4
|
/**
|
|
5
5
|
* @inheritdoc
|
|
6
6
|
*/
|
|
@@ -17,4 +17,4 @@ export declare class Signal<Value> extends Reactive<Value> {
|
|
|
17
17
|
/**
|
|
18
18
|
* Create a reactive value
|
|
19
19
|
*/
|
|
20
|
-
export declare function signal<Value>(value: Value): Signal<Value>;
|
|
20
|
+
export declare function signal<Value>(value: Value, options?: ReactiveOptions<Value>): Signal<Value>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
export type GenericCallback = (...args: any[]) => any;
|
|
4
|
+
/**
|
|
5
|
+
* A useful key type
|
|
6
|
+
*/
|
|
7
|
+
export type Key = number | string;
|
|
8
|
+
/**
|
|
9
|
+
* A generic object
|
|
10
|
+
*/
|
|
11
|
+
export type PlainObject = Record<PropertyKey, unknown>;
|
|
12
|
+
declare class Effect {
|
|
13
|
+
private readonly $mora;
|
|
14
|
+
private readonly state;
|
|
15
|
+
constructor(callback: GenericCallback);
|
|
16
|
+
}
|
|
17
|
+
declare class Computed<Value> extends Reactive<Value> {
|
|
18
|
+
private readonly effect;
|
|
19
|
+
constructor(callback: () => Value, options?: ReactiveOptions<Value>);
|
|
20
|
+
/**
|
|
21
|
+
* @inheritdoc
|
|
22
|
+
*/
|
|
23
|
+
get(): Value;
|
|
24
|
+
}
|
|
25
|
+
declare abstract class Reactive<Value, Equal = Value> {
|
|
26
|
+
protected readonly state: ReactiveState<Value, Equal>;
|
|
27
|
+
constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
|
|
28
|
+
/**
|
|
29
|
+
* Get the value
|
|
30
|
+
*/
|
|
31
|
+
abstract get(): Value;
|
|
32
|
+
/**
|
|
33
|
+
* Get the value _(without reactivity)_
|
|
34
|
+
*/
|
|
35
|
+
peek(): Value;
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to changes
|
|
38
|
+
*/
|
|
39
|
+
subscribe(callback: (value: Value) => void): Unsubscribe;
|
|
40
|
+
/**
|
|
41
|
+
* JSON representation of the value
|
|
42
|
+
*/
|
|
43
|
+
toJSON(): Value;
|
|
44
|
+
/**
|
|
45
|
+
* String representation of the value
|
|
46
|
+
*/
|
|
47
|
+
toString(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Unsubscribe from changes
|
|
50
|
+
*/
|
|
51
|
+
unsubscribe(callback: (value: Value) => void): void;
|
|
52
|
+
}
|
|
53
|
+
export type ReactiveOptions<Value> = {
|
|
54
|
+
/**
|
|
55
|
+
* Method to compare values for equality
|
|
56
|
+
*/
|
|
57
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
58
|
+
};
|
|
59
|
+
export type ReactiveState<Value, Equal> = {
|
|
60
|
+
computeds: Set<Computed<unknown>>;
|
|
61
|
+
effects: Set<Effect>;
|
|
62
|
+
equal: (first: Equal, second: Equal) => boolean;
|
|
63
|
+
subscriptions: Map<(value: Value) => void, Subscription<Value>>;
|
|
64
|
+
value: Value;
|
|
65
|
+
};
|
|
66
|
+
declare class Subscription<Value> {
|
|
67
|
+
state: ReactiveState<Value, never>;
|
|
68
|
+
callback: GenericCallback;
|
|
69
|
+
constructor(state: ReactiveState<Value, never>, callback: GenericCallback);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Unsubscribe from changes
|
|
73
|
+
*/
|
|
74
|
+
export type Unsubscribe = () => void;
|
|
75
|
+
export declare class Store<Value extends PlainObject> extends Reactive<Value, Value> {
|
|
76
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
77
|
+
/**
|
|
78
|
+
* @inheritdoc
|
|
79
|
+
*/
|
|
80
|
+
get(): Value;
|
|
81
|
+
/**
|
|
82
|
+
* Get a value by key _(without reactivity)_
|
|
83
|
+
*/
|
|
84
|
+
get(key: keyof Value): Value[keyof Value];
|
|
85
|
+
/**
|
|
86
|
+
* Get a value by key _(without reactivity)_
|
|
87
|
+
*/
|
|
88
|
+
get(key: Key): unknown;
|
|
89
|
+
/**
|
|
90
|
+
* Get the value _(without reactivity)_
|
|
91
|
+
*/
|
|
92
|
+
peek(): Value;
|
|
93
|
+
/**
|
|
94
|
+
* Get a value by key _(without reactivity)_
|
|
95
|
+
*/
|
|
96
|
+
peek(key: keyof Value): Value[keyof Value];
|
|
97
|
+
/**
|
|
98
|
+
* Get a value by key _(without reactivity)_
|
|
99
|
+
*/
|
|
100
|
+
peek(key: Key): unknown;
|
|
101
|
+
/**
|
|
102
|
+
* Set the value
|
|
103
|
+
*/
|
|
104
|
+
set(value?: Value): void;
|
|
105
|
+
/**
|
|
106
|
+
* Set a value by key
|
|
107
|
+
*/
|
|
108
|
+
set(key: keyof Value, value: Value[keyof Value]): void;
|
|
109
|
+
/**
|
|
110
|
+
* Set a value by key
|
|
111
|
+
*/
|
|
112
|
+
set(key: Key, value: unknown): void;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create a reactive store
|
|
116
|
+
*/
|
|
117
|
+
export declare function store<Value extends PlainObject>(value: Value, options?: ReactiveOptions<Value>): Store<Value>;
|
|
118
|
+
|
|
119
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Key, PlainObject } from '@oscarpalmer/atoms/models';
|
|
2
|
+
import { Reactive, type ReactiveOptions } from './reactive';
|
|
3
|
+
export declare class Store<Value extends PlainObject> extends Reactive<Value, Value> {
|
|
4
|
+
constructor(value: Value, options?: ReactiveOptions<Value>);
|
|
5
|
+
/**
|
|
6
|
+
* @inheritdoc
|
|
7
|
+
*/
|
|
8
|
+
get(): Value;
|
|
9
|
+
/**
|
|
10
|
+
* Get a value by key _(without reactivity)_
|
|
11
|
+
*/
|
|
12
|
+
get(key: keyof Value): Value[keyof Value];
|
|
13
|
+
/**
|
|
14
|
+
* Get a value by key _(without reactivity)_
|
|
15
|
+
*/
|
|
16
|
+
get(key: Key): unknown;
|
|
17
|
+
/**
|
|
18
|
+
* Get the value _(without reactivity)_
|
|
19
|
+
*/
|
|
20
|
+
peek(): Value;
|
|
21
|
+
/**
|
|
22
|
+
* Get a value by key _(without reactivity)_
|
|
23
|
+
*/
|
|
24
|
+
peek(key: keyof Value): Value[keyof Value];
|
|
25
|
+
/**
|
|
26
|
+
* Get a value by key _(without reactivity)_
|
|
27
|
+
*/
|
|
28
|
+
peek(key: Key): unknown;
|
|
29
|
+
/**
|
|
30
|
+
* Set the value
|
|
31
|
+
*/
|
|
32
|
+
set(value?: Value): void;
|
|
33
|
+
/**
|
|
34
|
+
* Set a value by key
|
|
35
|
+
*/
|
|
36
|
+
set(key: keyof Value, value: Value[keyof Value]): void;
|
|
37
|
+
/**
|
|
38
|
+
* Set a value by key
|
|
39
|
+
*/
|
|
40
|
+
set(key: Key, value: unknown): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a reactive store
|
|
44
|
+
*/
|
|
45
|
+
export declare function store<Value extends PlainObject>(value: Value, options?: ReactiveOptions<Value>): Store<Value>;
|