Skip to content

Instantly share code, notes, and snippets.

@ipassynk
Last active August 19, 2016 19:59
Show Gist options
  • Save ipassynk/05476a26e2de1c36e7146c6b6253ce63 to your computer and use it in GitHub Desktop.
Save ipassynk/05476a26e2de1c36e7146c6b6253ce63 to your computer and use it in GitHub Desktop.
import {CoreServices as services} from '../service/core-services';
/**
* This is a decorator with ngRedux and Angular 1.
*/
const reduxConnect = mapStateToParams => target => {
const echanced$onInit = function () {
let $ngRedux = services.$injector.get('$ngRedux');
let disconnect = $ngRedux.connect(target.prototype[mapStateToParams])(this);
this.$scope.$on('$destroy', disconnect);
};
const origin$onInit = target.prototype.$onInit;
target.prototype.$onInit = function () {
echanced$onInit.call(this);
origin$onInit.call(this);
};
return target;
};
export {reduxConnect};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment