@@ -405,6 +405,10 @@ export class RxState<State extends object>
405
405
* Connect a `Signal<Partial<State>>` to the state `State`.
406
406
* Any change emitted by the source will get merged into the state.
407
407
*
408
+ * @example
409
+ * const partialState = signal({ foo: 'foo', bar: 5 });
410
+ * state.connect(partialState);
411
+ *
408
412
* @param {Signal<Partial<State>> } signal
409
413
* @return void
410
414
*/
@@ -422,6 +426,7 @@ export class RxState<State extends object>
422
426
* const sliceToAdd$ = interval(250);
423
427
* state.connect(sliceToAdd$, (type, value) => ({bar: value}));
424
428
* // every 250ms the property bar get updated due to the emission of sliceToAdd$
429
+ *
425
430
* @param {Observable<Value> } inputOrSlice$
426
431
* @param {ProjectStateReducer<State, Value> } projectFn
427
432
* @return void
@@ -437,6 +442,11 @@ export class RxState<State extends object>
437
442
* Any change emitted by the source will get forwarded to the project function and merged into the state.
438
443
*
439
444
* You have to provide a `projectionFunction` to access the current state object and do custom mappings.
445
+ *
446
+ * @example
447
+ * const signalSlice = signal(5);
448
+ * state.connect(signalSlice, (type, value) => ({bar: value}));
449
+ *
440
450
* @param {Signal<Value> } signal
441
451
* @param {ProjectStateReducer<State, Value> } projectFn
442
452
* @return void
@@ -472,6 +482,11 @@ export class RxState<State extends object>
472
482
* @description
473
483
* Connect a `Signal<State[Key]>` source to a specific property `Key` in the state `State`.
474
484
* Any emitted change will update this specific property in the state.
485
+ *
486
+ * @example
487
+ * const currentTime = signal(Date.now())
488
+ * state.connect('currentTime', currentTime);
489
+ *
475
490
* @param {Key } key
476
491
* @param {Signal<State[Key]> } signal
477
492
*
@@ -490,6 +505,7 @@ export class RxState<State extends object>
490
505
* const myTimer$ = interval(250);
491
506
* state.connect('timer', myTimer$, (state, timerChange) => state.timer += timerChange);
492
507
* // every 250ms the property timer will get updated
508
+ *
493
509
* @param {Key } key
494
510
* @param {Observable<Value> } input$
495
511
* @param {ProjectValueReducer<State, Key, Value> } projectSliceFn
@@ -509,6 +525,11 @@ export class RxState<State extends object>
509
525
* `projectionFunction` to access the current state object on every emission of your connected `Observable`.
510
526
* Any change emitted by the source will get merged into the state.
511
527
* Subscription handling is done automatically.
528
+ *
529
+ * @example
530
+ * const currentTime = signal(Date.now())
531
+ * state.connect('currentTime', currentTime, (state, currentTime) => state.currentTime = currentTime);
532
+ *
512
533
* @param {Key } key
513
534
* @param {Signal<Value> } signal
514
535
* @param {ProjectValueReducer<State, Key, Value> } projectSliceFn
@@ -874,6 +895,10 @@ export class RxState<State extends object>
874
895
* Returns a signal of the given key. It's first value is determined by the
875
896
* current keys value in RxState. Whenever the key gets updated, the signal
876
897
* will also be updated accordingly.
898
+ *
899
+ * @example
900
+ * const fooSignal = state.signal('foo');
901
+ *
877
902
* @param {Key } key
878
903
*
879
904
* @return Signal<State[Key]>
@@ -886,6 +911,9 @@ export class RxState<State extends object>
886
911
* @description
887
912
* Lets you create a computed signal based off multiple keys stored in RxState.
888
913
*
914
+ * @example
915
+ * const computedSignal = state.computed((s) => s.foo + s.bar);
916
+ *
889
917
* @param {(slice: SignalStateProxy<Type>) => ComputedType } fn
890
918
* @return Signal<ComputedType>
891
919
*/
@@ -904,8 +932,14 @@ export class RxState<State extends object>
904
932
* @throws If the initial value is not provided and the signal is not sync.
905
933
* Use startWith() to provide an initial value.
906
934
*
907
- // * @param op1 { OperatorFunction<Type, TypeA> }
908
- // * @returns Signal<TypeA>
935
+ * @example
936
+ * const computedSignal = state.computedFrom(
937
+ * map(state => state.foo),
938
+ * filter(foo => foo > 5)
939
+ * );
940
+ *
941
+ * @param op1 { OperatorFunction<Type, TypeA> }
942
+ * @returns Signal<TypeA>
909
943
*/
910
944
computedFrom < TypeA = State > (
911
945
op1 : OperatorFunction < State , TypeA > ,
0 commit comments