Skip to content

Commit

Permalink
Merge 1239b7b into 0051834
Browse files Browse the repository at this point in the history
  • Loading branch information
richardcrng committed Sep 1, 2019
2 parents 0051834 + 1239b7b commit 3bba477
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 228 deletions.
39 changes: 38 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"babel-jest": "^24.7.1",
"coveralls": "^3.0.3",
"jest": "^24.7.1",
"typescript": "^3.5.3"
"typescript": "^3.5.3",
"util": "^0.12.1"
}
}
53 changes: 53 additions & 0 deletions src/actions/api/actionsAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as R from 'ramda'
import * as RA from 'ramda-adjunct'
import Dict from "../../types/Dict";
import LeafReducerConfig from "../../types/Leaf/Reducer/Config";
import { forAny } from '../for/any';
import { forArray } from '../for/array';
import { forBoolean } from '../for/boolean';
import { forNumber } from '../for/number';
import { forObject } from '../for/object';
import { forString } from '../for/string';
import { makeCustomActions } from '../custom';

function actionsAPI (stateShape: Dict<any>, customReducers: Dict<LeafReducerConfig>, pathToLeafOrBranch: string[] = []) {
const initialState = pathToLeafOrBranch.length >= 1
? R.path(pathToLeafOrBranch, stateShape)
: stateShape

const basicActionCreators = forAny(pathToLeafOrBranch)
const asArray = forArray(pathToLeafOrBranch)
const asBoolean = forBoolean(pathToLeafOrBranch)
const asNumber = forNumber(pathToLeafOrBranch)
const asObject = forObject(pathToLeafOrBranch)
const asString = forString(pathToLeafOrBranch)
const custom = makeCustomActions(customReducers, pathToLeafOrBranch)

let actionCreators

if (RA.isBoolean(initialState)) {
actionCreators = asBoolean
} else if (RA.isArray(initialState)) {
actionCreators = asArray
} else if (RA.isNumber(initialState)) {
actionCreators = asNumber
} else if (RA.isPlainObject(initialState)) {
actionCreators = asObject
} else if (RA.isString(initialState)) {
actionCreators = asString
}

return {
...basicActionCreators,
...actionCreators,
asArray,
asBoolean,
asNumber,
asObject,
asString,
custom,
...custom
}
}

export default actionsAPI
3 changes: 3 additions & 0 deletions src/actions/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import actionsAPI from "./actionsAPI";

export default actionsAPI
105 changes: 0 additions & 105 deletions src/actions/for/actionsFor.test.ts

This file was deleted.

106 changes: 0 additions & 106 deletions src/actions/for/actionsFor.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/actions/for/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { makeActionCreator } from './creator';
import { actionsFor } from './for';
import { makeCustomActions } from './custom';

export {
actionsFor,
makeActionCreator,
makeCustomActions
}

0 comments on commit 3bba477

Please sign in to comment.