Skip to content

Commit 563a2f2

Browse files
SethDavenportsmithad15
authored andcommitted
[Fixes #372] Add support for redux-batch (#397)
Redux-batch (@manaflair/redux-batch) works by overriding Redux's subscribe and notify mechanism. However, the way we were creating an observable out of the store was pushing updates independently of Subscribe. This has the effect that observable.next() was being called independently of redux-batches patched subscribe/notify mechanism and selectors fire on each change of the batched action set. The fix is to re-create our observable in terms of store.subscribe() in order to catch any adjustments made by 3rd-party enhancers.
1 parent 4466a8a commit 563a2f2

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

packages/store/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-redux/store",
3-
"version": "6.2.1",
3+
"version": "6.3.0-alpha.0",
44
"description": "Angular 2 bindings for Redux",
55
"main": "./lib/src/index.js",
66
"scripts": {

packages/store/src/components/ng-redux.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { Observable } from 'rxjs/Observable';
1717
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
1818
import 'rxjs/add/operator/map';
1919
import 'rxjs/add/operator/filter';
20-
import 'rxjs/add/observable/from';
2120
import 'rxjs/add/operator/distinctUntilChanged';
2221
import 'rxjs/add/operator/switchMap';
2322

@@ -47,9 +46,9 @@ export class NgRedux<RootState> {
4746
constructor(
4847
private ngZone: NgZone) {
4948
NgRedux.instance = this;
50-
this._store$ = new BehaviorSubject<RootState>(null)
51-
.filter(n => n !== null)
52-
.switchMap(n => Observable.from(n as any)) as BehaviorSubject<RootState>;
49+
this._store$ = new BehaviorSubject<RootState>(undefined)
50+
.filter(n => n !== undefined)
51+
.switchMap(n => this.storeToObservable(n as any)) as BehaviorSubject<RootState>;
5352
}
5453

5554
/**
@@ -183,4 +182,10 @@ export class NgRedux<RootState> {
183182
this._store = store;
184183
this._store$.next(store as any);
185184
}
185+
186+
private storeToObservable = (store: Store<RootState>): Observable<RootState> =>
187+
new Observable<RootState>(observer => {
188+
observer.next(store.getState());
189+
store.subscribe(() => observer.next(store.getState()));
190+
});
186191
};

0 commit comments

Comments
 (0)