Comments (3)
I suppose your fetchLocations
is being executed when some actions kicks in, right? You might want to keep the userId
in the payload of the action so that you can easily pass it to fetchLocations
saga.
from prism.
declare function require(name: string): any;
import { takeEvery } from "redux-saga";
import { take, put, call, fork, select, Effect } from "redux-saga/effects";
import { getRoles, receiveRoles, errorHandler, getLocations, receiveLocations, errorHandlerLocations } from "./actions";
import { loadRoles, loadLocations } from "./effects";
import { Map } from "immutable";
import { GET_ROLES, RECEIVE_ROLES, GET_LOCATIONS, RECEIVE_LOCATIONS } from "./actions";
const { Updater } = require("redux-elm");
// Switch this for users account id
const tempAccountId: number = 3;
// Initial immutable model/state passed to the Updater.
type Init = Map<string, any>;
export const init: Init = Map({
isGettingRoles: false,
isGettingLocations: false
});
function* fetchRoles (): IterableIterator<Effect> {
try {
yield put( getRoles() );
const roles = yield call(loadRoles, "https://pathToApiEndpoint/api/Roles");
yield put( receiveRoles(roles) );
}
catch (error) {
console.log(error.message, error.name);
yield put( errorHandler(error));
}
}
function* fetchLocations (): IterableIterator<Effect> {
try {
yield put( getLocations() );
const locations = yield call(loadLocations, "pathToApiEndpoint/" + tempAccountId + "/locations");
yield put( receiveLocations(locations) );
}
catch (error) {
console.log(error.message, error.name);
yield put( errorHandlerLocations(error));
}
}
function* locationSaga() {
yield* fetchLocations();
}
// Main saga passed to the Updater.
function* saga() {
yield fork(locationSaga);
yield* fetchRoles();
}
export default new Updater(init, saga)
.case(GET_ROLES, model => model.set("isGettingRoles", true))
.case(RECEIVE_ROLES, (model, {roles}) =>
model
.set("isGettingRoles", false)
.set("roles", roles))
.case(GET_LOCATIONS, model => model.set("isGettingLocations", true))
.case(RECEIVE_LOCATIONS, (model, {locations}) =>
model
.set("isGettingLocations", false)
.set("locations", locations))
.toReducer();
So I'm getting locations once I enter the route with this component.
from prism.
Closing because of irrelevance. prism
v4 does not deal with Sagas anymore.
from prism.
Related Issues (20)
- Don't Call PropTypes HOT 3
- Sibling components interaction best practice HOT 6
- Performance HOT 2
- Request to join cdnjs HOT 1
- Build a umd package for Browser usage
- Reduce bundle size by using rxjs modularity HOT 1
- Mount order and saga registering HOT 8
- Sagas not getting unmounted HOT 2
- Version 4.x.x HOT 7
- redux-saga update HOT 2
- Documentation links 404 HOT 5
- Where is documentation for v3? HOT 2
- Props 'selector' and 'wrapper' get passed down to enhanced component HOT 3
- prism-redux/escapeRegexp.js is missing a character in the regex
- Questions about using side-effect libraries with prism
- How to wrap/unwrap dynamic components? HOT 2
- Provide a wrapper compatible with the library-provided unwrapper
- EnhanceComponent doesn't work with thunk middleware
- Dynamic list of stateful components HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prism.