-
-
Save recurser/4b3aacf90e39fd29d26a5b9a0433148f 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/3b9a6c97ba74349c92a9dd46aead3eff/raw/59ecdbd34bd25750dc85df03214afb3a1c80432f/exchanges-flat.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