Skip to content

Commit

Permalink
npm run format
Browse files Browse the repository at this point in the history
  • Loading branch information
jednano committed Sep 3, 2019
1 parent 1d843cb commit b684953
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
11 changes: 9 additions & 2 deletions test/applyMiddleware.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { createStore, applyMiddleware, Middleware, AnyAction, Action, Store } from '..'
import {
createStore,
applyMiddleware,
Middleware,
AnyAction,
Action,
Store
} from '..'
import * as reducers from './helpers/reducers'
import { addTodo, addTodoAsync, addTodoIfEmpty } from './helpers/actionCreators'
import { thunk } from './helpers/middleware'
Expand Down Expand Up @@ -52,7 +59,7 @@ describe('applyMiddleware', () => {
const store = applyMiddleware(test(spy), thunk)(createStore)(reducers.todos)

await store.dispatch(addTodoAsync('Use Redux'))
expect(spy.mock.calls.length).toEqual(2);
expect(spy.mock.calls.length).toEqual(2)
})

it('works with thunk middleware', async () => {
Expand Down
24 changes: 17 additions & 7 deletions test/helpers/actionCreators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ThunkAction } from 'redux-thunk';
import { ThunkAction } from 'redux-thunk'

import {
ADD_TODO,
Expand All @@ -14,7 +14,7 @@ import {
THROW_ERROR,
ThrowError,
UNKNOWN_ACTION,
UnknownAction,
UnknownAction
} from './actionTypes'

export function addTodo(text: string): AddTodo {
Expand All @@ -31,36 +31,46 @@ export function addTodoAsync(text: string): ThunkAction<any, any, {}, AddTodo> {
)
}

export function addTodoIfEmpty(text: string): ThunkAction<any, any, {}, AddTodo> {
export function addTodoIfEmpty(
text: string
): ThunkAction<any, any, {}, AddTodo> {
return (dispatch, getState) => {
if (!getState().length) {
dispatch(addTodo(text))
}
}
}

export function dispatchInMiddle(boundDispatchFn: () => void): DispatchInMiddle {
export function dispatchInMiddle(
boundDispatchFn: () => void
): DispatchInMiddle {
return {
type: DISPATCH_IN_MIDDLE,
boundDispatchFn
}
}

export function getStateInMiddle(boundGetStateFn: () => void): GetStateInMiddle {
export function getStateInMiddle(
boundGetStateFn: () => void
): GetStateInMiddle {
return {
type: GET_STATE_IN_MIDDLE,
boundGetStateFn
}
}

export function subscribeInMiddle(boundSubscribeFn: () => void): SubscribeInMiddle {
export function subscribeInMiddle(
boundSubscribeFn: () => void
): SubscribeInMiddle {
return {
type: SUBSCRIBE_IN_MIDDLE,
boundSubscribeFn
}
}

export function unsubscribeInMiddle(boundUnsubscribeFn: () => void): UnsubscribeInMiddle {
export function unsubscribeInMiddle(
boundUnsubscribeFn: () => void
): UnsubscribeInMiddle {
return {
type: UNSUBSCRIBE_IN_MIDDLE,
boundUnsubscribeFn
Expand Down
5 changes: 3 additions & 2 deletions test/helpers/actionTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Action } from "../..";
import { Action } from '../..'

export const ADD_TODO = 'ADD_TODO'
export interface AddTodo extends Action<typeof ADD_TODO> {
Expand All @@ -21,7 +21,8 @@ export interface SubscribeInMiddle extends Action<typeof SUBSCRIBE_IN_MIDDLE> {
}

export const UNSUBSCRIBE_IN_MIDDLE = 'UNSUBSCRIBE_IN_MIDDLE'
export interface UnsubscribeInMiddle extends Action<typeof UNSUBSCRIBE_IN_MIDDLE> {
export interface UnsubscribeInMiddle
extends Action<typeof UNSUBSCRIBE_IN_MIDDLE> {
boundUnsubscribeFn: () => void
}

Expand Down
8 changes: 3 additions & 5 deletions test/helpers/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { ThunkDispatch } from 'redux-thunk'

import { rootActionTypes } from './actionTypes'
import { Middleware } from '../..';
import { Middleware } from '../..'

export const thunk: Middleware<
ThunkDispatch<any, {}, rootActionTypes>,
any,
ThunkDispatch<any, {}, rootActionTypes>
> = (
{ dispatch, getState },
) => {
return (next) => (action) =>
> = ({ dispatch, getState }) => {
return next => action =>
typeof action === 'function' ? action(dispatch, getState) : next(action)
}
2 changes: 1 addition & 1 deletion test/helpers/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
SUBSCRIBE_IN_MIDDLE,
THROW_ERROR,
UNSUBSCRIBE_IN_MIDDLE,
rootActionTypes,
rootActionTypes
} from './actionTypes'

function id(state: { id: number }[] = []) {
Expand Down

0 comments on commit b684953

Please # to comment.