Skip to content

Commit

Permalink
space thee A's in test, remove some union functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-okrushko committed Mar 28, 2019
1 parent 085ad4a commit 78b2275
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
7 changes: 7 additions & 0 deletions modules/store/spec/action_creator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('Action Creators', () => {
it('should create an action', () => {
const foo = createAction('FOO', (foo: number) => ({ foo }));
const fooAction = foo(42);

expect(fooAction).toEqual({ type: 'FOO', foo: 42 });
});

Expand All @@ -42,13 +43,15 @@ describe('Action Creators', () => {
throw new Error('Should not get here.');
}
};

narrow(foo(42));
});

it('should be serializable', () => {
const foo = createAction('FOO', (foo: number) => ({ foo }));
const fooAction = foo(42);
const text = JSON.stringify(fooAction);

expect(JSON.parse(text)).toEqual({ type: 'FOO', foo: 42 });
});

Expand Down Expand Up @@ -80,6 +83,7 @@ describe('Action Creators', () => {
it('should allow empty action', () => {
const foo = createAction('FOO');
const fooAction = foo();

expect(fooAction).toEqual({ type: 'FOO' });
});
});
Expand All @@ -88,6 +92,7 @@ describe('Action Creators', () => {
it('should create an action', () => {
const foo = createAction('FOO', props<{ foo: number }>());
const fooAction = foo({ foo: 42 });

expect(fooAction).toEqual({ type: 'FOO', foo: 42 });
});

Expand All @@ -102,13 +107,15 @@ describe('Action Creators', () => {
throw new Error('Should not get here.');
}
};

narrow(foo({ foo: 42 }));
});

it('should be serializable', () => {
const foo = createAction('FOO', props<{ foo: number }>());
const fooAction = foo({ foo: 42 });
const text = JSON.stringify(fooAction);

expect(JSON.parse(text)).toEqual({ foo: 42, type: 'FOO' });
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const loginFailure = createAction(

export const loginRedirect = createAction('[Auth/API] Login Redirect');

// This is an alternative to union() type export.
// This is an alternative to union() type export. Work great when you need
// to export only a single Action type.
export type AuthApiActionsUnion = ReturnType<
typeof loginSuccess | typeof loginFailure | typeof loginRedirect
>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ export const login = createAction(
props<{ credentials: Credentials }>()
);

const all = union({ login });
export type LoginPageActionsUnion = typeof all;
export type LoginPageActionsUnion = ReturnType<typeof login>;
5 changes: 2 additions & 3 deletions projects/example-app/src/app/books/actions/book.actions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { createAction, props, union } from '@ngrx/store';
import { createAction, props } from '@ngrx/store';
import { Book } from '@example-app/books/models/book';

export const loadBook = createAction(
'[Book Exists Guard] Load Book',
props<{ book: Book }>()
);

const all = union({ loadBook });
export type BookActionsUnion = typeof all;
export type BookActionsUnion = ReturnType<typeof loadBook>;
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { createAction, props, union } from '@ngrx/store';
import { createAction, props } from '@ngrx/store';

export const searchBooks = createAction(
'[Find Book Page] Search Books',
props<{ query: string }>()
);

const all = union({ searchBooks });

export type FindBookPageActionsUnion = typeof all;
export type FindBookPageActionsUnion = ReturnType<typeof searchBooks>;
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { createAction, union, props } from '@ngrx/store';
import { createAction, props } from '@ngrx/store';

export const selectBook = createAction(
'[View Book Page] Select Book',
props<{ id: string }>()
);

const all = union({ selectBook });
export type ViewBookPageActionsUnion = typeof all;
export type ViewBookPageActionsUnion = ReturnType<typeof selectBook>;

0 comments on commit 78b2275

Please sign in to comment.