Last active
August 19, 2016 19:59
-
-
Save ipassynk/05476a26e2de1c36e7146c6b6253ce63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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