Skip to content

Instantly share code, notes, and snippets.

@wbuchwalter
Last active August 15, 2016 21:44
Show Gist options
  • Save wbuchwalter/d1448395f0dee9212b70 to your computer and use it in GitHub Desktop.
Save wbuchwalter/d1448395f0dee9212b70 to your computer and use it in GitHub Desktop.
import {INgRedux} from 'ng-redux';
export default class NgReduxStub implements INgRedux {
private selectedState: any;
private target: any;
private mapState: (state: any) => Object;
push(selectedState: any) {
if (!_.isPlainObject(selectedState)) {
throw 'selectedState must be a plain object';
}
this.selectedState = selectedState;
this.updateTarget();
}
connect(
mapStateToTarget: (state: any) => Object,
mapDispatchToTarget?: Object | ((dispatch: Function) => Object)
): (target: Function | Object) => () => void {
this.mapState = mapStateToTarget;
return (target: Function | Object) => {
this.target = target;
this.updateTarget();
return () => { };
};
}
updateTarget() {
if (!this.target || !this.mapState || !this.selectedState) {
return;
}
if (_.isFunction(this.target)) {
this.target(this.mapState(this.selectedState));
return;
}
_.assign(this.target, this.mapState(this.selectedState));
}
//This properties are useless (right now) for testing, only there to comply with the interface
getReducer(): Redux.Reducer {
return undefined;
};
replaceReducer() {
return undefined;
}
dispatch() {
return undefined;
}
getState() {
return undefined;
}
subscribe() {
return undefined;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment