Slides for the 2016 Redux & Angular workshop. Redux is a popular library for state management. This workshop is about understanding how to use Redux and how to integrate it wit Angular 2
66. Async flow with middlewares
UI STORE
state
MIDDLEWARE
action action
67. export const middleware = store => next => action => {
return next(action)
};
Middleware
- get the current state from the store
- pass an action to the next middleware
- access the provided action
79. import {createStore} from “redux";
import {RootReducer} from './reducers/root';
export class Store {
private store = createStore(rootReducer);
get state() {
return this.store.getState();
}
dispatch(action){
this.store.dispatch(action)
}
}
89. @Injectable()
export class ListActions {
private store:Store;
constructor(_store:Store) {
this.store = _store;
}
add(item) {
this.store.dispatch({
type : LIST.ADD_ITEM,
payload: item
})
}
remove(item) {
this.store.dispatch({
type : LIST.REMOVE_ITEM,
payload: item
})
}
}
The list actions class is
an helper for dispatching
actions to the store