Comments (6)
Angular 1.5+ components can avoid $scope
usage by putting cleanup in the $onDestroy
hook. Not as concise, but may improve readability.
class MyComponentCtrl {
unsubscribe;
/* @ngInject */
constructor($ngRedux) {
this.unsubscribe = $ngRedux.connect(...)(this);
}
$onDestroy() {
this.unsubscribe();
}
}
PS: sorry for posting on a closed issue...it just seemed worth mentioning. It might even be worth adding to the docs.
from ng-redux.
Using $scope
in itself is not a bad practice, it's what people do with it that often end up being one.
In the case of ng-redux, $scope
is used solely to hook on the $destroy
event to unsubscribe from the store.
If you don't want to inject $scope
, you could manually unsubscribe in your transient component when it is disposed (for example, when the user click on a close button or something like that), that will work just as fine.
You can totally use ng-redux in a service, and since services are never disposed, you don't need to unsubscribe.
from ng-redux.
Thanks.
So, if i use it in a service, all in all, will ng-redux, upon change, run the entire digest loop from root?
from ng-redux.
Where you use ng-redux
has no impact on the digest cycle (ng-redux
does not trigger a digest cycle itself), so it won't change anything, it will be angular that will decide wether what you did may have affected the state of the DOM.
Side note: To be exact, the only place where ng-redux
may have an effect on the digest loop is in the middleware: All your middlewares are wrapped in a $evalAsync
, so that any timeout in one of your custom middleware does not get you out of the angular world, but this has no impact on what we are discussing here.
(I'm closing this issue, since it is not really one, but feel free to continue the discussion)
from ng-redux.
Great.
Thanks.
I'm looking into adding ng-redux to the style guide
https://github.com/orizens/angular-es2015-styleguide
from ng-redux.
@zourtney you could use $onInit()
instead of the constructor here; although it does mean storing a reference to $ngRedux
, it ensures that the connection is only made when the component is ready.
from ng-redux.
Related Issues (20)
- 4.0.x doesn't support Redux DevTools Chrome Extension HOT 11
- Typings Error when using Redux 4.0.0 HOT 2
- 4.1.0 Release HOT 4
- types: `connect` should allow `null` as the first argument HOT 3
- How to use multiple Actions in single $ngRedux.connect()? HOT 1
- Redux 4.0.0 is available HOT 2
- 4.X.0 Discussion/Tracking Issue HOT 8
- [TS] Type safety is not good enough when using $ngRedux.connect()
- Add standard version as part of the release process
- How to mock ngredux store in Jasmine Component Testing ?
- $digest may be triggered before the actual state change
- Question: async dispatch / thunk advice requested
- Lodash dependancy bloating the bundle size. HOT 1
- Release new version HOT 3
- Upgrade lodash in order to fix SNYK-JS-LODASH-450202 HOT 1
- New release? HOT 3
- How do I call an angularjs service function inside a reducer? HOT 1
- the published version of 4.4.1 depends on a vulnerable version of lodash (4.17.13) HOT 1
- Maintainer access HOT 8
- `$ngRedux.provideStore()` leaks subscription to provided store after `$rootScope.$destroy()`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng-redux.