-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
27 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const API_ACTION_PREFIX = '@@saga-query'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import test from 'ava'; | ||
import { createAction } from './util'; | ||
import { API_ACTION_PREFIX } from './constants'; | ||
|
||
test('createAction - should return action type when stringified', (t) => { | ||
const undo = createAction('UNDO'); | ||
t.assert(`${API_ACTION_PREFIX}/UNDO` === `${undo}`); | ||
}); | ||
|
||
test('createAction - return object with type', (t) => { | ||
const undo = createAction('UNDO'); | ||
t.deepEqual(undo(), { type: `${API_ACTION_PREFIX}/UNDO` }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
import { API_ACTION_PREFIX } from './constants'; | ||
export const isFn = (fn?: any) => fn && typeof fn === 'function'; | ||
export const isObject = (obj?: any) => typeof obj === 'object' && obj !== null; | ||
export const createAction = (curType: string) => { | ||
if (!curType) throw new Error('createAction requires non-empty string'); | ||
const type = `${API_ACTION_PREFIX}/${curType}`; | ||
const action = () => ({ type }); | ||
action.toString = () => type; | ||
return action; | ||
}; |