Skip to content

Commit 0c946e6

Browse files
committed
refactor(state): add js docs
1 parent 54d33e7 commit 0c946e6

File tree

1 file changed

+15
-28
lines changed

1 file changed

+15
-28
lines changed

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

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,33 @@ import {
1414
import { actionProxyHandler } from './proxy';
1515

1616
/**
17-
* Returns a object based off of the provided typing with a separate setter `[prop](value: T[K]): void` and observable stream `[prop]$: Observable<T[K]>`;
18-
*
19-
* { search: string } => { search$: Observable<string>, search: (value: string) => void;}
17+
* Manage events in components and services in a single place
2018
*
2119
* @example
2220
*
23-
* interface UIActions {
21+
* interface UI {
2422
* search: string,
2523
* submit: void
2624
* };
2725
*
28-
* const actions = new RxActionFactory<UIActions>().create();
29-
*
30-
* actions.search($event.target.value);
31-
* actions.search$.subscribe();
26+
* import { rxActions } from '@rx-angular/state/actions';
3227
*
33-
* As it is well typed the following things would not work:
34-
* actions.submit('not void'); // not void
35-
* actions.search(); // requires an argument
36-
* actions.search(42); // not a string
37-
* actions.search$.error(new Error('traraaa')); // not possible by typings as well as in code
38-
* actions.search = "string"; // not a setter. the proxy will throw an error pointing out that you have to call it
28+
* @Component({...})
29+
* export class Component {
30+
* ui = rxActions<{ name: string }>(({transforms}) => transforms({name: v => v}));
3931
*
40-
* @param transforms - A map of transform functions to apply on transformations to actions before emitting them.
41-
* This is very useful to clean up bloated templates and components. e.g. `[input]="$event?.target?.value"` => `[input]="$event"`
32+
* name$ = this.ui.name$; // Observable<string> - listens to name changes
33+
* emitName = this.ui.name; // (name: string) => void - emits name change
34+
* sub = this.ui.onName(o$ => o$.pipe(), console.log) // () => void - stops side effect
4235
*
43-
* @example
44-
* function coerceSearchActionParams(e: Event | string | number): string {
45-
* if(e?.target?.value !== undefined) {
46-
* return e?.target?.value + ''
36+
* onInit() {
37+
* const name$ = this.ui.name$; // Observable<string> - listens to name changes
38+
* const emitName = this.ui.name; // (name: string) => void - emits name change
39+
* const stop = this.ui.onName(o$ => o$.pipe(), console.log) // () => void - stops side effect
40+
* stop();
4741
* }
48-
* return e + '';
49-
* }
50-
* const actions = getActions<search: string, submit: void>({search: coerceSearchActionParams, submit: (v: any) => void 0;});
5142
*
52-
* actions.search($event);
53-
* actions.search('string');
54-
* actions.search(42);
55-
* actions.submit('not void'); // does not error anymore
56-
* actions.search$.subscribe(); // string Observable
43+
* }
5744
*
5845
*/
5946
export function rxActions<

0 commit comments

Comments
 (0)