@reactables/core 1.0.0-beta.6 → 1.0.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/README.md
CHANGED
|
@@ -16,11 +16,12 @@ Reactive state management with RxJS.
|
|
|
16
16
|
1. [Examples](#examples)
|
|
17
17
|
1. [Basic Counter](#basic-counter-example)
|
|
18
18
|
1. [Scoped Effects - Updating Todos](#scoped-effects-example)
|
|
19
|
-
1. [Connecting Multiple Reactables - Event Prices](#connecting-hub-example)
|
|
20
19
|
1. [API](#api)
|
|
21
20
|
1. [Reactable](#reactable)
|
|
22
21
|
1. [RxBuilder](#rx-builder)
|
|
23
22
|
1. [RxConfig](#rx-config)
|
|
23
|
+
1. [ofTypes](#of-types)
|
|
24
|
+
1. [storeValue](#store-value)
|
|
24
25
|
1. [Other Interfaces](#interfaces)
|
|
25
26
|
1. [Effect](#api-effect)
|
|
26
27
|
1. [ScopedEffects](#api-scoped-effects)
|
|
@@ -106,41 +107,34 @@ Design Diagram | Reactable | Try it out on StackBlitz.<br /> Choo
|
|
|
106
107
|
:-------------------------:|:-------------------------:|:-------------------------:
|
|
107
108
|
<img src="https://raw.githubusercontent.com/reactables/reactables/main/documentation/Slide12ScopedEffectsExampleTodos.jpg" width="400" /> | [See Code for RxTodoUpdates](https://github.com/reactables/reactables/tree/main/packages/examples/src/RxTodoUpdates/RxTodoUpdates.ts) | <a href="https://stackblitz.com/edit/github-6pgtev?file=src%2Findex.js"><img src="https://raw.githubusercontent.com/reactables/reactables/main/documentation/VanillaJS.jpg" width="50" /></a><br /><a href="https://stackblitz.com/edit/github-1r6pki?file=src%2FTodoUpdates.tsx"><img src="https://raw.githubusercontent.com/reactables/reactables/main/documentation/React.png" width="60" /><br /><a href="https://stackblitz.com/edit/github-zfmupm?file=src%2Fapp%2Fapp.component.ts,src%2Fapp%2Ftodos%2Ftodos.component.ts"><img src="https://raw.githubusercontent.com/reactables/reactables/main/documentation/Angular.png" width="60" /></a>
|
|
108
109
|
|
|
109
|
-
### Connecting Multiple Reactables - Event Tickets <a name="connecting-hub-example"></a>
|
|
110
|
-
|
|
111
|
-
This examples shows two sets of reactables. The first is responsible for updating the state of user controls, while the second fetches prices based on input from the first.
|
|
112
|
-
|
|
113
|
-
Design Diagram | Reactable | Try it out on StackBlitz.<br /> Choose your framework
|
|
114
|
-
:-------------------------:|:-------------------------:|:-------------------------:
|
|
115
|
-
<img src="https://raw.githubusercontent.com/reactables/reactables/main/documentation/Slide13ConnectingHubsExampleEventPrices.jpg" width="400" />| [See Code for RxEventTickets](https://github.com/reactables/reactables/tree/main/packages/examples/src/RxEventTickets/RxEventTickets.ts) | <a href="https://stackblitz.com/edit/github-pgpwly?file=src%2findex.js"><img src="https://raw.githubusercontent.com/reactables/reactables/main/documentation/VanillaJS.jpg" width="50" /></a><br /><a href="https://stackblitz.com/edit/github-eypqvc?file=src%2FEventTickets.tsx"><img src="https://raw.githubusercontent.com/reactables/reactables/main/documentation/React.png" width="60" /></a><br /><a href="https://stackblitz.com/edit/github-66mbtu?file=src%2Fapp%2Fevent-tickets%2Fevent-tickets.component.ts"><img src="https://raw.githubusercontent.com/reactables/reactables/main/documentation/Angular.png" width="60" /></a>
|
|
116
|
-
|
|
117
|
-
|
|
118
110
|
## API <a name="api"></a>
|
|
119
111
|
|
|
120
|
-
### Reactable <a name="reactable"></a>
|
|
112
|
+
### `Reactable` <a name="reactable"></a>
|
|
121
113
|
|
|
122
114
|
Reactables provide the API for applications and UI components to receive and trigger state updates.
|
|
123
115
|
|
|
124
116
|
It is a tuple with the first item being an Observable emitting state changes and the second item is a dictionary of action methods for triggering state updates.
|
|
125
117
|
|
|
118
|
+
Reactables may also expose an optional third item - an observable emitting all the actions the received by the store during state updates. This can be helpful if other reactables also want to subscribe and react to any of those actions.
|
|
119
|
+
|
|
126
120
|
```typescript
|
|
127
|
-
export type Reactable<T, S = ActionMap> = [Observable<T>, S];
|
|
121
|
+
export type Reactable<T, S = ActionMap> = [Observable<T>, S, Observable<Action<unknown>>?];
|
|
128
122
|
|
|
129
123
|
export interface ActionMap {
|
|
130
124
|
[key: string | number]: (payload?: unknown) => void | ActionMap;
|
|
131
125
|
}
|
|
132
126
|
```
|
|
133
127
|
|
|
134
|
-
### RxBuilder <a name="rx-builder"></a>
|
|
128
|
+
### `RxBuilder` <a name="rx-builder"></a>
|
|
135
129
|
|
|
136
130
|
Factory function for building [Reactables](#reactable). Accepts a [RxConfig](#rx-confg) configuration object.
|
|
137
131
|
|
|
138
132
|
```typescript
|
|
139
|
-
|
|
133
|
+
declare const RxBuilder: <T, S extends Cases<T>>(config: RxConfig<T, S>) => Reactable<T, { [K in keyof S]: (payload?: unknown) => void; }>;
|
|
140
134
|
|
|
141
135
|
```
|
|
142
136
|
|
|
143
|
-
#### RxConfig <a name="rx-config"></a>
|
|
137
|
+
#### `RxConfig` <a name="rx-config"></a>
|
|
144
138
|
|
|
145
139
|
Configuration object for creating Reactables.
|
|
146
140
|
|
|
@@ -148,7 +142,6 @@ Configuration object for creating Reactables.
|
|
|
148
142
|
interface RxConfig <T, S extends Cases<T>>{
|
|
149
143
|
initialState: T;
|
|
150
144
|
reducers: S;
|
|
151
|
-
storeValue?: boolean;
|
|
152
145
|
debug?: boolean;
|
|
153
146
|
effects?: Effect<unknown, unknown>[];
|
|
154
147
|
sources?: Observable<Action<unknown>>[] | { [key: string]: Observable<unknown> };
|
|
@@ -169,7 +162,6 @@ type SingleActionReducer<T, S> = (state: T, action: Action<S>) => T;
|
|
|
169
162
|
| initialState | Initial state of the Reactable |
|
|
170
163
|
| reducers | Dictionary of cases for the Reactable to handle. Each case can be a reducer function or a configuration object. RxBuilder will use this to generate Actions, Reducers, and add [ScopedEffects](#api-scoped-effects). |
|
|
171
164
|
| debug (optional) | to turn on debugging to console.log all messages received by the store and state changes |
|
|
172
|
-
| storeValue (optional) | Option to store value if Reactable is used to persist application state. Subsequent subscriptions will receive the latest stored value. Default to false |
|
|
173
165
|
| effects (optional) | Array of [Effects](#api-effects) to be registered to the Reactable |
|
|
174
166
|
| sources (optional) <a name="hub-sources"></a> | Additional [Action](#api-actions) Observables the Reactable is listening to. Can be an array or a dictionary where key is the action type and value is the Observable emitting the payload |
|
|
175
167
|
|
|
@@ -177,9 +169,31 @@ Debug Example:
|
|
|
177
169
|
|
|
178
170
|
<img src="https://raw.githubusercontent.com/reactables/reactables/main/documentation/SlideSixDebug.jpg" width="500" />
|
|
179
171
|
|
|
172
|
+
### `ofTypes` <a name="of-Types"></a>
|
|
173
|
+
|
|
174
|
+
Function that accepts an array of action types (`string`) and returns an `OperatorFunction` that will filter for those `Action`s.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
export declare const ofTypes: (types: string[]) => OperatorFunction<Action<unknown>, Action<unknown>>;
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### `storeValue` <a name="store-value"></a>
|
|
181
|
+
|
|
182
|
+
Decorator function used store the state value in a `ReplaySubject` instead of an `Observable` so subsequent subscriptions can access the latest stored value.
|
|
183
|
+
|
|
184
|
+
Also add's a `destroy` action method to be called to teardown any Reactable decorated with `storeValue`.
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
interface DestroyAction {
|
|
188
|
+
destroy: () => void;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
declare const storeValue: <T, S>(reactable: Reactable<T, S>) => Reactable<T, S & DestroyAction>;
|
|
192
|
+
```
|
|
193
|
+
|
|
180
194
|
### Other Interfaces <a name="interfaces"></a>
|
|
181
195
|
|
|
182
|
-
#### Effect <a name="api-effect"></a>
|
|
196
|
+
#### `Effect` <a name="api-effect"></a>
|
|
183
197
|
|
|
184
198
|
Effects are expressed as [RxJS Operator Functions](https://rxjs.dev/api/index/interface/OperatorFunction). They pipe the [dispatcher$](#hub-dispatcher) stream and run side effects on incoming [Actions](#api-action).
|
|
185
199
|
|
|
@@ -187,7 +201,7 @@ Effects are expressed as [RxJS Operator Functions](https://rxjs.dev/api/index/in
|
|
|
187
201
|
type Effect<T, S> = OperatorFunction<Action<T>, Action<S>>;
|
|
188
202
|
```
|
|
189
203
|
|
|
190
|
-
#### ScopedEffects <a name="api-scoped-effects"></a>
|
|
204
|
+
#### `ScopedEffects` <a name="api-scoped-effects"></a>
|
|
191
205
|
|
|
192
206
|
Scoped Effects are declared when defining reducers in [RxConfig](#rx-config). They are dynamically created stream(s) scoped to an Action `type` & `key` combination.
|
|
193
207
|
|
|
@@ -203,7 +217,7 @@ interface ScopedEffects<T> {
|
|
|
203
217
|
| effects | Array of [Effects](#api-effects) scoped to the Action `type` & `key` |
|
|
204
218
|
|
|
205
219
|
|
|
206
|
-
#### Action <a name="api-action"></a>
|
|
220
|
+
#### `Action` <a name="api-action"></a>
|
|
207
221
|
```typescript
|
|
208
222
|
interface Action<T = undefined> {
|
|
209
223
|
type: string;
|
|
@@ -217,7 +231,7 @@ interface Action<T = undefined> {
|
|
|
217
231
|
| payload (optional) | payload associated with Action |
|
|
218
232
|
| scopedEffects (optional) | [See ScopedEffects](#api-scoped-effects) |
|
|
219
233
|
|
|
220
|
-
#### Reducer <a name="api-reducer"></a>
|
|
234
|
+
#### `Reducer` <a name="api-reducer"></a>
|
|
221
235
|
|
|
222
236
|
From the [Redux Docs](https://redux.js.org/tutorials/fundamentals/part-3-state-actions-reducers):
|
|
223
237
|
> Reducers are functions that take the current state and an action as arguments, and return a new state result
|
|
@@ -11,6 +11,7 @@ export interface EffectsAndSources {
|
|
|
11
11
|
}
|
|
12
12
|
export interface RxConfig<T, S extends Cases<T>> extends SliceConfig<T, S>, EffectsAndSources {
|
|
13
13
|
debug?: boolean;
|
|
14
|
+
/**@deprecated Use storeValue decorator instead to add store value behaviour to reactable */
|
|
14
15
|
storeValue?: boolean;
|
|
15
16
|
}
|
|
16
17
|
export declare const RxBuilder: <T, S extends Cases<T>>({ effects, sources, debug, storeValue, ...sliceConfig }: RxConfig<T, S>) => Reactable<T, { [K in keyof S]: (payload?: unknown) => void; }>;
|
package/dist/Helpers/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -291,5 +291,14 @@ var RxBuilder = function (_a) {
|
|
|
291
291
|
];
|
|
292
292
|
};
|
|
293
293
|
|
|
294
|
+
var storeValue = function (reactable) {
|
|
295
|
+
var replaySubject$ = new rxjs.ReplaySubject(1);
|
|
296
|
+
var state$ = reactable[0], actions = reactable[1], actions$ = reactable[2];
|
|
297
|
+
var subscription = state$.subscribe(function (state) { return replaySubject$.next(state); });
|
|
298
|
+
var destroy = function () { return subscription.unsubscribe(); };
|
|
299
|
+
return [replaySubject$, __assign(__assign({}, actions), { destroy: destroy }), actions$];
|
|
300
|
+
};
|
|
301
|
+
|
|
294
302
|
exports.RxBuilder = RxBuilder;
|
|
295
303
|
exports.ofTypes = ofTypes;
|
|
304
|
+
exports.storeValue = storeValue;
|
package/package.json
CHANGED