@oscarpalmer/mora 0.18.1 → 0.19.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.
@@ -0,0 +1,120 @@
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
+ #private;
77
+ constructor(value: Value, options?: ReactiveOptions<Value>);
78
+ /**
79
+ * @inheritdoc
80
+ */
81
+ get(): Value;
82
+ /**
83
+ * Get a value by key _(without reactivity)_
84
+ */
85
+ get(key: keyof Value): Value[keyof Value];
86
+ /**
87
+ * Get a value by key _(without reactivity)_
88
+ */
89
+ get(key: Key): unknown;
90
+ /**
91
+ * Get the value _(without reactivity)_
92
+ */
93
+ peek(): Value;
94
+ /**
95
+ * Get a value by key _(without reactivity)_
96
+ */
97
+ peek(key: keyof Value): Value[keyof Value];
98
+ /**
99
+ * Get a value by key _(without reactivity)_
100
+ */
101
+ peek(key: Key): unknown;
102
+ /**
103
+ * Set the value
104
+ */
105
+ set(value?: Value): void;
106
+ /**
107
+ * Set a value by key
108
+ */
109
+ set(key: keyof Value, value: Value[keyof Value]): void;
110
+ /**
111
+ * Set a value by key
112
+ */
113
+ set(key: Key, value: unknown): void;
114
+ }
115
+ /**
116
+ * Create a reactive store
117
+ */
118
+ export declare function store<Value extends PlainObject>(value: Value, options?: ReactiveOptions<Value>): Store<Value>;
119
+
120
+ export {};
@@ -1,6 +1,7 @@
1
1
  import type { Key, PlainObject } from '@oscarpalmer/atoms/models';
2
2
  import { Reactive, type ReactiveOptions } from './reactive';
3
3
  export declare class Store<Value extends PlainObject> extends Reactive<Value, Value> {
4
+ #private;
4
5
  constructor(value: Value, options?: ReactiveOptions<Value>);
5
6
  /**
6
7
  * @inheritdoc