If you're in a big legacy Angular 1 codebase and you don't want to introduce new dependencies (like ngRedux), would it be a terrible idea to start using classic Angular 1 features, such as $rootScope, $broadcast, $on, $watch to implement a Redux-like architecture?
The way I see it, it could be done as following:
- For store/model -> use
$rootScope
- For
store.dispatch(ACTION)
-> use$rootScope.$broadcast(ACTION)
- Reducers would be implemented as services injecting
$rootScope
and doing$on(ACTION)
- Controllers could watch for changes on
$rootScope
with$watch
and update the view or views could bind directly to$rootScope
properties
As long as you're disciplined to not do weird out-of-place mutations on $rootScope
properties, keep all application logic in the Reducers and keep controllers code to a minimum, the greatest drawback I can see with this is having terrible performance due to Angular 1 expensive digest cycles. But if you can also stick to immutable data structures, it might not even be the case.
Is this a bad idea? Has anybody tried this?