Skip to content

Commit

Permalink
fix: handle.others instead of handle.default
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazzmanpw authored and the-dr-lazy committed Oct 1, 2020
1 parent e12a45f commit f9aec53
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ exports[`createHandlerMap handle([increment, increase], (state: number) => state

exports[`createHandlerMap handle(increment, (state: number) => state + 1) (type) should match snapshot 1`] = `"HandlerMap<number, { type: \\"[Counter] increment\\"; }, number>"`;

exports[`createHandlerMap handle.default((state: number) => state + 1) (type) should match snapshot 1`] = `"{ default: Handler<number, any, number>; }"`;
exports[`createHandlerMap handle.others((state: number) => state + 1) (type) should match snapshot 1`] = `"{ default: Handler<number, any, number>; }"`;
2 changes: 1 addition & 1 deletion src/__tests__/create-handler-map.dts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ handle(increment, (state: number) => state + 1)
handle([increment, increase], (state: number) => state + 1)

// @dts-jest:pass:snap
handle.default((state: number) => state + 1)
handle.others((state: number) => state + 1)
4 changes: 2 additions & 2 deletions src/__tests__/create-handler-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('createHandlerMap', () => {
).toMatchSnapshot()
})

it('should put the handler by "default" key', () => {
it('should put the "others" handler by "default" key', () => {
const reducer = (state: number) => state + 1
expect(handle.default(reducer)).toEqual({ default: reducer });
expect(handle.others(reducer)).toEqual({ default: reducer });
})
})
10 changes: 5 additions & 5 deletions src/__tests__/create-reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ describe('createReducer', () => {
const defaultCounterState = 0

const handleReset = jest.fn(() => defaultCounterState);
const handleDefault = jest.fn((state: number, { payload }: Action<string, number>) => (
const handleOthers = jest.fn((state: number, { payload }: Action<string, number>) => (
payload % 2 === 0 ? state + 1 : state
))

const evenNumbersCounterReducer = createReducer(defaultCounterState, handleAction => [
handleAction(resetCounter, handleReset),
handleAction.default(handleDefault)
handleAction.others(handleOthers)
])

beforeEach(() => {
handleReset.mockReset()
handleDefault.mockReset()
handleOthers.mockReset()
})

it('should initiate with default state when state is undefined', () => {
Expand All @@ -86,14 +86,14 @@ describe('createReducer', () => {
expect(evenNumbersCounterReducer(5, resetCounter())).toBe(handleReset())

expect(handleReset).toBeCalledTimes(2)
expect(handleDefault).not.toBeCalled()
expect(handleOthers).not.toBeCalled()
})

it('should calls the default handler when there is no proper handler', () => {
const action = drawNumber(6)

expect(evenNumbersCounterReducer(defaultCounterState, action)).toBe(
handleDefault(defaultCounterState, action)
handleOthers(defaultCounterState, action)
)
})
})
Expand Down
6 changes: 3 additions & 3 deletions src/create-handler-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type InferNextStateFromHandlerMap<

type InferActionFromCreator<TActionCreator> = TActionCreator extends (...args: any[]) => infer T ? T : never

type CreateDefaultHandler<TPrevState> = <
type CreateOthersHandler<TPrevState> = <
TActionCreator extends ActionCreator<any>,
TNextState extends TPrevState,
TAction extends AnyAction = InferActionFromCreator<TActionCreator>
Expand All @@ -37,7 +37,7 @@ type CreateCustomHandlerMap<TPrevState> = <
) => HandlerMap<TPrevState, TAction, TNextState>

export type CreateHandlerMap<TPrevState> = CreateCustomHandlerMap<TPrevState> & {
default: CreateDefaultHandler<TPrevState>
others: CreateOthersHandler<TPrevState>
}

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ export const createHandlerMap = Object.assign(
}, {} as any)
},
{
default: <TActionCreator extends ActionCreator<any>,
others: <TActionCreator extends ActionCreator<any>,
TPrevState,
TNextState extends TPrevState,
TAction extends AnyAction = InferActionFromCreator<TActionCreator>
Expand Down

0 comments on commit f9aec53

Please sign in to comment.