Skip to content

Commit

Permalink
feat(effects): change the signature of provideEffect (#3587)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
timdeschryver authored Oct 17, 2022
1 parent 8636734 commit 899afe7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
16 changes: 8 additions & 8 deletions modules/effects/spec/provide_effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ describe('provideEffects', () => {
},
provideStore({}).ɵproviders,
// provide effects twice
provideEffects([]).ɵproviders,
provideEffects([]).ɵproviders,
provideEffects().ɵproviders,
provideEffects().ɵproviders,
],
});

Expand All @@ -50,8 +50,8 @@ describe('provideEffects', () => {
},
provideStore().ɵproviders,
// provide effects twice
provideEffects([]).ɵproviders,
provideEffects([]).ɵproviders,
provideEffects().ɵproviders,
provideEffects().ɵproviders,
],
});

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

expect(() => TestBed.inject(TestEffects)).toThrowError();
Expand All @@ -73,7 +73,7 @@ describe('provideEffects', () => {
TestBed.configureTestingModule({
providers: [
provideStore().ɵproviders,
provideEffects([TestEffects]).ɵproviders,
provideEffects(TestEffects).ɵproviders,
],
});

Expand All @@ -91,7 +91,7 @@ describe('provideEffects', () => {
it('runs provided effects after root state registration', (done) => {
TestBed.configureTestingModule({
providers: [
provideEffects([TestEffects]).ɵproviders,
provideEffects(TestEffects).ɵproviders,
// provide store after effects
provideStore({ [rootSliceKey]: createReducer('ngrx') }).ɵproviders,
],
Expand All @@ -114,7 +114,7 @@ describe('provideEffects', () => {
TestBed.configureTestingModule({
providers: [
provideStore().ɵproviders,
provideEffects([TestEffects]).ɵproviders,
provideEffects(TestEffects).ɵproviders,
// provide feature state after effects
provideState(featureSliceKey, createReducer('effects')).ɵproviders,
],
Expand Down
8 changes: 5 additions & 3 deletions modules/effects/src/provide_effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { rootEffectsInit as effectsInit } from './effects_actions';
*
* ```ts
* bootstrapApplication(AppComponent, {
* providers: [provideEffects([RouterEffects])],
* providers: [provideEffects(RouterEffects]],
* });
* ```
*
Expand All @@ -34,7 +34,7 @@ import { rootEffectsInit as effectsInit } from './effects_actions';
* const booksRoutes: Route[] = [
* {
* path: '',
* providers: [provideEffects([BooksApiEffects])],
* providers: [provideEffects(BooksApiEffects)],
* children: [
* { path: '', component: BookListComponent },
* { path: ':id', component: BookDetailsComponent },
Expand All @@ -43,7 +43,9 @@ import { rootEffectsInit as effectsInit } from './effects_actions';
* ];
* ```
*/
export function provideEffects(effects: Type<unknown>[]): EnvironmentProviders {
export function provideEffects(
...effects: Type<unknown>[]
): EnvironmentProviders {
return {
ɵproviders: [
effects,
Expand Down
2 changes: 1 addition & 1 deletion projects/standalone-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ bootstrapApplication(AppComponent, {
name: 'NgRx Standalone App',
}),
provideRouterStore(),
provideEffects([AppEffects]),
provideEffects(AppEffects),
],
});

0 comments on commit 899afe7

Please sign in to comment.