Package Exports
- redux-rest-adapter
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (redux-rest-adapter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
redux-rest-adapter
redux-rest-adapter is REST adapter for redux based on redux-api-middleware
##Setup
###known-entities-api.js
import EntityApi from 'redux-rest-adapter';
export const KnownEntitiesUrls = {
NEWS_TAGS: 'news-tags',
NEWS_TAG_FOR_EDIT: 'news-tags',
//..
};
export default _.mapValues(KnownEntitiesUrls, (url, name)=> new EntityApi({
entityName: name,
endpointUrl: config.endpointRoot + url
}));###entities-reducer.js
// Ability to extend default api reducers
const entityReducersExtensions = {
NEWS_TAGS: tagsReducer
}
const entitiesReducers = _.mapValues(knownEntitiesApi, (api, key) => api.configureReducer(entityReducersExtensions[key]));
export default combineReducers(entitiesReducers);###your-index-reducer.js
export default combineReducers({
entities: entitiesReducers
//..
});###configure-store.js
import {apiMiddleware} from 'redux-rest-adapter/redux-api-middleware';
//..
export default function configureStore(initialState) {
return createStore(
yourIndexReducer,
initialState,
applyMiddleware(apiMiddleware)
);
}###entities-actions.js
export default _.mapValues(knownEntitiesApi, entityApi => entityApi.actions);##Adapter is ready

##Usage
###tags-container.js
class TagsComponent extends Component {
componentWillMount() {
this.props.loadList();
}
//..
componentWillUnmount() {
this.props.resetEntryForEdit();
}
onTagFormSubmit = ()=> {
const data = this.props.tagForEdit;
if (data.id) {
this.props.updateTag(data.id, data);
} else {
this.props.createTag(data);
}
}
render() {
return (
this.props.pending ?
<Loading/> :
<div>
{/*...*/}
</div>
);
}
}
const mapStateToProps = (state) => ({
list: state.entities.NEWS_TAGS.data || [],
pending: state.entities.NEWS_TAGS.pending,
tagForEdit: state.entities.NEWS_TAG_FOR_EDIT.data || {}
});
const mapDispatchToProps = {
createTag: entitiesActions.NEWS_TAG_FOR_EDIT.create,
updateTag: entitiesActions.NEWS_TAG_FOR_EDIT.update,
removeTag: entitiesActions.NEWS_TAG_FOR_EDIT.remove,
setTagForEdit: entitiesActions.NEWS_TAG_FOR_EDIT.set,
resetEntryForEdit: entitiesActions.NEWS_TAG_FOR_EDIT.reset,
loadList: entitiesActions.NEWS_TAGS.load
};
const TagsContainer = connect(mapStateToProps, mapDispatchToProps)(TagsComponent);
export {TagsComponent, TagsContainer};##TODO
Example of generated list reducer (basic CRUD operations)
##Changelog
- v1.1.6 - Add source code to package. Workaround for issue with babel and redux-api-middleware@1.1.2
###See also