diff --git a/modules/effects/spec/map_to_action.spec.ts b/modules/effects/spec/act.spec.ts similarity index 86% rename from modules/effects/spec/map_to_action.spec.ts rename to modules/effects/spec/act.spec.ts index dbd8bc8f78..37fca017c5 100644 --- a/modules/effects/spec/map_to_action.spec.ts +++ b/modules/effects/spec/act.spec.ts @@ -1,10 +1,10 @@ import { cold, hot } from 'jasmine-marbles'; import { mergeMap, take, switchMap } from 'rxjs/operators'; import { createAction, Action } from '@ngrx/store'; -import { mapToAction } from '@ngrx/effects'; +import { act } from '@ngrx/effects'; import { throwError, Subject } from 'rxjs'; -describe('mapToAction operator', () => { +describe('act operator', () => { /** * Helper function that converts a string (or array of letters) into the * object, each property of which is a letter that is assigned an Action @@ -41,7 +41,7 @@ describe('mapToAction operator', () => { }); const error = () => createAction('e')(); - sources$.pipe(mapToAction(project, error)).subscribe(); + sources$.pipe(act(project, error)).subscribe(); expect(actual$).toBeObservable( cold(' -a-b', { @@ -57,7 +57,7 @@ describe('mapToAction operator', () => { const error = () => createAction('e')(); const expected$ = cold('-v', genActions('v')); - const output$ = sources$.pipe(mapToAction(project, error)); + const output$ = sources$.pipe(act(project, error)); expect(output$).toBeObservable(expected$); }); @@ -68,7 +68,7 @@ describe('mapToAction operator', () => { const error = () => createAction('e')(); const expected$ = cold('-v', genActions('v')); - const output$ = sources$.pipe(mapToAction(project, error)); + const output$ = sources$.pipe(act(project, error)); expect(output$).toBeObservable(expected$); }); @@ -81,7 +81,7 @@ describe('mapToAction operator', () => { // offset by source delay and doesn't complete const expected$ = cold('-v--', genActions('v')); - const output$ = sources$.pipe(mapToAction({ project, error })); + const output$ = sources$.pipe(act({ project, error })); expect(output$).toBeObservable(expected$); }); @@ -92,7 +92,7 @@ describe('mapToAction operator', () => { const error = () => createAction('e')(); const expected$ = cold('-e', genActions('e')); - const output$ = sources$.pipe(mapToAction(project, error)); + const output$ = sources$.pipe(act(project, error)); expect(output$).toBeObservable(expected$); }); @@ -106,7 +106,7 @@ describe('mapToAction operator', () => { // handled const expected$ = cold('-e--v', genActions('ev')); - const output$ = sources$.pipe(mapToAction(project, error)); + const output$ = sources$.pipe(act(project, error)); expect(output$).toBeObservable(expected$); }); @@ -118,7 +118,7 @@ describe('mapToAction operator', () => { // offset by source delay and doesn't complete const expected$ = cold('-v-w-x-y--', genActions('vwxy')); - const output$ = sources$.pipe(mapToAction(project, error)); + const output$ = sources$.pipe(act(project, error)); expect(output$).toBeObservable(expected$); }); @@ -130,7 +130,7 @@ describe('mapToAction operator', () => { // offset by source delay const expected$ = cold('-v-w-x-y', genActions('vwxy')); - const output$ = sources$.pipe(mapToAction({ project, error })); + const output$ = sources$.pipe(act({ project, error })); expect(output$).toBeObservable(expected$); }); @@ -142,7 +142,7 @@ describe('mapToAction operator', () => { const expected$ = cold('-v--v-', genActions('v')); - const output$ = sources$.pipe(mapToAction(project, error)); + const output$ = sources$.pipe(act(project, error)); expect(output$).toBeObservable(expected$); }); @@ -154,7 +154,7 @@ describe('mapToAction operator', () => { const expected$ = cold('-v--v-', genActions('v')); - const output$ = sources$.pipe(mapToAction(project, error)); + const output$ = sources$.pipe(act(project, error)); expect(output$).toBeObservable(expected$); }); @@ -168,7 +168,7 @@ describe('mapToAction operator', () => { // wait for the project to complete before handling second source action. const expected$ = cold('-v------(wv)---w', genActions('vw')); - const output$ = sources$.pipe(mapToAction(project, error)); + const output$ = sources$.pipe(act(project, error)); expect(output$).toBeObservable(expected$); }); @@ -182,7 +182,7 @@ describe('mapToAction operator', () => { // wait for the project to complete before handling second source action. const expected$ = cold('-v------(wv)---w', genActions('vw')); - const output$ = sources$.pipe(mapToAction({ project, error })); + const output$ = sources$.pipe(act({ project, error })); expect(output$).toBeObservable(expected$); }); @@ -195,9 +195,7 @@ describe('mapToAction operator', () => { // Merge map starts project streams in parallel const expected$ = cold('-v--v---w--w', genActions('vw')); - const output$ = sources$.pipe( - mapToAction({ project, error, operator: mergeMap }) - ); + const output$ = sources$.pipe(act({ project, error, operator: mergeMap })); expect(output$).toBeObservable(expected$); }); @@ -211,7 +209,7 @@ describe('mapToAction operator', () => { // Completed is the last action const expected$ = cold('-v-c', genActions('vc')); - const output$ = sources$.pipe(mapToAction({ project, error, complete })); + const output$ = sources$.pipe(act({ project, error, complete })); expect(output$).toBeObservable(expected$); }); @@ -230,7 +228,7 @@ describe('mapToAction operator', () => { return createAction('c')(); }); - sources$.pipe(mapToAction({ project, error, complete })).subscribe(); + sources$.pipe(act({ project, error, complete })).subscribe(); expect(actual$).toBeObservable( cold('-----a', { @@ -249,7 +247,7 @@ describe('mapToAction operator', () => { const expected$ = cold('-v-(uv)--w', genActions('vuw')); const output$ = sources$.pipe( - mapToAction({ project, error, unsubscribe, operator: switchMap }) + act({ project, error, unsubscribe, operator: switchMap }) ); expect(output$).toBeObservable(expected$); @@ -273,7 +271,7 @@ describe('mapToAction operator', () => { }); sources$ - .pipe(mapToAction({ project, error, unsubscribe, operator: switchMap })) + .pipe(act({ project, error, unsubscribe, operator: switchMap })) .subscribe(); expect(actual$).toBeObservable( diff --git a/modules/effects/src/map_to_action.ts b/modules/effects/src/act.ts similarity index 95% rename from modules/effects/src/map_to_action.ts rename to modules/effects/src/act.ts index f590d7ebfe..a3be951e1f 100644 --- a/modules/effects/src/map_to_action.ts +++ b/modules/effects/src/act.ts @@ -17,8 +17,8 @@ import { materialize, } from 'rxjs/operators'; -/** Represents config with named paratemeters for mapToAction */ -export interface MapToActionConfig< +/** Represents config with named paratemeters for act */ +export interface ActConfig< Input, OutputAction extends Action, ErrorAction extends Action, @@ -50,7 +50,7 @@ export interface MapToActionConfig< * Takes either config with named properties that represent different possible * callbacks or project/error callbacks that are required. */ -export function mapToAction< +export function act< Input, OutputAction extends Action, ErrorAction extends Action @@ -58,14 +58,14 @@ export function mapToAction< project: (input: Input, index: number) => Observable, error: (error: any, input: Input) => ErrorAction ): (source: Observable) => Observable; -export function mapToAction< +export function act< Input, OutputAction extends Action, ErrorAction extends Action, CompleteAction extends Action = never, UnsubscribeAction extends Action = never >( - config: MapToActionConfig< + config: ActConfig< Input, OutputAction, ErrorAction, @@ -77,7 +77,7 @@ export function mapToAction< ) => Observable< OutputAction | ErrorAction | CompleteAction | UnsubscribeAction >; -export function mapToAction< +export function act< Input, OutputAction extends Action, ErrorAction extends Action, @@ -86,7 +86,7 @@ export function mapToAction< >( /** Allow to take either config object or project/error functions */ configOrProject: - | MapToActionConfig< + | ActConfig< Input, OutputAction, ErrorAction, diff --git a/modules/effects/src/index.ts b/modules/effects/src/index.ts index 0008709339..26ac588b1d 100644 --- a/modules/effects/src/index.ts +++ b/modules/effects/src/index.ts @@ -8,7 +8,7 @@ export { EffectsModule } from './effects_module'; export { EffectSources } from './effect_sources'; export { EffectNotification } from './effect_notification'; export { ROOT_EFFECTS_INIT } from './effects_root_module'; -export { mapToAction } from './map_to_action'; +export { act } from './act'; export { OnIdentifyEffects, OnRunEffects,