Vodka
need to create an object of objects properties which can be mapped into children
So I need a map of
parent: {
child:{
child:{
child:{}
},
},
};
Calling {parent}_{child}/UPDATE_OBJECTS
updates parent's child property in reducer
Base object needs to consist of
{
objects: {},
loading: false,
pagination: {
total: null,
currentPage: 0,
perPage: null,
},
paginationKeys: [],
currentPage: 0,
filter: (object) => {return true;},
[{child_module_name*}] => {},
}
Example usage
import Vodka from 'react-vodka';
const vodka = new Vodka({
baseUrl: 'https://api.bookstore.local',
headers: {
'Content-Type': 'application/json',
},
});
vodka.shot({
name: 'books',
endpoint: 'books/{book}',
key:'slug',
});
vodka.shot({
parents: 'books',
name: 'pages',
endpoint: 'books/{book}/{pages}/',
});
vodka.shot({
parents: 'books.pages',
name: 'words',
endpoint: 'books/{book}/pages/{page}/words/{word}',
});
export default vodka;
vodka.shot({
name: 'pages',
endpoint: '/books/{book}/pages/{pages}/',
parents: 'books',
key: 'slug',
configs: [
'CREATE_LINE',
'CREATE_LINE_ASYNC',
],
reducers: {
'CREATE_LINE' : (state, action) => {
return Object.assign({}, state, {
lines: Object.assign(state.books[action.params.book].lines, action.lines),
});
},
},
sagas: {
'CREATE_LINE_ASNYC': function* () {
while(true) {
const action = yield effects.take('blah');
}
},
},
except: [
'store',
],
});
vodka.shots([
{
name: 'books',
endpoint: 'books/{book}',
key:'slug',
},
{
name: 'pages',
parents: 'books',
endpoint: 'books/{book}/{pages}/',
},
{
name: 'words',
parents: 'books.pages',
endpoint: 'books/{book}/pages/{page}/words/{word}',
},
]);
export default vodka;
Reducer file
import {combineReducers} from 'redux';
import {routerReducer} from 'react-router-redux';
import vodka from './mixers';
export default combineReducers({
routing: routerReducer,
...vodka.getReducers(),
});
Saga file
import vodka from './mixers';
const sagas = [
...vodka.getSagas(),
];
export default sagas;
Routes file
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {
Route,
Switch,
withRouter,
} from 'react-router-dom';
import vodka from './mixers';
class Routes extends Component {
render() {
return (
<Switch>
<Route exact path="/" component={Login}/>
<Route exact path="/register/" component={Register}/>
<vodka.getRoutes/>
</Switch>
);
}
}
export default withRouter(connect()(Routes));
Must import vodka mixers before reducers and sagas are setup
TODO
- Need to find a way to add a trailing slash if outgoing url doesn't already have one
- [DONE] Need to figure out how to have a manageable config object
- [DONE] Need to replace child's parent's reducer function with an object with child's key as a property
- Need to add sagas to manage children easier rather than update parent each time
- Figure out how to export a immutable object/array
- [DONE] Rename Vodka file to index
- Build package and install in stylique app for testing properly
- Have a go at building a routes component
- [DONE] Refactor child to parent method calling by removing parent, name object
- Make sure child reducer types do not conflict with parent's
- Test that sagas work correctly
- Test child setup
- Update dependencies
- Rewrite README
Not so important right now
- Add custom reducer methods to vodka function config
- Add custom saga methods to vodka function config