Skip to content

Instantly share code, notes, and snippets.

@pastcompute
Created December 1, 2017 11:31
Show Gist options
  • Save pastcompute/1e30aecd23deea1cb613d179d24474cc to your computer and use it in GitHub Desktop.
Save pastcompute/1e30aecd23deea1cb613d179d24474cc to your computer and use it in GitHub Desktop.
Funky ngrx reducer notes
import { IUser } from './../state/app.state';
import { UserActionTypes, EditUserAction } from '../actions/user.actions';
// All reducers get called with all actions.
// So how the fuck does it know where in AppState state comes from?
// Theory: app.reducer -- reducers.user --> userReducer
// Pseudocode:
// for action in actions
// let function;
// unrolled example:
// function = reducers.user; state.user = function(state.user, action);
// function = reducers.x; state.x = function(state.x, action);
//
// state.x might not exist which means it gets called with the default arg somehow
// and thereafter, it does exist. So things can get added to the store without typing...
//
// Direct store select and log synchronously:
// import 'rxjs/add/operator/take';
// ...
// this.store.take(1).subscribe(next => console.log(next));
export function funkyReducer(state = '', action: {type, payload?}): string {
console.log('funkyReducer ' + action.type);
console.log(state);
switch (action.type) {
default: {
return state;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment