Created
December 11, 2017 10:27
-
-
Save recurser/6c0779420c004c659afb1d397abeb9c5 to your computer and use it in GitHub Desktop.
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
/* Imports */ | |
require("isomorphic-fetch") | |
const { crudSaga, crudReducer, fetchCollection, selectCollection, ApiClient } = require("redux-crud-store") | |
const { createStore, compose, applyMiddleware } = require("redux") | |
const createSagaMiddleware = require("redux-saga").default | |
const params = {} | |
const fetchAction = fetchCollection('exchanges', '/recurser/23fc68358024ff8bc84596a006821ad7/raw/73fecb79edbe86705ed88852f22043a5404220e3/exchanges.json', params) | |
const client = new ApiClient({ basePath: 'https://gist.githubusercontent.com' }) | |
/* Set up store and integrate redux-crud-store as the top level reducer */ | |
const crudMiddleware = createSagaMiddleware() | |
const createStoreWithMiddleware = compose( | |
applyMiddleware( | |
crudMiddleware | |
) | |
)(createStore) | |
let store = createStoreWithMiddleware(crudReducer) | |
crudMiddleware.run(crudSaga(client)) | |
/* Demo */ | |
const log = [] | |
store.subscribe(() => { | |
if (log.length === 0) { | |
log.push("selectCollection after first FETCH:") | |
log.push(selectCollection('exchanges', store.getState(), params)) | |
log.push("state after first FETCH:") | |
log.push(store.getState()) | |
} else if (log.length === 4) { | |
log.push("selectCollection after FETCH_SUCCESS/FETCH_ERROR:") | |
log.push(selectCollection('exchanges', store.getState(), params)) | |
log.push("state after FETCH_SUCCESS/FETCH_ERROR:") | |
log.push(store.getState()) | |
} | |
console.log(log) | |
}) | |
store.dispatch(fetchAction) // FETCH | |
"You can use the result of selectCollection in your components" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment