Skip to content
This repository was archived by the owner on Dec 26, 2017. It is now read-only.

Commit 264555f

Browse files
committed
fix(StateUpdates): Generate metadata for StateUpdates class to make it easy to provide
1 parent 43e27bf commit 264555f

2 files changed

Lines changed: 23 additions & 24 deletions

File tree

lib/ng2.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,33 @@ import {Store, Dispatcher} from "@ngrx/store";
88
export const BOOTSTRAP_EFFECTS = new String('@ngrx/effects Bootstrap Effects');
99

1010
export function runEffects(...effects: any[]) {
11-
const individuals = flatten(effects);
11+
const individuals = flatten(effects);
1212

13-
const allEffects = individuals.map(effectClass => createDynamicProvider(effectClass));
14-
return [
15-
...individuals,
16-
...allEffects,
17-
CONNECT_EFFECTS_PROVIDER,
18-
STATE_UPDATES_PROVIDER
19-
];
13+
const allEffects = individuals.map(effectClass => createDynamicProvider(effectClass));
14+
return [
15+
...individuals,
16+
...allEffects,
17+
CONNECT_EFFECTS_PROVIDER,
18+
STATE_UPDATES_PROVIDER
19+
];
2020
}
2121

2222
export const CONNECT_EFFECTS_PROVIDER = {
23-
provide: APP_INITIALIZER,
24-
multi: true,
25-
deps: [Store, BOOTSTRAP_EFFECTS],
26-
useFactory: connectEffectsToStore
23+
provide: APP_INITIALIZER,
24+
multi: true,
25+
deps: [Store, BOOTSTRAP_EFFECTS],
26+
useFactory: connectEffectsToStore
2727
};
2828

2929
export const STATE_UPDATES_PROVIDER = {
30-
provide: StateUpdates,
31-
deps: [Dispatcher, Store],
32-
useFactory(dispatcher: Dispatcher, store: Store<any>) {
33-
return new StateUpdates(dispatcher, store);
34-
}
30+
provide: StateUpdates,
31+
useClass: StateUpdates
3532
};
3633

3734
function createDynamicProvider(effectClass: any) {
38-
return {
39-
provide: BOOTSTRAP_EFFECTS,
40-
useExisting: effectClass,
41-
multi: true
42-
}
43-
}
35+
return {
36+
provide: BOOTSTRAP_EFFECTS,
37+
useExisting: effectClass,
38+
multi: true
39+
}
40+
}

lib/state-updates.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { filter } from 'rxjs/operator/filter';
33
import { Observable } from 'rxjs/Observable';
44
import { ReplaySubject } from 'rxjs/ReplaySubject';
55
import { Action, Dispatcher, State } from '@ngrx/store';
6+
import { Injectable } from '@angular/core';
67

78
export interface StateUpdate<S> {
89
state: S;
910
action: Action;
1011
}
1112

13+
@Injectable()
1214
export class StateUpdates<S> extends ReplaySubject<StateUpdate<S>> {
1315
constructor(actions$: Dispatcher, state$: State<S>) {
1416
super(1);
@@ -29,4 +31,4 @@ export class StateUpdates<S> extends ReplaySubject<StateUpdate<S>> {
2931
({ action }: StateUpdate<S>) => actionTypes.indexOf(action.type) > -1
3032
);
3133
}
32-
}
34+
}

0 commit comments

Comments
 (0)