Skip to content

Commit

Permalink
refactor(store): rename mapToAction operator to act (#1927)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-okrushko authored and brandonroberts committed Jun 6, 2019
1 parent dec4bfa commit 36f14bd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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', {
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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$);
});
Expand All @@ -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', {
Expand All @@ -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$);
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -50,22 +50,22 @@ 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
>(
project: (input: Input, index: number) => Observable<OutputAction>,
error: (error: any, input: Input) => ErrorAction
): (source: Observable<Input>) => Observable<OutputAction | ErrorAction>;
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,
Expand All @@ -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,
Expand All @@ -86,7 +86,7 @@ export function mapToAction<
>(
/** Allow to take either config object or project/error functions */
configOrProject:
| MapToActionConfig<
| ActConfig<
Input,
OutputAction,
ErrorAction,
Expand Down
2 changes: 1 addition & 1 deletion modules/effects/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 36f14bd

Please sign in to comment.