Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad786d7

Browse files
authored
Merge pull request rx-angular#1724 from mikelgo/improve-rx-state-js-docs
docs(state): improve jsdocs
2 parents ea44fc1 + 45c0823 commit ad786d7

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

libs/state/src/lib/rx-state.service.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ export class RxState<State extends object>
405405
* Connect a `Signal<Partial<State>>` to the state `State`.
406406
* Any change emitted by the source will get merged into the state.
407407
*
408+
* @example
409+
* const partialState = signal({ foo: 'foo', bar: 5 });
410+
* state.connect(partialState);
411+
*
408412
* @param {Signal<Partial<State>>} signal
409413
* @return void
410414
*/
@@ -422,6 +426,7 @@ export class RxState<State extends object>
422426
* const sliceToAdd$ = interval(250);
423427
* state.connect(sliceToAdd$, (type, value) => ({bar: value}));
424428
* // every 250ms the property bar get updated due to the emission of sliceToAdd$
429+
*
425430
* @param {Observable<Value>} inputOrSlice$
426431
* @param {ProjectStateReducer<State, Value>} projectFn
427432
* @return void
@@ -437,6 +442,11 @@ export class RxState<State extends object>
437442
* Any change emitted by the source will get forwarded to the project function and merged into the state.
438443
*
439444
* 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+
*
440450
* @param {Signal<Value>} signal
441451
* @param {ProjectStateReducer<State, Value>} projectFn
442452
* @return void
@@ -472,6 +482,11 @@ export class RxState<State extends object>
472482
* @description
473483
* Connect a `Signal<State[Key]>` source to a specific property `Key` in the state `State`.
474484
* 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+
*
475490
* @param {Key} key
476491
* @param {Signal<State[Key]>} signal
477492
*
@@ -490,6 +505,7 @@ export class RxState<State extends object>
490505
* const myTimer$ = interval(250);
491506
* state.connect('timer', myTimer$, (state, timerChange) => state.timer += timerChange);
492507
* // every 250ms the property timer will get updated
508+
*
493509
* @param {Key} key
494510
* @param {Observable<Value>} input$
495511
* @param {ProjectValueReducer<State, Key, Value>} projectSliceFn
@@ -509,6 +525,11 @@ export class RxState<State extends object>
509525
* `projectionFunction` to access the current state object on every emission of your connected `Observable`.
510526
* Any change emitted by the source will get merged into the state.
511527
* 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+
*
512533
* @param {Key} key
513534
* @param {Signal<Value>} signal
514535
* @param {ProjectValueReducer<State, Key, Value>} projectSliceFn
@@ -874,6 +895,10 @@ export class RxState<State extends object>
874895
* Returns a signal of the given key. It's first value is determined by the
875896
* current keys value in RxState. Whenever the key gets updated, the signal
876897
* will also be updated accordingly.
898+
*
899+
* @example
900+
* const fooSignal = state.signal('foo');
901+
*
877902
* @param {Key} key
878903
*
879904
* @return Signal<State[Key]>
@@ -886,6 +911,9 @@ export class RxState<State extends object>
886911
* @description
887912
* Lets you create a computed signal based off multiple keys stored in RxState.
888913
*
914+
* @example
915+
* const computedSignal = state.computed((s) => s.foo + s.bar);
916+
*
889917
* @param {(slice: SignalStateProxy<Type>) => ComputedType} fn
890918
* @return Signal<ComputedType>
891919
*/
@@ -904,8 +932,14 @@ export class RxState<State extends object>
904932
* @throws If the initial value is not provided and the signal is not sync.
905933
* Use startWith() to provide an initial value.
906934
*
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>
909943
*/
910944
computedFrom<TypeA = State>(
911945
op1: OperatorFunction<State, TypeA>,

0 commit comments

Comments
 (0)