ngxs-synchronizers 1.0.0-rc.1 → 1.0.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/LICENSE +18 -18
- package/README.md +168 -168
- package/bundles/ngxs-synchronizers.umd.js +12 -6
- package/bundles/ngxs-synchronizers.umd.js.map +1 -1
- package/docs/api-reference.md +700 -700
- package/docs/usage-guide.md +385 -385
- package/esm2015/decorators/sync-class.js +1 -1
- package/esm2015/decorators/sync-state.js +9 -3
- package/esm2015/index.js +1 -1
- package/esm2015/module.js +1 -1
- package/esm2015/state-selector.js +5 -5
- package/esm2015/sync-store.js +1 -1
- package/esm2015/synchronizer/collection-synchronizer.js +1 -1
- package/esm2015/synchronizer/property-synchronizer.js +1 -1
- package/esm2015/synchronizer/state-synchronizer.js +1 -1
- package/esm2015/synchronizer/synchronizer-dictionary.js +1 -1
- package/esm2015/synchronizer/synchronizer.js +1 -1
- package/fesm2015/ngxs-synchronizers.js +12 -6
- package/fesm2015/ngxs-synchronizers.js.map +1 -1
- package/package.json +1 -1
- package/state-selector.d.ts +2 -2
package/docs/api-reference.md
CHANGED
|
@@ -1,701 +1,701 @@
|
|
|
1
|
-
# ngxs-synchronizers API Reference
|
|
2
|
-
|
|
3
|
-
## `NgxsSyncModule`
|
|
4
|
-
|
|
5
|
-
The Angular module for this library.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
class NgxsSyncModule {}
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## `@SyncState`
|
|
12
|
-
|
|
13
|
-
The class decorator used to create state definitions. Wraps the `@State` decorator [from NGXS](https://www.ngxs.io/concepts/state).
|
|
14
|
-
|
|
15
|
-
See the [NGXS documentation](https://www.ngxs.io/concepts/state) for more information about `@State`.
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
function SyncState<T>(options: SyncStoreOptions<T>): ClassDecorator
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
`options` - The [`SyncStoreOptions`](#syncstoreoptions) used to define this state.
|
|
22
|
-
|
|
23
|
-
## `SyncStoreOptions`
|
|
24
|
-
|
|
25
|
-
Interface for defining a state via `@SyncState`.
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
interface SyncStoreOptions<T> {
|
|
29
|
-
name: string;
|
|
30
|
-
defaults?: T;
|
|
31
|
-
children?: any[];
|
|
32
|
-
synchronizers?: SynchronizerDictionary<T>;
|
|
33
|
-
}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
`name` - See [NGXS docs](https://www.ngxs.io/concepts/state).
|
|
37
|
-
|
|
38
|
-
`defaults` - See [NGXS docs](https://www.ngxs.io/concepts/state).
|
|
39
|
-
|
|
40
|
-
`children` - See [NGXS docs](https://www.ngxs.io/concepts/state).
|
|
41
|
-
|
|
42
|
-
`synchronizers` - The synchronizers for this state, declared as a [`SynchronizerDictionary`](#synchronizerdictionary).
|
|
43
|
-
|
|
44
|
-
## `SynchronizerDictionary`
|
|
45
|
-
|
|
46
|
-
A dictionary of synchronizers for a given state, which is either a record of property synchronizers or a single collection synchronizer.
|
|
47
|
-
|
|
48
|
-
```ts
|
|
49
|
-
type SynchronizerDictionary<T> = {
|
|
50
|
-
[P in keyof T]?: Type<PropertySynchronizer<T, P>>;
|
|
51
|
-
} | Type<CollectionSynchronizer<T>>;
|
|
52
|
-
|
|
53
|
-
namespace SynchronizerDictionary {
|
|
54
|
-
|
|
55
|
-
function keys<T>(dict: SynchronizerDictionary<T>): Array<keyof T>;
|
|
56
|
-
|
|
57
|
-
function isCollectionSynchronizer<T>(
|
|
58
|
-
dict: SynchronizerDictionary<T>
|
|
59
|
-
): dict is Type<CollectionSynchronizer<T>>;
|
|
60
|
-
|
|
61
|
-
function resolveSynchronizer<T>(
|
|
62
|
-
dict: SynchronizerDictionary<T>,
|
|
63
|
-
propKey: keyof T
|
|
64
|
-
): Type<Synchronizer<T, keyof T, unknown, unknown>>;
|
|
65
|
-
|
|
66
|
-
function resolveSynchronizerInstance<T>(
|
|
67
|
-
injector: Injector,
|
|
68
|
-
dict: SynchronizerDictionary<T>,
|
|
69
|
-
propKey: keyof T
|
|
70
|
-
): Synchronizer<T, keyof T, unknown, unknown>;
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Namespace functions
|
|
75
|
-
|
|
76
|
-
#### `SynchronizerDictionary.keys`
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
function keys<T>(dict: SynchronizerDictionary<T>): Array<keyof T>
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Returns the list of keys in the dictionary.
|
|
83
|
-
|
|
84
|
-
`dict` - The synchronizer dictionary.
|
|
85
|
-
|
|
86
|
-
#### `SynchronizerDictionary.isCollectionSynchronizer`
|
|
87
|
-
|
|
88
|
-
```ts
|
|
89
|
-
function isCollectionSynchronizer<T>(
|
|
90
|
-
dict: SynchronizerDictionary<T>
|
|
91
|
-
): dict is Type<CollectionSynchronizer<T>>
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Returns whether or not the given dictionary is a [`CollectionSynchronizer`](#collectionsynchronizer).
|
|
95
|
-
|
|
96
|
-
`dict` - The synchronizer dictionary.
|
|
97
|
-
|
|
98
|
-
#### `SynchronizerDictionary.resolveSynchronizer`
|
|
99
|
-
|
|
100
|
-
```ts
|
|
101
|
-
function resolveSynchronizer<T>(
|
|
102
|
-
dict: SynchronizerDictionary<T>,
|
|
103
|
-
propKey: keyof T
|
|
104
|
-
): Type<Synchronizer<T, keyof T, unknown, unknown>>
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Resolves the synchronizer associated with the property `propKey` from the dictionary (or the [`CollectionSynchronizer`](#collectionsynchronizer)).
|
|
108
|
-
|
|
109
|
-
`dict` - The synchronizer dictionary.
|
|
110
|
-
|
|
111
|
-
`propKey` - The property to resolve the synchronizer of.
|
|
112
|
-
|
|
113
|
-
#### `SynchronizerDictionary.resolveSynchronizerInstance`
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
function resolveSynchronizerInstance<T>(
|
|
117
|
-
injector: Injector,
|
|
118
|
-
dict: SynchronizerDictionary<T>,
|
|
119
|
-
propKey: keyof T
|
|
120
|
-
): Synchronizer<T, keyof T, unknown, unknown>
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
Resolves a synchronizer instance associated with the property `propKey` from the dictionary (or the [`CollectionSynchronizer`](#collectionsynchronizer)).
|
|
124
|
-
|
|
125
|
-
`injector` - The Angular injector.
|
|
126
|
-
|
|
127
|
-
`dict` - The synchronizer dictionary.
|
|
128
|
-
|
|
129
|
-
`propKey` - The property to resolve the synchronizer instance of.
|
|
130
|
-
|
|
131
|
-
## `SyncStore`
|
|
132
|
-
|
|
133
|
-
A global state manager for interacting with synchronizers. Extends the `Store` class [from NGXS](https://www.ngxs.io/concepts/store).
|
|
134
|
-
|
|
135
|
-
See the [NGXS documentation](https://www.ngxs.io/concepts/store) for more information about `Store`.
|
|
136
|
-
|
|
137
|
-
```ts
|
|
138
|
-
class SyncStore extends Store {
|
|
139
|
-
|
|
140
|
-
public state<T>(syncState: SyncClass<T>): StateSelector<T>;
|
|
141
|
-
}
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### Methods
|
|
145
|
-
|
|
146
|
-
#### `SyncStore.state`
|
|
147
|
-
|
|
148
|
-
```ts
|
|
149
|
-
function state<T>(syncState: SyncClass<T>): StateSelector<T>
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
Method used for obtaining a [`StateSelector`](#stateselector) instance for a given [`SyncClass`](#syncclass). `StateSelector` instances are cached so that the same instance will be used for each `SyncClass` type. If the given `syncState` is not a known state, the method will return `null`.
|
|
153
|
-
|
|
154
|
-
```syncState``` - The state class to obtain a [`StateSelector`](#stateselector) for.
|
|
155
|
-
|
|
156
|
-
## `SyncClass`
|
|
157
|
-
|
|
158
|
-
```ts
|
|
159
|
-
import { Type } from '@angular/core';
|
|
160
|
-
|
|
161
|
-
type SyncClass<T> = Type<T>;
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## `StateSelector`
|
|
165
|
-
|
|
166
|
-
Used to manage synchronizers and synchronization state. `StateSelector` objects are unique to a specific state class.
|
|
167
|
-
|
|
168
|
-
```ts
|
|
169
|
-
class StateSelector<T> {
|
|
170
|
-
|
|
171
|
-
public dispatch<PropT extends keyof T>(propertyName: PropT, value: T[PropT]): Observable<T>;
|
|
172
|
-
|
|
173
|
-
public property<PropT extends keyof T>(propertyName: PropT): Observable<T[PropT]>;
|
|
174
|
-
public properties(): Observable<T>;
|
|
175
|
-
public definedProperty<PropT extends keyof T>(propertyName: PropT): Observable<T[PropT]>;
|
|
176
|
-
|
|
177
|
-
public isSyncingProperty(propertyName: keyof T): Observable<boolean>;
|
|
178
|
-
public onPropertySyncing<PropT extends keyof T>(propertyName: PropT): Observable<PropT>;
|
|
179
|
-
public onPropertySynced<PropT extends keyof T>(propertyName: PropT): Observable<PropT>;
|
|
180
|
-
public onEveryPropertySyncing(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>;
|
|
181
|
-
public onEveryPropertySynced(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>;
|
|
182
|
-
public onSomePropertySyncing(...propertyNames: Array<keyof T>): Observable<keyof T>;
|
|
183
|
-
public onSomePropertySynced(...propertyNames: Array<keyof T>): Observable<keyof T>;
|
|
184
|
-
|
|
185
|
-
public require<RequestParamsT = never>(
|
|
186
|
-
propertyNames: keyof T | Array<keyof T>,
|
|
187
|
-
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
188
|
-
): Observable<T>;
|
|
189
|
-
|
|
190
|
-
public requireProperty<PropT extends keyof T, RequestParamsT = never>(
|
|
191
|
-
propertyName: PropT,
|
|
192
|
-
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
193
|
-
): Observable<T[PropT]>;
|
|
194
|
-
|
|
195
|
-
public sync<RequestParamsT = never>(
|
|
196
|
-
propertyNames: keyof T | Array<keyof T>,
|
|
197
|
-
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
198
|
-
): Observable<T>;
|
|
199
|
-
|
|
200
|
-
public syncProperty<PropT extends keyof T, RequestParamsT = never>(
|
|
201
|
-
propertyName: PropT,
|
|
202
|
-
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
203
|
-
): Observable<T[PropT]>;
|
|
204
|
-
|
|
205
|
-
public export<RequestParamsT = never>(
|
|
206
|
-
propertyNames: keyof T | Array<keyof T>,
|
|
207
|
-
options?: Synchronizer.WriteOptions<RequestParamsT>
|
|
208
|
-
): Observable<any>;
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### Methods
|
|
213
|
-
|
|
214
|
-
#### `StateSelector.dispatch`
|
|
215
|
-
|
|
216
|
-
```ts
|
|
217
|
-
function dispatch<PropT extends keyof T>(propertyName: PropT, value: T[PropT]): Observable<T>
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
Dispatches an action that updates the property `propertyName` to the given `value`. Returns an observable that emits after all actions have completed.
|
|
221
|
-
|
|
222
|
-
`propertyName` - The name of the property to update.
|
|
223
|
-
|
|
224
|
-
`value` - The value to set the property to.
|
|
225
|
-
|
|
226
|
-
#### `StateSelector.property`
|
|
227
|
-
|
|
228
|
-
```ts
|
|
229
|
-
function property<PropT extends keyof T>(propertyName: PropT): Observable<T[PropT]>
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
Returns an observable that emits the value of the property `propertyName`. This observable will emit every time the property's value changes.
|
|
233
|
-
|
|
234
|
-
`propertyName` - The name of the property to observe.
|
|
235
|
-
|
|
236
|
-
#### `StateSelector.properties`
|
|
237
|
-
|
|
238
|
-
```ts
|
|
239
|
-
function properties(): Observable<T>
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
Returns an observable that emits the current state value. This observable will emit every time the state is updated.
|
|
243
|
-
|
|
244
|
-
#### `StateSelector.definedProperty`
|
|
245
|
-
|
|
246
|
-
```ts
|
|
247
|
-
function definedProperty<PropT extends keyof T>(propertyName: PropT): Observable<T[PropT]>
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
Returns an observable that emits the value of the property `propertyName` only if the value is not `null` or `undefined`. This observable will emit every time the property's value changes and is not `null` or `undefined`.
|
|
251
|
-
|
|
252
|
-
`propertyName` - The name of the property to observe.
|
|
253
|
-
|
|
254
|
-
#### `StateSelector.isSyncingProperty`
|
|
255
|
-
|
|
256
|
-
```ts
|
|
257
|
-
function isSyncingProperty(propertyName: keyof T): Observable<boolean>
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
Returns an observable that emits whether or not the property `propertyName` is being synchronized. This observable will emit every time the property's synchronization state changes.
|
|
261
|
-
|
|
262
|
-
`propertyName` - The name of the property to observe the synchronization state of.
|
|
263
|
-
|
|
264
|
-
#### `StateSelector.onPropertySyncing`
|
|
265
|
-
|
|
266
|
-
```ts
|
|
267
|
-
function onPropertySyncing<PropT extends keyof T>(propertyName: PropT): Observable<PropT>
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
Returns an observable that emits whenever the property `propertyName` is starting to be synchronized. This observable will emit every time the property is starting to be synchronized. The returned observable will emit `propertyName`.
|
|
271
|
-
|
|
272
|
-
`propertyName` - The name of the property to observe the synchronization state of.
|
|
273
|
-
|
|
274
|
-
#### `StateSelector.onPropertySynced`
|
|
275
|
-
|
|
276
|
-
```ts
|
|
277
|
-
function onPropertySynced<PropT extends keyof T>(propertyName: PropT): Observable<PropT>
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
Returns an observable that emits whenever the property `propertyName` is completed being synchronized. This observable will emit every time the property is completed being synchronized. The returned observable will emit `propertyName`.
|
|
281
|
-
|
|
282
|
-
`propertyName` - The name of the property to observe the synchronization state of.
|
|
283
|
-
|
|
284
|
-
#### `StateSelector.onEveryPropertySyncing`
|
|
285
|
-
|
|
286
|
-
```ts
|
|
287
|
-
function onEveryPropertySyncing(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
Returns an observable that emits whenever all of the given properties in `propertyNames` are starting to be synchronized. This observable will emit every time all of the given properties are starting to be synchronized. The returned observable will emit an array of property names that are being synchronized.
|
|
291
|
-
|
|
292
|
-
`propertyNames` - The names of the properties to observe the synchronization states of.
|
|
293
|
-
|
|
294
|
-
#### `StateSelector.onEveryPropertySynced`
|
|
295
|
-
|
|
296
|
-
```ts
|
|
297
|
-
function onEveryPropertySynced(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
Returns an observable that emits whenever all of the given properties in `propertyNames` are completed being synchronized. This observable will emit every time all of the given properties are completed being synchronized. The returned observable will emit an array of property names that are completed being synchronized.
|
|
301
|
-
|
|
302
|
-
`propertyNames` - The names of the properties to observe the synchronization states of.
|
|
303
|
-
|
|
304
|
-
#### `StateSelector.onSomePropertySyncing`
|
|
305
|
-
|
|
306
|
-
```ts
|
|
307
|
-
function onSomePropertySyncing(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
Returns an observable that emits whenever any of the given properties in `propertyNames` is starting to be synchronized. This observable will emit every time any of the given properties is starting to be synchronized. The returned observable will emit an array of property names that are being synchronized.
|
|
311
|
-
|
|
312
|
-
`propertyNames` - The names of the properties to observe the synchronization states of.
|
|
313
|
-
|
|
314
|
-
#### `StateSelector.onSomePropertySynced`
|
|
315
|
-
|
|
316
|
-
```ts
|
|
317
|
-
function onSomePropertySynced(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
Returns an observable that emits whenever any of the given properties in `propertyNames` is completed being synchronized. This observable will emit every time any of the given properties is completed being synchronized. The returned observable will emit an array of property names that are completed being synchronized.
|
|
321
|
-
|
|
322
|
-
`propertyNames` - The names of the properties to observe the synchronization states of.
|
|
323
|
-
|
|
324
|
-
#### `StateSelector.require`
|
|
325
|
-
|
|
326
|
-
```ts
|
|
327
|
-
function require<RequestParamsT = never>(
|
|
328
|
-
propertyNames: keyof T | Array<keyof T>,
|
|
329
|
-
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
330
|
-
): Observable<T>
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
Conditionally invokes the read operation for the synchronizers of the given properties in `propertyNames` only if the property value is not yet defined. Returns an observable that emits the value of the state after the invoked synchronizer operations are completed, or the current property value if it was defined.
|
|
334
|
-
|
|
335
|
-
`propertyNames` - The names of the properties (or single property) to conditionally invoke the read operation of their synchronizer(s) on.
|
|
336
|
-
|
|
337
|
-
`options` - (Optional) The [`Synchronizer.ReadOptions`](#synchronizer.readoptions) to pass to each synchronizer's read operation when invoked.
|
|
338
|
-
|
|
339
|
-
See [`Synchronizer.read`](#synchronizer.read) for more information.
|
|
340
|
-
|
|
341
|
-
#### `StateSelector.requireProperty`
|
|
342
|
-
|
|
343
|
-
```ts
|
|
344
|
-
function requireProperty<PropT extends keyof T, RequestParamsT = never>(
|
|
345
|
-
propertyName: PropT,
|
|
346
|
-
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
347
|
-
): Observable<T[PropT]>
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
Conditionally invokes the read operation for the synchronizer of the given property `propertyName` only if the property value is not yet defined. Returns an observable that emits the value of the property after the invoked synchronizer operation is completed, or the current property value if it was defined.
|
|
351
|
-
|
|
352
|
-
`propertyName` - The name of the property to conditionally invoke the read operation of its synchronizer on.
|
|
353
|
-
|
|
354
|
-
`options` - (Optional) The [`Synchronizer.ReadOptions`](#synchronizer.readoptions) to pass to the synchronizer's read operation when invoked.
|
|
355
|
-
|
|
356
|
-
See [`Synchronizer.read`](#synchronizer.read) for more information.
|
|
357
|
-
|
|
358
|
-
#### `StateSelector.sync`
|
|
359
|
-
|
|
360
|
-
```ts
|
|
361
|
-
function sync<RequestParamsT = never>(
|
|
362
|
-
propertyNames: keyof T | Array<keyof T>,
|
|
363
|
-
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
364
|
-
): Observable<T>
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
Invokes the read operation for the synchronizers of the given properties in `propertyNames`. Returns an observable that emits the value of the state after the invoked synchronizer operations are completed.
|
|
368
|
-
|
|
369
|
-
`propertyNames` - The names of the properties (or single property) to invoke the read operation of their synchronizer(s) on.
|
|
370
|
-
|
|
371
|
-
`options` - (Optional) The [`Synchronizer.ReadOptions`](#synchronizer.readoptions) to pass to each synchronizer's read operation when invoked.
|
|
372
|
-
|
|
373
|
-
See [`Synchronizer.read`](#synchronizer.read) for more information.
|
|
374
|
-
|
|
375
|
-
#### `StateSelector.syncProperty`
|
|
376
|
-
|
|
377
|
-
```ts
|
|
378
|
-
function syncProperty<PropT extends keyof T, RequestParamsT = never>(
|
|
379
|
-
propertyName: PropT,
|
|
380
|
-
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
381
|
-
): Observable<T[PropT]>
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
Invokes the read operation for the synchronizer of the given property `propertyName`. Returns an observable that emits the value of the property after the invoked synchronizer operation is completed.
|
|
385
|
-
|
|
386
|
-
`propertyName` - The name of the property to invoke the read operation of its synchronizer on.
|
|
387
|
-
|
|
388
|
-
`options` - (Optional) The [`Synchronizer.ReadOptions`](#synchronizer.readoptions) to pass to the synchronizer's read operation when invoked.
|
|
389
|
-
|
|
390
|
-
See [`Synchronizer.read`](#synchronizer.read) for more information.
|
|
391
|
-
|
|
392
|
-
#### `StateSelector.export`
|
|
393
|
-
|
|
394
|
-
```ts
|
|
395
|
-
function export<RequestParamsT = never>(
|
|
396
|
-
propertyNames: keyof T | Array<keyof T>,
|
|
397
|
-
options?: Synchronizer.WriteOptions<RequestParamsT>
|
|
398
|
-
): Observable<any>
|
|
399
|
-
```
|
|
400
|
-
|
|
401
|
-
Invokes the write operation for the synchronizers of the given properties in `propertyNames`. Returns an observable that emits the combined response value after the invoked synchronizer operations are completed.
|
|
402
|
-
|
|
403
|
-
`propertyNames` - The names of the properties (or single property) to invoke the write operation of their synchronizer(s) on.
|
|
404
|
-
|
|
405
|
-
`options` - (Optional) The [`Synchronizer.WriteOptions`](#synchronizer.writeoptions) to pass to each synchronizer's write operation when invoked.
|
|
406
|
-
|
|
407
|
-
See [`Synchronizer.write`](#synchronizer.write) for more information.
|
|
408
|
-
|
|
409
|
-
## `Synchronizer`
|
|
410
|
-
|
|
411
|
-
Base interface for all synchronizers.
|
|
412
|
-
|
|
413
|
-
```ts
|
|
414
|
-
interface Synchronizer<
|
|
415
|
-
T,
|
|
416
|
-
PropKey extends keyof T,
|
|
417
|
-
ReadParamsT,
|
|
418
|
-
WriteParamsT
|
|
419
|
-
> {
|
|
420
|
-
requiredProperties?: Array<keyof T>;
|
|
421
|
-
proxy?: boolean;
|
|
422
|
-
|
|
423
|
-
read(
|
|
424
|
-
requiredDetails: Partial<T>,
|
|
425
|
-
options: Synchronizer.BaseOptions<T, PropKey, ReadParamsT> & Synchronizer.ReadOptions<ReadParamsT>
|
|
426
|
-
): Observable<T[PropKey]>;
|
|
427
|
-
|
|
428
|
-
write?(
|
|
429
|
-
value: T[PropKey],
|
|
430
|
-
options: Synchronizer.BaseOptions<T, PropKey, WriteParamsT> & Synchronizer.WriteOptions<WriteParamsT>
|
|
431
|
-
): Observable<any>;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
namespace Synchronizer {
|
|
435
|
-
|
|
436
|
-
interface BaseOptions<
|
|
437
|
-
T,
|
|
438
|
-
PropKey extends keyof T,
|
|
439
|
-
ParamsT
|
|
440
|
-
> {
|
|
441
|
-
propertyName: PropKey;
|
|
442
|
-
requestParams?: ParamsT;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
interface ReadOptions<ParamsT> {
|
|
446
|
-
clearStore?: boolean;
|
|
447
|
-
requestParams?: ParamsT;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
interface WriteOptions<ParamsT> {
|
|
451
|
-
requestParams?: ParamsT;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
```
|
|
455
|
-
|
|
456
|
-
### Interface properties
|
|
457
|
-
|
|
458
|
-
`requiredProperties` - (Optional) The list of properties that are required to be defined before this synchronizer's read operation is invoked. If any of the given properties has its own synchronizer, it's read operation will be completed before invoking this synchronizer if its value is not yet defined (or if this is a proxy synchronizer).
|
|
459
|
-
|
|
460
|
-
`proxy` - (Optional) Whether or not this is a proxy synchronizer. A proxy synchronizer is a synchronizer that does not make its own requests, but simply transforms the state of other synchronized values. A proxy synchronizer's `requiredProperties` will always have their synchronizer's invoked when the proxy synchronizer itself is invoked. Defaults to `false`.
|
|
461
|
-
|
|
462
|
-
### Interface methods
|
|
463
|
-
|
|
464
|
-
#### `Synchronizer.read`
|
|
465
|
-
|
|
466
|
-
```ts
|
|
467
|
-
function read(
|
|
468
|
-
requiredDetails: Partial<T>,
|
|
469
|
-
options: Synchronizer.BaseOptions<T, PropKey, ReadParamsT> & Synchronizer.ReadOptions<ReadParamsT>
|
|
470
|
-
): Observable<T[PropKey]>
|
|
471
|
-
```
|
|
472
|
-
|
|
473
|
-
The read operation of the synchronizer, used to retrieve a value from a remote data store. Returns an observable that emits the value retrieved from the remote data store.
|
|
474
|
-
|
|
475
|
-
`requiredDetails` - A partial list of state values corresponding to the properties defined in `requiredProperties`. Empty if no `requiredProperties` were defined.
|
|
476
|
-
|
|
477
|
-
`options` - The [`Synchronizer.ReadOptions`](#synchronizer.readoptions) to use for this operation.
|
|
478
|
-
|
|
479
|
-
#### `Synchronizer.write`
|
|
480
|
-
|
|
481
|
-
```ts
|
|
482
|
-
function write(
|
|
483
|
-
value: T[PropKey],
|
|
484
|
-
options: Synchronizer.BaseOptions<T, PropKey, WriteParamsT> & Synchronizer.WriteOptions<WriteParamsT>
|
|
485
|
-
): Observable<any>
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
(Optional) The write operation of the synchronizer, used to send a value to a remote data store. Returns an observable that emits the response (if any) from the remote data store after the write operation is complete.
|
|
489
|
-
|
|
490
|
-
`value` - The value to write to the remote data store.
|
|
491
|
-
|
|
492
|
-
`options` - The [`Synchronizer.WriteOptions`](#synchronizer.writeoptions) to use for this operation.
|
|
493
|
-
|
|
494
|
-
### Namespace functions
|
|
495
|
-
|
|
496
|
-
#### `Synchronizer.BaseOptions`
|
|
497
|
-
|
|
498
|
-
```ts
|
|
499
|
-
interface BaseOptions<
|
|
500
|
-
T,
|
|
501
|
-
PropKey extends keyof T,
|
|
502
|
-
ParamsT
|
|
503
|
-
> {
|
|
504
|
-
propertyName: PropKey;
|
|
505
|
-
requestParams?: ParamsT;
|
|
506
|
-
}
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
The base interface for all [`Synchronizer`](#synchronizer) operations.
|
|
510
|
-
|
|
511
|
-
`propertyName` - The name of the state property involved in the current operation.
|
|
512
|
-
|
|
513
|
-
`requestParams` - (Optional) Any request params to be passed to the remote data store.
|
|
514
|
-
|
|
515
|
-
#### `Synchronizer.ReadOptions`
|
|
516
|
-
|
|
517
|
-
```ts
|
|
518
|
-
interface ReadOptions<ParamsT> {
|
|
519
|
-
clearStore?: boolean;
|
|
520
|
-
requestParams?: ParamsT;
|
|
521
|
-
}
|
|
522
|
-
```
|
|
523
|
-
|
|
524
|
-
The interface for all [`Synchronizer`](#synchronizer) read operations.
|
|
525
|
-
|
|
526
|
-
`clearStore` - (Optional) Whether or not the current property value should be cleared before invoking the read operation.
|
|
527
|
-
|
|
528
|
-
`requestParams` - (Optional) Any request params to be passed to the remote data store.
|
|
529
|
-
|
|
530
|
-
#### `Synchronizer.WriteOptions`
|
|
531
|
-
|
|
532
|
-
```ts
|
|
533
|
-
interface WriteOptions<ParamsT> {
|
|
534
|
-
requestParams?: ParamsT;
|
|
535
|
-
}
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
The interface for all [`Synchronizer`](#synchronizer) write operations.
|
|
539
|
-
|
|
540
|
-
`requestParams` - (Optional) Any request params to be passed to the remote data store.
|
|
541
|
-
|
|
542
|
-
## `PropertySynchronizer`
|
|
543
|
-
|
|
544
|
-
Interface for declaring property synchronizers, which are linked to a specific state property.
|
|
545
|
-
|
|
546
|
-
```ts
|
|
547
|
-
interface PropertySynchronizer<
|
|
548
|
-
T,
|
|
549
|
-
PropKey extends keyof T,
|
|
550
|
-
ReadParamsT = never,
|
|
551
|
-
WriteParamsT = never
|
|
552
|
-
> extends Synchronizer<T, PropKey, ReadParamsT, WriteParamsT> {
|
|
553
|
-
|
|
554
|
-
read(
|
|
555
|
-
requiredDetails: Partial<T>,
|
|
556
|
-
options: PropertySynchronizer.ReadOptions<T, PropKey, ReadParamsT>
|
|
557
|
-
): Observable<T[PropKey]>;
|
|
558
|
-
|
|
559
|
-
write?(
|
|
560
|
-
value: T[PropKey],
|
|
561
|
-
options: PropertySynchronizer.WriteOptions<T, PropKey, WriteParamsT>
|
|
562
|
-
): Observable<any>;
|
|
563
|
-
}
|
|
564
|
-
```
|
|
565
|
-
|
|
566
|
-
### Interface methods
|
|
567
|
-
|
|
568
|
-
#### `PropertySynchronizer.read`
|
|
569
|
-
|
|
570
|
-
```ts
|
|
571
|
-
function read(
|
|
572
|
-
requiredDetails: Partial<T>,
|
|
573
|
-
options: PropertySynchronizer.ReadOptions<T, PropKey, ReadParamsT>
|
|
574
|
-
): Observable<T[PropKey]>
|
|
575
|
-
```
|
|
576
|
-
|
|
577
|
-
See [`Synchronizer.read`](#synchronizer.read).
|
|
578
|
-
|
|
579
|
-
#### `PropertySynchronizer.write`
|
|
580
|
-
|
|
581
|
-
```ts
|
|
582
|
-
function write(
|
|
583
|
-
value: T[PropKey],
|
|
584
|
-
options: PropertySynchronizer.WriteOptions<T, PropKey, WriteParamsT>
|
|
585
|
-
): Observable<any>
|
|
586
|
-
```
|
|
587
|
-
|
|
588
|
-
See [`Synchronizer.write`](#synchronizer.write).
|
|
589
|
-
|
|
590
|
-
## `CollectionSynchronizer`
|
|
591
|
-
|
|
592
|
-
Interface for declaring collection synchronizers, which manage all properties dynamically in a given state.
|
|
593
|
-
|
|
594
|
-
```ts
|
|
595
|
-
interface CollectionSynchronizer<
|
|
596
|
-
T,
|
|
597
|
-
ReadParamsT = never,
|
|
598
|
-
WriteParamsT = never
|
|
599
|
-
> extends Synchronizer<T, keyof T, ReadParamsT, WriteParamsT> {
|
|
600
|
-
|
|
601
|
-
read(
|
|
602
|
-
requiredDetails: Partial<T>,
|
|
603
|
-
options: CollectionSynchronizer.ReadOptions<T, ReadParamsT>
|
|
604
|
-
): Observable<T[keyof T]>;
|
|
605
|
-
|
|
606
|
-
write?(
|
|
607
|
-
value: T[keyof T],
|
|
608
|
-
options: CollectionSynchronizer.WriteOptions<T, WriteParamsT>
|
|
609
|
-
): Observable<any>;
|
|
610
|
-
}
|
|
611
|
-
```
|
|
612
|
-
|
|
613
|
-
### Interface methods
|
|
614
|
-
|
|
615
|
-
#### `CollectionSynchronizer.read`
|
|
616
|
-
|
|
617
|
-
```ts
|
|
618
|
-
function read(
|
|
619
|
-
requiredDetails: Partial<T>,
|
|
620
|
-
options: CollectionSynchronizer.ReadOptions<T, PropKey, ReadParamsT>
|
|
621
|
-
): Observable<T[PropKey]>
|
|
622
|
-
```
|
|
623
|
-
|
|
624
|
-
See [`Synchronizer.read`](#synchronizer.read).
|
|
625
|
-
|
|
626
|
-
#### `CollectionSynchronizer.write`
|
|
627
|
-
|
|
628
|
-
```ts
|
|
629
|
-
function write(
|
|
630
|
-
value: T[PropKey],
|
|
631
|
-
options: CollectionSynchronizer.WriteOptions<T, PropKey, WriteParamsT>
|
|
632
|
-
): Observable<any>
|
|
633
|
-
```
|
|
634
|
-
|
|
635
|
-
See [`Synchronizer.write`](#synchronizer.write).
|
|
636
|
-
|
|
637
|
-
## `StateSynchronizer`
|
|
638
|
-
|
|
639
|
-
Abstract class for declaring state synchronizers, which are a special kind of aggregate [`PropertySynchronizer`](#propertysynchronizer) that by default invoke all of the synchronizers defined for the given state.
|
|
640
|
-
|
|
641
|
-
```ts
|
|
642
|
-
abstract class StateSynchronizer<
|
|
643
|
-
T,
|
|
644
|
-
PropKey extends keyof T,
|
|
645
|
-
ReadParamsT = never,
|
|
646
|
-
WriteParamsT = never
|
|
647
|
-
> implements PropertySynchronizer<T, PropKey, ReadParamsT, WriteParamsT> {
|
|
648
|
-
|
|
649
|
-
constructor(
|
|
650
|
-
private readonly injector: Injector,
|
|
651
|
-
private readonly propertyState: SyncClass<T[PropKey]>
|
|
652
|
-
);
|
|
653
|
-
|
|
654
|
-
public read(
|
|
655
|
-
_requiredDetails: Partial<T>,
|
|
656
|
-
_options: PropertySynchronizer.ReadOptions<T, PropKey, ReadParamsT>
|
|
657
|
-
): Observable<T[PropKey]>;
|
|
658
|
-
|
|
659
|
-
protected readSubset(properties: Array<keyof T[PropKey]>): Observable<T[PropKey]>;
|
|
660
|
-
}
|
|
661
|
-
```
|
|
662
|
-
|
|
663
|
-
### Methods
|
|
664
|
-
|
|
665
|
-
#### `StateSynchronizer.constructor`
|
|
666
|
-
|
|
667
|
-
```ts
|
|
668
|
-
constructor(
|
|
669
|
-
private readonly injector: Injector,
|
|
670
|
-
private readonly propertyState: SyncClass<T[PropKey]>
|
|
671
|
-
)
|
|
672
|
-
```
|
|
673
|
-
|
|
674
|
-
`injector` - The Angular injector used to resolve state dependencies.
|
|
675
|
-
|
|
676
|
-
`propertyState` - The state class definition to invoke its synchronizer operations on.
|
|
677
|
-
|
|
678
|
-
#### `StateSynchronizer.read`
|
|
679
|
-
|
|
680
|
-
```ts
|
|
681
|
-
function read(
|
|
682
|
-
_requiredDetails: Partial<T>,
|
|
683
|
-
_options: PropertySynchronizer.ReadOptions<T, PropKey, ReadParamsT>
|
|
684
|
-
): Observable<T[PropKey]>
|
|
685
|
-
```
|
|
686
|
-
|
|
687
|
-
By default, invokes all of the synchronizers read operations defined for the given state.
|
|
688
|
-
|
|
689
|
-
`_requiredDetails` - Unused.
|
|
690
|
-
|
|
691
|
-
`_options` - Unused.
|
|
692
|
-
|
|
693
|
-
#### `StateSynchronizer.readSubset`
|
|
694
|
-
|
|
695
|
-
```ts
|
|
696
|
-
function readSubset(properties: Array<keyof T[PropKey]>): Observable<T[PropKey]>
|
|
697
|
-
```
|
|
698
|
-
|
|
699
|
-
Helper method for invoking the read synchronizer operation on a specific subset of properties. Can be used in conjunction with overriding [`read`](#statesynchronizer.read) to override the default behavior of the state synchronizer. Returns an observable that emits when all read operations have completed.
|
|
700
|
-
|
|
1
|
+
# ngxs-synchronizers API Reference
|
|
2
|
+
|
|
3
|
+
## `NgxsSyncModule`
|
|
4
|
+
|
|
5
|
+
The Angular module for this library.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
class NgxsSyncModule {}
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## `@SyncState`
|
|
12
|
+
|
|
13
|
+
The class decorator used to create state definitions. Wraps the `@State` decorator [from NGXS](https://www.ngxs.io/concepts/state).
|
|
14
|
+
|
|
15
|
+
See the [NGXS documentation](https://www.ngxs.io/concepts/state) for more information about `@State`.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
function SyncState<T>(options: SyncStoreOptions<T>): ClassDecorator
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`options` - The [`SyncStoreOptions`](#syncstoreoptions) used to define this state.
|
|
22
|
+
|
|
23
|
+
## `SyncStoreOptions`
|
|
24
|
+
|
|
25
|
+
Interface for defining a state via `@SyncState`.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
interface SyncStoreOptions<T> {
|
|
29
|
+
name: string;
|
|
30
|
+
defaults?: T;
|
|
31
|
+
children?: any[];
|
|
32
|
+
synchronizers?: SynchronizerDictionary<T>;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`name` - See [NGXS docs](https://www.ngxs.io/concepts/state).
|
|
37
|
+
|
|
38
|
+
`defaults` - See [NGXS docs](https://www.ngxs.io/concepts/state).
|
|
39
|
+
|
|
40
|
+
`children` - See [NGXS docs](https://www.ngxs.io/concepts/state).
|
|
41
|
+
|
|
42
|
+
`synchronizers` - The synchronizers for this state, declared as a [`SynchronizerDictionary`](#synchronizerdictionary).
|
|
43
|
+
|
|
44
|
+
## `SynchronizerDictionary`
|
|
45
|
+
|
|
46
|
+
A dictionary of synchronizers for a given state, which is either a record of property synchronizers or a single collection synchronizer.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
type SynchronizerDictionary<T> = {
|
|
50
|
+
[P in keyof T]?: Type<PropertySynchronizer<T, P>>;
|
|
51
|
+
} | Type<CollectionSynchronizer<T>>;
|
|
52
|
+
|
|
53
|
+
namespace SynchronizerDictionary {
|
|
54
|
+
|
|
55
|
+
function keys<T>(dict: SynchronizerDictionary<T>): Array<keyof T>;
|
|
56
|
+
|
|
57
|
+
function isCollectionSynchronizer<T>(
|
|
58
|
+
dict: SynchronizerDictionary<T>
|
|
59
|
+
): dict is Type<CollectionSynchronizer<T>>;
|
|
60
|
+
|
|
61
|
+
function resolveSynchronizer<T>(
|
|
62
|
+
dict: SynchronizerDictionary<T>,
|
|
63
|
+
propKey: keyof T
|
|
64
|
+
): Type<Synchronizer<T, keyof T, unknown, unknown>>;
|
|
65
|
+
|
|
66
|
+
function resolveSynchronizerInstance<T>(
|
|
67
|
+
injector: Injector,
|
|
68
|
+
dict: SynchronizerDictionary<T>,
|
|
69
|
+
propKey: keyof T
|
|
70
|
+
): Synchronizer<T, keyof T, unknown, unknown>;
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Namespace functions
|
|
75
|
+
|
|
76
|
+
#### `SynchronizerDictionary.keys`
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
function keys<T>(dict: SynchronizerDictionary<T>): Array<keyof T>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Returns the list of keys in the dictionary.
|
|
83
|
+
|
|
84
|
+
`dict` - The synchronizer dictionary.
|
|
85
|
+
|
|
86
|
+
#### `SynchronizerDictionary.isCollectionSynchronizer`
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
function isCollectionSynchronizer<T>(
|
|
90
|
+
dict: SynchronizerDictionary<T>
|
|
91
|
+
): dict is Type<CollectionSynchronizer<T>>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Returns whether or not the given dictionary is a [`CollectionSynchronizer`](#collectionsynchronizer).
|
|
95
|
+
|
|
96
|
+
`dict` - The synchronizer dictionary.
|
|
97
|
+
|
|
98
|
+
#### `SynchronizerDictionary.resolveSynchronizer`
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
function resolveSynchronizer<T>(
|
|
102
|
+
dict: SynchronizerDictionary<T>,
|
|
103
|
+
propKey: keyof T
|
|
104
|
+
): Type<Synchronizer<T, keyof T, unknown, unknown>>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Resolves the synchronizer associated with the property `propKey` from the dictionary (or the [`CollectionSynchronizer`](#collectionsynchronizer)).
|
|
108
|
+
|
|
109
|
+
`dict` - The synchronizer dictionary.
|
|
110
|
+
|
|
111
|
+
`propKey` - The property to resolve the synchronizer of.
|
|
112
|
+
|
|
113
|
+
#### `SynchronizerDictionary.resolveSynchronizerInstance`
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
function resolveSynchronizerInstance<T>(
|
|
117
|
+
injector: Injector,
|
|
118
|
+
dict: SynchronizerDictionary<T>,
|
|
119
|
+
propKey: keyof T
|
|
120
|
+
): Synchronizer<T, keyof T, unknown, unknown>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Resolves a synchronizer instance associated with the property `propKey` from the dictionary (or the [`CollectionSynchronizer`](#collectionsynchronizer)).
|
|
124
|
+
|
|
125
|
+
`injector` - The Angular injector.
|
|
126
|
+
|
|
127
|
+
`dict` - The synchronizer dictionary.
|
|
128
|
+
|
|
129
|
+
`propKey` - The property to resolve the synchronizer instance of.
|
|
130
|
+
|
|
131
|
+
## `SyncStore`
|
|
132
|
+
|
|
133
|
+
A global state manager for interacting with synchronizers. Extends the `Store` class [from NGXS](https://www.ngxs.io/concepts/store).
|
|
134
|
+
|
|
135
|
+
See the [NGXS documentation](https://www.ngxs.io/concepts/store) for more information about `Store`.
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
class SyncStore extends Store {
|
|
139
|
+
|
|
140
|
+
public state<T>(syncState: SyncClass<T>): StateSelector<T>;
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Methods
|
|
145
|
+
|
|
146
|
+
#### `SyncStore.state`
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
function state<T>(syncState: SyncClass<T>): StateSelector<T>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Method used for obtaining a [`StateSelector`](#stateselector) instance for a given [`SyncClass`](#syncclass). `StateSelector` instances are cached so that the same instance will be used for each `SyncClass` type. If the given `syncState` is not a known state, the method will return `null`.
|
|
153
|
+
|
|
154
|
+
```syncState``` - The state class to obtain a [`StateSelector`](#stateselector) for.
|
|
155
|
+
|
|
156
|
+
## `SyncClass`
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
import { Type } from '@angular/core';
|
|
160
|
+
|
|
161
|
+
type SyncClass<T> = Type<T>;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## `StateSelector`
|
|
165
|
+
|
|
166
|
+
Used to manage synchronizers and synchronization state. `StateSelector` objects are unique to a specific state class.
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
class StateSelector<T> {
|
|
170
|
+
|
|
171
|
+
public dispatch<PropT extends keyof T>(propertyName: PropT, value: T[PropT]): Observable<T>;
|
|
172
|
+
|
|
173
|
+
public property<PropT extends keyof T>(propertyName: PropT): Observable<T[PropT]>;
|
|
174
|
+
public properties(): Observable<T>;
|
|
175
|
+
public definedProperty<PropT extends keyof T>(propertyName: PropT): Observable<T[PropT]>;
|
|
176
|
+
|
|
177
|
+
public isSyncingProperty(propertyName: keyof T): Observable<boolean>;
|
|
178
|
+
public onPropertySyncing<PropT extends keyof T>(propertyName: PropT): Observable<PropT>;
|
|
179
|
+
public onPropertySynced<PropT extends keyof T>(propertyName: PropT): Observable<PropT>;
|
|
180
|
+
public onEveryPropertySyncing(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>;
|
|
181
|
+
public onEveryPropertySynced(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>;
|
|
182
|
+
public onSomePropertySyncing(...propertyNames: Array<keyof T>): Observable<keyof T>;
|
|
183
|
+
public onSomePropertySynced(...propertyNames: Array<keyof T>): Observable<keyof T>;
|
|
184
|
+
|
|
185
|
+
public require<RequestParamsT = never>(
|
|
186
|
+
propertyNames: keyof T | Array<keyof T>,
|
|
187
|
+
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
188
|
+
): Observable<T>;
|
|
189
|
+
|
|
190
|
+
public requireProperty<PropT extends keyof T, RequestParamsT = never>(
|
|
191
|
+
propertyName: PropT,
|
|
192
|
+
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
193
|
+
): Observable<T[PropT]>;
|
|
194
|
+
|
|
195
|
+
public sync<RequestParamsT = never>(
|
|
196
|
+
propertyNames: keyof T | Array<keyof T>,
|
|
197
|
+
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
198
|
+
): Observable<T>;
|
|
199
|
+
|
|
200
|
+
public syncProperty<PropT extends keyof T, RequestParamsT = never>(
|
|
201
|
+
propertyName: PropT,
|
|
202
|
+
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
203
|
+
): Observable<T[PropT]>;
|
|
204
|
+
|
|
205
|
+
public export<RequestParamsT = never>(
|
|
206
|
+
propertyNames: keyof T | Array<keyof T>,
|
|
207
|
+
options?: Synchronizer.WriteOptions<RequestParamsT>
|
|
208
|
+
): Observable<any>;
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Methods
|
|
213
|
+
|
|
214
|
+
#### `StateSelector.dispatch`
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
function dispatch<PropT extends keyof T>(propertyName: PropT, value: T[PropT]): Observable<T>
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Dispatches an action that updates the property `propertyName` to the given `value`. Returns an observable that emits after all actions have completed.
|
|
221
|
+
|
|
222
|
+
`propertyName` - The name of the property to update.
|
|
223
|
+
|
|
224
|
+
`value` - The value to set the property to.
|
|
225
|
+
|
|
226
|
+
#### `StateSelector.property`
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
function property<PropT extends keyof T>(propertyName: PropT): Observable<T[PropT]>
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Returns an observable that emits the value of the property `propertyName`. This observable will emit every time the property's value changes.
|
|
233
|
+
|
|
234
|
+
`propertyName` - The name of the property to observe.
|
|
235
|
+
|
|
236
|
+
#### `StateSelector.properties`
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
function properties(): Observable<T>
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Returns an observable that emits the current state value. This observable will emit every time the state is updated.
|
|
243
|
+
|
|
244
|
+
#### `StateSelector.definedProperty`
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
function definedProperty<PropT extends keyof T>(propertyName: PropT): Observable<T[PropT]>
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Returns an observable that emits the value of the property `propertyName` only if the value is not `null` or `undefined`. This observable will emit every time the property's value changes and is not `null` or `undefined`.
|
|
251
|
+
|
|
252
|
+
`propertyName` - The name of the property to observe.
|
|
253
|
+
|
|
254
|
+
#### `StateSelector.isSyncingProperty`
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
function isSyncingProperty(propertyName: keyof T): Observable<boolean>
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Returns an observable that emits whether or not the property `propertyName` is being synchronized. This observable will emit every time the property's synchronization state changes.
|
|
261
|
+
|
|
262
|
+
`propertyName` - The name of the property to observe the synchronization state of.
|
|
263
|
+
|
|
264
|
+
#### `StateSelector.onPropertySyncing`
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
function onPropertySyncing<PropT extends keyof T>(propertyName: PropT): Observable<PropT>
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Returns an observable that emits whenever the property `propertyName` is starting to be synchronized. This observable will emit every time the property is starting to be synchronized. The returned observable will emit `propertyName`.
|
|
271
|
+
|
|
272
|
+
`propertyName` - The name of the property to observe the synchronization state of.
|
|
273
|
+
|
|
274
|
+
#### `StateSelector.onPropertySynced`
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
function onPropertySynced<PropT extends keyof T>(propertyName: PropT): Observable<PropT>
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Returns an observable that emits whenever the property `propertyName` is completed being synchronized. This observable will emit every time the property is completed being synchronized. The returned observable will emit `propertyName`.
|
|
281
|
+
|
|
282
|
+
`propertyName` - The name of the property to observe the synchronization state of.
|
|
283
|
+
|
|
284
|
+
#### `StateSelector.onEveryPropertySyncing`
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
function onEveryPropertySyncing(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Returns an observable that emits whenever all of the given properties in `propertyNames` are starting to be synchronized. This observable will emit every time all of the given properties are starting to be synchronized. The returned observable will emit an array of property names that are being synchronized.
|
|
291
|
+
|
|
292
|
+
`propertyNames` - The names of the properties to observe the synchronization states of.
|
|
293
|
+
|
|
294
|
+
#### `StateSelector.onEveryPropertySynced`
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
function onEveryPropertySynced(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Returns an observable that emits whenever all of the given properties in `propertyNames` are completed being synchronized. This observable will emit every time all of the given properties are completed being synchronized. The returned observable will emit an array of property names that are completed being synchronized.
|
|
301
|
+
|
|
302
|
+
`propertyNames` - The names of the properties to observe the synchronization states of.
|
|
303
|
+
|
|
304
|
+
#### `StateSelector.onSomePropertySyncing`
|
|
305
|
+
|
|
306
|
+
```ts
|
|
307
|
+
function onSomePropertySyncing(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Returns an observable that emits whenever any of the given properties in `propertyNames` is starting to be synchronized. This observable will emit every time any of the given properties is starting to be synchronized. The returned observable will emit an array of property names that are being synchronized.
|
|
311
|
+
|
|
312
|
+
`propertyNames` - The names of the properties to observe the synchronization states of.
|
|
313
|
+
|
|
314
|
+
#### `StateSelector.onSomePropertySynced`
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
function onSomePropertySynced(...propertyNames: Array<keyof T>): Observable<Array<keyof T>>
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Returns an observable that emits whenever any of the given properties in `propertyNames` is completed being synchronized. This observable will emit every time any of the given properties is completed being synchronized. The returned observable will emit an array of property names that are completed being synchronized.
|
|
321
|
+
|
|
322
|
+
`propertyNames` - The names of the properties to observe the synchronization states of.
|
|
323
|
+
|
|
324
|
+
#### `StateSelector.require`
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
function require<RequestParamsT = never>(
|
|
328
|
+
propertyNames: keyof T | Array<keyof T>,
|
|
329
|
+
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
330
|
+
): Observable<T>
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Conditionally invokes the read operation for the synchronizers of the given properties in `propertyNames` only if the property value is not yet defined. Returns an observable that emits the value of the state after the invoked synchronizer operations are completed, or the current property value if it was defined.
|
|
334
|
+
|
|
335
|
+
`propertyNames` - The names of the properties (or single property) to conditionally invoke the read operation of their synchronizer(s) on.
|
|
336
|
+
|
|
337
|
+
`options` - (Optional) The [`Synchronizer.ReadOptions`](#synchronizer.readoptions) to pass to each synchronizer's read operation when invoked.
|
|
338
|
+
|
|
339
|
+
See [`Synchronizer.read`](#synchronizer.read) for more information.
|
|
340
|
+
|
|
341
|
+
#### `StateSelector.requireProperty`
|
|
342
|
+
|
|
343
|
+
```ts
|
|
344
|
+
function requireProperty<PropT extends keyof T, RequestParamsT = never>(
|
|
345
|
+
propertyName: PropT,
|
|
346
|
+
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
347
|
+
): Observable<T[PropT]>
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
Conditionally invokes the read operation for the synchronizer of the given property `propertyName` only if the property value is not yet defined. Returns an observable that emits the value of the property after the invoked synchronizer operation is completed, or the current property value if it was defined.
|
|
351
|
+
|
|
352
|
+
`propertyName` - The name of the property to conditionally invoke the read operation of its synchronizer on.
|
|
353
|
+
|
|
354
|
+
`options` - (Optional) The [`Synchronizer.ReadOptions`](#synchronizer.readoptions) to pass to the synchronizer's read operation when invoked.
|
|
355
|
+
|
|
356
|
+
See [`Synchronizer.read`](#synchronizer.read) for more information.
|
|
357
|
+
|
|
358
|
+
#### `StateSelector.sync`
|
|
359
|
+
|
|
360
|
+
```ts
|
|
361
|
+
function sync<RequestParamsT = never>(
|
|
362
|
+
propertyNames: keyof T | Array<keyof T>,
|
|
363
|
+
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
364
|
+
): Observable<T>
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Invokes the read operation for the synchronizers of the given properties in `propertyNames`. Returns an observable that emits the value of the state after the invoked synchronizer operations are completed.
|
|
368
|
+
|
|
369
|
+
`propertyNames` - The names of the properties (or single property) to invoke the read operation of their synchronizer(s) on.
|
|
370
|
+
|
|
371
|
+
`options` - (Optional) The [`Synchronizer.ReadOptions`](#synchronizer.readoptions) to pass to each synchronizer's read operation when invoked.
|
|
372
|
+
|
|
373
|
+
See [`Synchronizer.read`](#synchronizer.read) for more information.
|
|
374
|
+
|
|
375
|
+
#### `StateSelector.syncProperty`
|
|
376
|
+
|
|
377
|
+
```ts
|
|
378
|
+
function syncProperty<PropT extends keyof T, RequestParamsT = never>(
|
|
379
|
+
propertyName: PropT,
|
|
380
|
+
options?: Synchronizer.ReadOptions<RequestParamsT>
|
|
381
|
+
): Observable<T[PropT]>
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
Invokes the read operation for the synchronizer of the given property `propertyName`. Returns an observable that emits the value of the property after the invoked synchronizer operation is completed.
|
|
385
|
+
|
|
386
|
+
`propertyName` - The name of the property to invoke the read operation of its synchronizer on.
|
|
387
|
+
|
|
388
|
+
`options` - (Optional) The [`Synchronizer.ReadOptions`](#synchronizer.readoptions) to pass to the synchronizer's read operation when invoked.
|
|
389
|
+
|
|
390
|
+
See [`Synchronizer.read`](#synchronizer.read) for more information.
|
|
391
|
+
|
|
392
|
+
#### `StateSelector.export`
|
|
393
|
+
|
|
394
|
+
```ts
|
|
395
|
+
function export<RequestParamsT = never>(
|
|
396
|
+
propertyNames: keyof T | Array<keyof T>,
|
|
397
|
+
options?: Synchronizer.WriteOptions<RequestParamsT>
|
|
398
|
+
): Observable<any>
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Invokes the write operation for the synchronizers of the given properties in `propertyNames`. Returns an observable that emits the combined response value after the invoked synchronizer operations are completed.
|
|
402
|
+
|
|
403
|
+
`propertyNames` - The names of the properties (or single property) to invoke the write operation of their synchronizer(s) on.
|
|
404
|
+
|
|
405
|
+
`options` - (Optional) The [`Synchronizer.WriteOptions`](#synchronizer.writeoptions) to pass to each synchronizer's write operation when invoked.
|
|
406
|
+
|
|
407
|
+
See [`Synchronizer.write`](#synchronizer.write) for more information.
|
|
408
|
+
|
|
409
|
+
## `Synchronizer`
|
|
410
|
+
|
|
411
|
+
Base interface for all synchronizers.
|
|
412
|
+
|
|
413
|
+
```ts
|
|
414
|
+
interface Synchronizer<
|
|
415
|
+
T,
|
|
416
|
+
PropKey extends keyof T,
|
|
417
|
+
ReadParamsT,
|
|
418
|
+
WriteParamsT
|
|
419
|
+
> {
|
|
420
|
+
requiredProperties?: Array<keyof T>;
|
|
421
|
+
proxy?: boolean;
|
|
422
|
+
|
|
423
|
+
read(
|
|
424
|
+
requiredDetails: Partial<T>,
|
|
425
|
+
options: Synchronizer.BaseOptions<T, PropKey, ReadParamsT> & Synchronizer.ReadOptions<ReadParamsT>
|
|
426
|
+
): Observable<T[PropKey]>;
|
|
427
|
+
|
|
428
|
+
write?(
|
|
429
|
+
value: T[PropKey],
|
|
430
|
+
options: Synchronizer.BaseOptions<T, PropKey, WriteParamsT> & Synchronizer.WriteOptions<WriteParamsT>
|
|
431
|
+
): Observable<any>;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
namespace Synchronizer {
|
|
435
|
+
|
|
436
|
+
interface BaseOptions<
|
|
437
|
+
T,
|
|
438
|
+
PropKey extends keyof T,
|
|
439
|
+
ParamsT
|
|
440
|
+
> {
|
|
441
|
+
propertyName: PropKey;
|
|
442
|
+
requestParams?: ParamsT;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
interface ReadOptions<ParamsT> {
|
|
446
|
+
clearStore?: boolean;
|
|
447
|
+
requestParams?: ParamsT;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
interface WriteOptions<ParamsT> {
|
|
451
|
+
requestParams?: ParamsT;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
### Interface properties
|
|
457
|
+
|
|
458
|
+
`requiredProperties` - (Optional) The list of properties that are required to be defined before this synchronizer's read operation is invoked. If any of the given properties has its own synchronizer, it's read operation will be completed before invoking this synchronizer if its value is not yet defined (or if this is a proxy synchronizer).
|
|
459
|
+
|
|
460
|
+
`proxy` - (Optional) Whether or not this is a proxy synchronizer. A proxy synchronizer is a synchronizer that does not make its own requests, but simply transforms the state of other synchronized values. A proxy synchronizer's `requiredProperties` will always have their synchronizer's invoked when the proxy synchronizer itself is invoked. Defaults to `false`.
|
|
461
|
+
|
|
462
|
+
### Interface methods
|
|
463
|
+
|
|
464
|
+
#### `Synchronizer.read`
|
|
465
|
+
|
|
466
|
+
```ts
|
|
467
|
+
function read(
|
|
468
|
+
requiredDetails: Partial<T>,
|
|
469
|
+
options: Synchronizer.BaseOptions<T, PropKey, ReadParamsT> & Synchronizer.ReadOptions<ReadParamsT>
|
|
470
|
+
): Observable<T[PropKey]>
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
The read operation of the synchronizer, used to retrieve a value from a remote data store. Returns an observable that emits the value retrieved from the remote data store.
|
|
474
|
+
|
|
475
|
+
`requiredDetails` - A partial list of state values corresponding to the properties defined in `requiredProperties`. Empty if no `requiredProperties` were defined.
|
|
476
|
+
|
|
477
|
+
`options` - The [`Synchronizer.ReadOptions`](#synchronizer.readoptions) to use for this operation.
|
|
478
|
+
|
|
479
|
+
#### `Synchronizer.write`
|
|
480
|
+
|
|
481
|
+
```ts
|
|
482
|
+
function write(
|
|
483
|
+
value: T[PropKey],
|
|
484
|
+
options: Synchronizer.BaseOptions<T, PropKey, WriteParamsT> & Synchronizer.WriteOptions<WriteParamsT>
|
|
485
|
+
): Observable<any>
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
(Optional) The write operation of the synchronizer, used to send a value to a remote data store. Returns an observable that emits the response (if any) from the remote data store after the write operation is complete.
|
|
489
|
+
|
|
490
|
+
`value` - The value to write to the remote data store.
|
|
491
|
+
|
|
492
|
+
`options` - The [`Synchronizer.WriteOptions`](#synchronizer.writeoptions) to use for this operation.
|
|
493
|
+
|
|
494
|
+
### Namespace functions
|
|
495
|
+
|
|
496
|
+
#### `Synchronizer.BaseOptions`
|
|
497
|
+
|
|
498
|
+
```ts
|
|
499
|
+
interface BaseOptions<
|
|
500
|
+
T,
|
|
501
|
+
PropKey extends keyof T,
|
|
502
|
+
ParamsT
|
|
503
|
+
> {
|
|
504
|
+
propertyName: PropKey;
|
|
505
|
+
requestParams?: ParamsT;
|
|
506
|
+
}
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
The base interface for all [`Synchronizer`](#synchronizer) operations.
|
|
510
|
+
|
|
511
|
+
`propertyName` - The name of the state property involved in the current operation.
|
|
512
|
+
|
|
513
|
+
`requestParams` - (Optional) Any request params to be passed to the remote data store.
|
|
514
|
+
|
|
515
|
+
#### `Synchronizer.ReadOptions`
|
|
516
|
+
|
|
517
|
+
```ts
|
|
518
|
+
interface ReadOptions<ParamsT> {
|
|
519
|
+
clearStore?: boolean;
|
|
520
|
+
requestParams?: ParamsT;
|
|
521
|
+
}
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
The interface for all [`Synchronizer`](#synchronizer) read operations.
|
|
525
|
+
|
|
526
|
+
`clearStore` - (Optional) Whether or not the current property value should be cleared before invoking the read operation.
|
|
527
|
+
|
|
528
|
+
`requestParams` - (Optional) Any request params to be passed to the remote data store.
|
|
529
|
+
|
|
530
|
+
#### `Synchronizer.WriteOptions`
|
|
531
|
+
|
|
532
|
+
```ts
|
|
533
|
+
interface WriteOptions<ParamsT> {
|
|
534
|
+
requestParams?: ParamsT;
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
The interface for all [`Synchronizer`](#synchronizer) write operations.
|
|
539
|
+
|
|
540
|
+
`requestParams` - (Optional) Any request params to be passed to the remote data store.
|
|
541
|
+
|
|
542
|
+
## `PropertySynchronizer`
|
|
543
|
+
|
|
544
|
+
Interface for declaring property synchronizers, which are linked to a specific state property.
|
|
545
|
+
|
|
546
|
+
```ts
|
|
547
|
+
interface PropertySynchronizer<
|
|
548
|
+
T,
|
|
549
|
+
PropKey extends keyof T,
|
|
550
|
+
ReadParamsT = never,
|
|
551
|
+
WriteParamsT = never
|
|
552
|
+
> extends Synchronizer<T, PropKey, ReadParamsT, WriteParamsT> {
|
|
553
|
+
|
|
554
|
+
read(
|
|
555
|
+
requiredDetails: Partial<T>,
|
|
556
|
+
options: PropertySynchronizer.ReadOptions<T, PropKey, ReadParamsT>
|
|
557
|
+
): Observable<T[PropKey]>;
|
|
558
|
+
|
|
559
|
+
write?(
|
|
560
|
+
value: T[PropKey],
|
|
561
|
+
options: PropertySynchronizer.WriteOptions<T, PropKey, WriteParamsT>
|
|
562
|
+
): Observable<any>;
|
|
563
|
+
}
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
### Interface methods
|
|
567
|
+
|
|
568
|
+
#### `PropertySynchronizer.read`
|
|
569
|
+
|
|
570
|
+
```ts
|
|
571
|
+
function read(
|
|
572
|
+
requiredDetails: Partial<T>,
|
|
573
|
+
options: PropertySynchronizer.ReadOptions<T, PropKey, ReadParamsT>
|
|
574
|
+
): Observable<T[PropKey]>
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
See [`Synchronizer.read`](#synchronizer.read).
|
|
578
|
+
|
|
579
|
+
#### `PropertySynchronizer.write`
|
|
580
|
+
|
|
581
|
+
```ts
|
|
582
|
+
function write(
|
|
583
|
+
value: T[PropKey],
|
|
584
|
+
options: PropertySynchronizer.WriteOptions<T, PropKey, WriteParamsT>
|
|
585
|
+
): Observable<any>
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
See [`Synchronizer.write`](#synchronizer.write).
|
|
589
|
+
|
|
590
|
+
## `CollectionSynchronizer`
|
|
591
|
+
|
|
592
|
+
Interface for declaring collection synchronizers, which manage all properties dynamically in a given state.
|
|
593
|
+
|
|
594
|
+
```ts
|
|
595
|
+
interface CollectionSynchronizer<
|
|
596
|
+
T,
|
|
597
|
+
ReadParamsT = never,
|
|
598
|
+
WriteParamsT = never
|
|
599
|
+
> extends Synchronizer<T, keyof T, ReadParamsT, WriteParamsT> {
|
|
600
|
+
|
|
601
|
+
read(
|
|
602
|
+
requiredDetails: Partial<T>,
|
|
603
|
+
options: CollectionSynchronizer.ReadOptions<T, ReadParamsT>
|
|
604
|
+
): Observable<T[keyof T]>;
|
|
605
|
+
|
|
606
|
+
write?(
|
|
607
|
+
value: T[keyof T],
|
|
608
|
+
options: CollectionSynchronizer.WriteOptions<T, WriteParamsT>
|
|
609
|
+
): Observable<any>;
|
|
610
|
+
}
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
### Interface methods
|
|
614
|
+
|
|
615
|
+
#### `CollectionSynchronizer.read`
|
|
616
|
+
|
|
617
|
+
```ts
|
|
618
|
+
function read(
|
|
619
|
+
requiredDetails: Partial<T>,
|
|
620
|
+
options: CollectionSynchronizer.ReadOptions<T, PropKey, ReadParamsT>
|
|
621
|
+
): Observable<T[PropKey]>
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
See [`Synchronizer.read`](#synchronizer.read).
|
|
625
|
+
|
|
626
|
+
#### `CollectionSynchronizer.write`
|
|
627
|
+
|
|
628
|
+
```ts
|
|
629
|
+
function write(
|
|
630
|
+
value: T[PropKey],
|
|
631
|
+
options: CollectionSynchronizer.WriteOptions<T, PropKey, WriteParamsT>
|
|
632
|
+
): Observable<any>
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
See [`Synchronizer.write`](#synchronizer.write).
|
|
636
|
+
|
|
637
|
+
## `StateSynchronizer`
|
|
638
|
+
|
|
639
|
+
Abstract class for declaring state synchronizers, which are a special kind of aggregate [`PropertySynchronizer`](#propertysynchronizer) that by default invoke all of the synchronizers defined for the given state.
|
|
640
|
+
|
|
641
|
+
```ts
|
|
642
|
+
abstract class StateSynchronizer<
|
|
643
|
+
T,
|
|
644
|
+
PropKey extends keyof T,
|
|
645
|
+
ReadParamsT = never,
|
|
646
|
+
WriteParamsT = never
|
|
647
|
+
> implements PropertySynchronizer<T, PropKey, ReadParamsT, WriteParamsT> {
|
|
648
|
+
|
|
649
|
+
constructor(
|
|
650
|
+
private readonly injector: Injector,
|
|
651
|
+
private readonly propertyState: SyncClass<T[PropKey]>
|
|
652
|
+
);
|
|
653
|
+
|
|
654
|
+
public read(
|
|
655
|
+
_requiredDetails: Partial<T>,
|
|
656
|
+
_options: PropertySynchronizer.ReadOptions<T, PropKey, ReadParamsT>
|
|
657
|
+
): Observable<T[PropKey]>;
|
|
658
|
+
|
|
659
|
+
protected readSubset(properties: Array<keyof T[PropKey]>): Observable<T[PropKey]>;
|
|
660
|
+
}
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
### Methods
|
|
664
|
+
|
|
665
|
+
#### `StateSynchronizer.constructor`
|
|
666
|
+
|
|
667
|
+
```ts
|
|
668
|
+
constructor(
|
|
669
|
+
private readonly injector: Injector,
|
|
670
|
+
private readonly propertyState: SyncClass<T[PropKey]>
|
|
671
|
+
)
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
`injector` - The Angular injector used to resolve state dependencies.
|
|
675
|
+
|
|
676
|
+
`propertyState` - The state class definition to invoke its synchronizer operations on.
|
|
677
|
+
|
|
678
|
+
#### `StateSynchronizer.read`
|
|
679
|
+
|
|
680
|
+
```ts
|
|
681
|
+
function read(
|
|
682
|
+
_requiredDetails: Partial<T>,
|
|
683
|
+
_options: PropertySynchronizer.ReadOptions<T, PropKey, ReadParamsT>
|
|
684
|
+
): Observable<T[PropKey]>
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
By default, invokes all of the synchronizers read operations defined for the given state.
|
|
688
|
+
|
|
689
|
+
`_requiredDetails` - Unused.
|
|
690
|
+
|
|
691
|
+
`_options` - Unused.
|
|
692
|
+
|
|
693
|
+
#### `StateSynchronizer.readSubset`
|
|
694
|
+
|
|
695
|
+
```ts
|
|
696
|
+
function readSubset(properties: Array<keyof T[PropKey]>): Observable<T[PropKey]>
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
Helper method for invoking the read synchronizer operation on a specific subset of properties. Can be used in conjunction with overriding [`read`](#statesynchronizer.read) to override the default behavior of the state synchronizer. Returns an observable that emits when all read operations have completed.
|
|
700
|
+
|
|
701
701
|
`properties` - The list of properties that will have their read synchronizer operation invoked.
|