Skip to content

Commit 899afe7

Browse files
feat(effects): change the signature of provideEffect (#3587)
BREAKING CHANGE: The signature of `provideEffects` is changed to expect a spreaded array of effects. BEFORE: `provideEffects` expecteded the effects to be passed as an array. ```ts // single effect provideEffects([MyEffect]) // multiple effects provideEffects([MyEffect, MySecondEffect]) ```ts AFTER: `provideEffects` expects the effects as a spreaded array as argument. ```ts // single effect provideEffects(MyEffect) // multiple effects provideEffects(MyEffect, MySecondEffect) ```ts
1 parent 8636734 commit 899afe7

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

modules/effects/spec/provide_effects.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ describe('provideEffects', () => {
3131
},
3232
provideStore({}).ɵproviders,
3333
// provide effects twice
34-
provideEffects([]).ɵproviders,
35-
provideEffects([]).ɵproviders,
34+
provideEffects().ɵproviders,
35+
provideEffects().ɵproviders,
3636
],
3737
});
3838

@@ -50,8 +50,8 @@ describe('provideEffects', () => {
5050
},
5151
provideStore().ɵproviders,
5252
// provide effects twice
53-
provideEffects([]).ɵproviders,
54-
provideEffects([]).ɵproviders,
53+
provideEffects().ɵproviders,
54+
provideEffects().ɵproviders,
5555
],
5656
});
5757

@@ -63,7 +63,7 @@ describe('provideEffects', () => {
6363
it('throws an error when store is not provided', () => {
6464
TestBed.configureTestingModule({
6565
// provide only effects
66-
providers: [provideEffects([TestEffects]).ɵproviders],
66+
providers: [provideEffects(TestEffects).ɵproviders],
6767
});
6868

6969
expect(() => TestBed.inject(TestEffects)).toThrowError();
@@ -73,7 +73,7 @@ describe('provideEffects', () => {
7373
TestBed.configureTestingModule({
7474
providers: [
7575
provideStore().ɵproviders,
76-
provideEffects([TestEffects]).ɵproviders,
76+
provideEffects(TestEffects).ɵproviders,
7777
],
7878
});
7979

@@ -91,7 +91,7 @@ describe('provideEffects', () => {
9191
it('runs provided effects after root state registration', (done) => {
9292
TestBed.configureTestingModule({
9393
providers: [
94-
provideEffects([TestEffects]).ɵproviders,
94+
provideEffects(TestEffects).ɵproviders,
9595
// provide store after effects
9696
provideStore({ [rootSliceKey]: createReducer('ngrx') }).ɵproviders,
9797
],
@@ -114,7 +114,7 @@ describe('provideEffects', () => {
114114
TestBed.configureTestingModule({
115115
providers: [
116116
provideStore().ɵproviders,
117-
provideEffects([TestEffects]).ɵproviders,
117+
provideEffects(TestEffects).ɵproviders,
118118
// provide feature state after effects
119119
provideState(featureSliceKey, createReducer('effects')).ɵproviders,
120120
],

modules/effects/src/provide_effects.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { rootEffectsInit as effectsInit } from './effects_actions';
2424
*
2525
* ```ts
2626
* bootstrapApplication(AppComponent, {
27-
* providers: [provideEffects([RouterEffects])],
27+
* providers: [provideEffects(RouterEffects]],
2828
* });
2929
* ```
3030
*
@@ -34,7 +34,7 @@ import { rootEffectsInit as effectsInit } from './effects_actions';
3434
* const booksRoutes: Route[] = [
3535
* {
3636
* path: '',
37-
* providers: [provideEffects([BooksApiEffects])],
37+
* providers: [provideEffects(BooksApiEffects)],
3838
* children: [
3939
* { path: '', component: BookListComponent },
4040
* { path: ':id', component: BookDetailsComponent },
@@ -43,7 +43,9 @@ import { rootEffectsInit as effectsInit } from './effects_actions';
4343
* ];
4444
* ```
4545
*/
46-
export function provideEffects(effects: Type<unknown>[]): EnvironmentProviders {
46+
export function provideEffects(
47+
...effects: Type<unknown>[]
48+
): EnvironmentProviders {
4749
return {
4850
ɵproviders: [
4951
effects,

projects/standalone-app/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ bootstrapApplication(AppComponent, {
3737
name: 'NgRx Standalone App',
3838
}),
3939
provideRouterStore(),
40-
provideEffects([AppEffects]),
40+
provideEffects(AppEffects),
4141
],
4242
});

0 commit comments

Comments
 (0)