Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tungv/redux-yucks
declarative redux ducks with FP
https://github.com/tungv/redux-yucks
Last synced: about 2 months ago
JSON representation
declarative redux ducks with FP
- Host: GitHub
- URL: https://github.com/tungv/redux-yucks
- Owner: tungv
- License: mit
- Created: 2016-10-14T04:57:03.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-14T07:08:54.000Z (about 8 years ago)
- Last Synced: 2024-10-12T13:17:18.897Z (3 months ago)
- Size: 4.88 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-yucks
declarative redux ducks with FP# Proposal
Given a yaml file like this:
```yaml
module: myAwesomeModule
imports:
./some/other/file: ACTIONSstates:
currentStep: initialselectors:
isAtTheInitialStepSelector: currentStepSelector | eq('initial')actionCreators:
gotoInitialStep: constant('initial') | currentStepSetter
gotoAwesomeStep: constant('awesome') | currentStepSetterepics:
updateStepWhenUpdateComplete:
- filter get('type') | eq(ACTIONS.AWESOME)
- filter get('payload.awesomeness') | gte(9000)
- mapTo currentStepSetter('success')
````redux-yucks` will take it as an input an returns the follow file
```js
import { combineReducers } from 'redux';
import { createAction, handleActions } from 'redux-actions';
import { combineEpics } from 'redux-observable';
import { ACTIONS } from './some/other/file';import flow from 'lodash/fp/flow';
import get from 'lodash/fp/get';
import constant from 'lodash/fp/constant';
import eq from 'lodash/fp/eq';
import gte from 'lodash/fp/gte';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/mapTo';// helpers
const takePayload = (state, { payload }) => payload;// currentStep
const ACTION_SETTER_currentStep = 'myAwesomeModule/action/SETTER_currentStep';
export const currentStepSetter = createAction(ACTION_SETTER_currentStep);
export const currentStepSelector = get('myAwesomeModule.currentStep');
const currentStep = handleActions({
[ACTION_SETTER_currentStep]: takePayload
}, 'initial');// selectors
export const isAtTheInitialStepSelector = flow(currentStepSelector, eq('initial'));// actionCreators
export const gotoInitialStep = flow(constant('initial'), currentStepSetter);
export const gotoAwesomeStep = flow(constant('awesome'), currentStepSetter);// combined reducer
export const reducer = combineReducers({
currentStep,
});// epics
const updateStepWhenUpdateComplete = actions$ =>
actions$
.filter(flow(get('type'), eq(ACTIONS.AWESOME)))
.filter(flow(get('payload.awesomeness'), gte(9000)))
.mapTo(currentStepSetter('success'));export const epic = combineEpics({
updateStepWhenUpdateComplete,
});export default { myAwesomeModule: reducer };
```