Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Commit d1286d2

Browse files
sandangelMikeRyanDev
authored andcommitted
fix: Add support for Angular 6 and RxJS 6
BREAKING CHANGE: NgRx now has a minimum version requirement on Angular 6 and RxJS 6.
1 parent 1352d83 commit d1286d2

File tree

91 files changed

+2712
-2793
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+2712
-2793
lines changed

Diff for: MIGRATION.md

+106-100
Large diffs are not rendered by default.

Diff for: docs/effects/README.md

+24-30
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ RxJS powered side effect model for @ngrx/store
44

55
@ngrx/effects provides an API to model event sources as actions. Effects:
66

7-
- Listen for actions dispatched from @ngrx/store
8-
- Isolate side effects from components, allowing for more _pure_ components that select state and dispatch actions
9-
- Provide [new sources](https://martinfowler.com/eaaDev/EventSourcing.html) of actions to reduce state based on external interactions such as network requests, web socket messages and time-based events.
7+
* Listen for actions dispatched from @ngrx/store
8+
* Isolate side effects from components, allowing for more _pure_ components that select state and dispatch actions
9+
* Provide [new sources](https://martinfowler.com/eaaDev/EventSourcing.html) of actions to reduce state based on external interactions such as network requests, web socket messages and time-based events.
1010

1111
### Installation
12+
1213
Install @ngrx/effects from npm:
1314

1415
`npm install @ngrx/effects --save` OR `yarn add @ngrx/effects`
1516

16-
1717
### Nightly builds
1818

1919
`npm install github:ngrx/effects-builds` OR `yarn add github:ngrx/effects-builds`
@@ -28,27 +28,28 @@ The `@Effect()` decorator provides metadata to register observable side-effects
2828

2929
### Actions Observable
3030

31-
- Represents an observable of all actions dispatched to the store.
32-
- Emits the latest action _after_ the action has passed through all reducers.
33-
- The `ofType` operator lets you filter for actions of a certain type in which you want to use to perform a side effect.
31+
* Represents an observable of all actions dispatched to the store.
32+
* Emits the latest action _after_ the action has passed through all reducers.
33+
* The `ofType` operator lets you filter for actions of a certain type in which you want to use to perform a side effect.
3434

3535
## Example
36-
1. Create an AuthEffects service that describes a source of login actions:
36+
37+
1. Create an AuthEffects service that describes a source of login actions:
3738

3839
```ts
3940
// ./effects/auth.effects.ts
4041
import { Injectable } from '@angular/core';
4142
import { HttpClient } from '@angular/common/http';
4243
import { Action } from '@ngrx/store';
4344
import { Actions, Effect, ofType } from '@ngrx/effects';
44-
import { Observable } from 'rxjs/Observable';
45-
import { of } from 'rxjs/observable/of';
45+
import { Observable, of } from 'rxjs';
4646
import { catchError, map, mergeMap } from 'rxjs/operators';
4747

4848
@Injectable()
4949
export class AuthEffects {
5050
// Listen for the 'LOGIN' action
51-
@Effect() login$: Observable<Action> = this.actions$.pipe(
51+
@Effect()
52+
login$: Observable<Action> = this.actions$.pipe(
5253
ofType('LOGIN'),
5354
mergeMap(action =>
5455
this.http.post('/auth', action.payload).pipe(
@@ -59,26 +60,20 @@ export class AuthEffects {
5960
)
6061
)
6162
);
62-
6363

64-
constructor(
65-
private http: HttpClient,
66-
private actions$: Actions
67-
) {}
64+
constructor(private http: HttpClient, private actions$: Actions) {}
6865
}
6966
```
7067

71-
2. Register the EffectsModule in your application root imports. This EffectsModule *must* be added to
72-
your root `NgModule` for the effects providers to be registered and start when your application is loaded.
68+
2. Register the EffectsModule in your application root imports. This EffectsModule _must_ be added to
69+
your root `NgModule` for the effects providers to be registered and start when your application is loaded.
7370

7471
```ts
7572
import { EffectsModule } from '@ngrx/effects';
7673
import { AuthEffects } from './effects/auth.effects';
7774

7875
@NgModule({
79-
imports: [
80-
EffectsModule.forRoot([AuthEffects])
81-
]
76+
imports: [EffectsModule.forRoot([AuthEffects])],
8277
})
8378
export class AppModule {}
8479
```
@@ -92,17 +87,16 @@ import { EffectsModule } from '@ngrx/effects';
9287
import { AdminEffects } from './effects/admin.effects';
9388

9489
@NgModule({
95-
imports: [
96-
EffectsModule.forFeature([AdminEffects])
97-
]
90+
imports: [EffectsModule.forFeature([AdminEffects])],
9891
})
9992
export class AdminModule {}
10093
```
10194

10295
## API Documentation
103-
- [Controlling Effects](./api.md#controlling-effects)
104-
- [Filtering Actions](./api.md#oftype)
105-
- [Non-dispatching effects](./api.md#non-dispatching-effects)
106-
- [Initializing effect](./api.md#initializing-effect)
107-
- [Utilities](./api.md#utilities)
108-
- [Testing](./testing.md)
96+
97+
* [Controlling Effects](./api.md#controlling-effects)
98+
* [Filtering Actions](./api.md#oftype)
99+
* [Non-dispatching effects](./api.md#non-dispatching-effects)
100+
* [Initializing effect](./api.md#initializing-effect)
101+
* [Utilities](./api.md#utilities)
102+
* [Testing](./testing.md)

Diff for: docs/effects/api.md

+51-34
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,29 @@
55
NgModule for @ngrx/effects.
66

77
### forRoot
8+
89
Registers internal @ngrx/effects services to run in your application. This is required once in your root NgModule.
910

1011
Usage:
12+
1113
```ts
1214
@NgModule({
13-
imports: [
14-
EffectsModule.forRoot([
15-
FirstEffectsClass,
16-
SecondEffectsClass,
17-
])
18-
]
15+
imports: [EffectsModule.forRoot([FirstEffectsClass, SecondEffectsClass])],
1916
})
20-
export class AppModule { }
17+
export class AppModule {}
2118
```
2219

2320
### forFeature
21+
2422
Registers @ngrx/effects services to run with your feature modules.
2523

2624
**Note**: Running an effects class multiple times, either by `forRoot()` or `forFeature()`, (for example via different lazy loaded modules) will not cause Effects to run multiple times. There is no functional difference between effects loaded by `forRoot()` and `forFeature()`; the important difference between the functions is that `forRoot()` sets up the providers required for effects.
2725

2826
Usage:
27+
2928
```ts
3029
@NgModule({
31-
imports: [
32-
EffectsModule.forFeature([
33-
SomeEffectsClass,
34-
AnotherEffectsClass,
35-
])
36-
]
30+
imports: [EffectsModule.forFeature([SomeEffectsClass, AnotherEffectsClass])],
3731
})
3832
export class FeatureModule {}
3933
```
@@ -43,6 +37,7 @@ export class FeatureModule {}
4337
Stream of all actions dispatched in your application including actions dispatched by effect streams.
4438

4539
Usage:
40+
4641
```ts
4742
import { Injectable } from '@angular/core';
4843
import { Actions } from '@ngrx/effects';
@@ -58,6 +53,7 @@ export class SomeEffectsClass {
5853
Filter actions by action types. Specify the action type to allow type-safe mapping to other data on the action, including payload.
5954

6055
Usage:
56+
6157
```ts
6258
import { Injectable } from '@angular/core';
6359
import { Actions, Effect, ofType } from '@ngrx/effects';
@@ -67,68 +63,76 @@ import { tap } from 'rxjs/operators';
6763
export class SomeEffectsClass {
6864
constructor(private actions$: Actions) {}
6965

70-
@Effect() authActions$ = this.actions$.pipe(
66+
@Effect()
67+
authActions$ = this.actions$.pipe(
7168
ofType<LoginAction | LogoutAction>('LOGIN', 'LOGOUT'),
7269
tap(action => console.log(action))
7370
);
7471
}
7572
```
7673

7774
### Non-dispatching Effects
75+
7876
Pass `{ dispatch: false }` to the decorator to prevent dispatching.
7977

8078
Usage:
79+
8180
```ts
8281
import { Injectable } from '@angular/core';
8382
import { Actions, Effect, ofType } from '@ngrx/effects';
8483
import { tap } from 'rxjs/operators';
8584

8685
@Injectable()
8786
export class SomeEffectsClass {
88-
constructor(private actions$: Actions) { }
87+
constructor(private actions$: Actions) {}
8988

90-
@Effect({ dispatch: false }) logActions$ = this.actions$.pipe(
91-
tap(action => console.log(action))
92-
);
89+
@Effect({ dispatch: false })
90+
logActions$ = this.actions$.pipe(tap(action => console.log(action)));
9391
}
9492
```
9593

9694
### Initializing effect
95+
9796
You can execute some code that will be executed directly after the effect class is loaded.
97+
9898
```ts
9999
import { Injectable } from '@angular/core';
100100
import { Actions, Effect, ofType } from '@ngrx/effects';
101-
import { defer } from 'rxjs/observable/defer';
101+
import { defer } from 'rxjs';
102102
import { tap } from 'rxjs/operators';
103103

104104
@Injectable()
105105
export class SomeEffectsClass {
106-
constructor(private actions$: Actions) { }
106+
constructor(private actions$: Actions) {}
107107

108-
@Effect({ dispatch: false }) init$: Observable<any> = defer(() => of(null)).pipe(
109-
tap(() => console.log('init$')),
108+
@Effect({ dispatch: false })
109+
init$: Observable<any> = defer(() => of(null)).pipe(
110+
tap(() => console.log('init$'))
110111
);
111112
}
112113
```
113114

114115
If you want to trigger another action, be careful to add this effect at the end.
116+
115117
```ts
116118
import { Injectable } from '@angular/core';
117119
import { Actions, Effect, ofType } from '@ngrx/effects';
118-
import { defer } from 'rxjs/observable/defer';
120+
import { defer } from 'rxjs';
119121
import { LoginAction, LogoutAction } from './auth';
120122

121123
@Injectable()
122124
export class SomeEffectsClass {
123-
constructor(private actions$: Actions) { }
125+
constructor(private actions$: Actions) {}
124126

125-
@Effect({ dispatch: false }) authActions$ = this.actions$.pipe(
127+
@Effect({ dispatch: false })
128+
authActions$ = this.actions$.pipe(
126129
ofType<LoginAction | LogoutAction>('LOGIN', 'LOGOUT'),
127-
tap(action => console.log(action))
128-
);
130+
tap(action => console.log(action))
131+
);
129132

130133
// Should be your last effect
131-
@Effect() init$: Observable<action> = defer(() => {
134+
@Effect()
135+
init$: Observable<action> = defer(() => {
132136
return of(new LogoutAction());
133137
});
134138
}
@@ -137,21 +141,30 @@ export class SomeEffectsClass {
137141
## Controlling Effects
138142

139143
### OnRunEffects
144+
140145
By default, effects are merged and subscribed to the store. Implement the `OnRunEffects` interface to control the lifecycle of the resolved effects.
141146

142147
Usage:
148+
143149
```ts
144150
import { Injectable } from '@angular/core';
145-
import { Actions, Effect, OnRunEffects, EffectNotification, ofType } from '@ngrx/effects';
151+
import {
152+
Actions,
153+
Effect,
154+
OnRunEffects,
155+
EffectNotification,
156+
ofType,
157+
} from '@ngrx/effects';
146158
import { Action } from '@ngrx/store';
147-
import { Observable } from 'rxjs/Observable';
159+
import { Observable } from 'rxjs';
148160
import { exhaustMap, takeUntil, tap } from 'rxjs/operators';
149161

150162
@Injectable()
151163
export class UserEffects implements OnRunEffects {
152164
constructor(private actions$: Actions) {}
153165

154-
@Effect() updateUser$: Observable<Action> = this.actions$.pipe(
166+
@Effect()
167+
updateUser$: Observable<Action> = this.actions$.pipe(
155168
ofType('UPDATE_USER'),
156169
tap(action => {
157170
console.log(action);
@@ -161,9 +174,11 @@ export class UserEffects implements OnRunEffects {
161174
ngrxOnRunEffects(resolvedEffects$: Observable<EffectNotification>) {
162175
return this.actions$.pipe(
163176
ofType('LOGGED_IN'),
164-
exhaustMap(() => resolvedEffects$.pipe(
165-
takeUntil(this.actions$.pipe(ofType('LOGGED_OUT')))
166-
))
177+
exhaustMap(() =>
178+
resolvedEffects$.pipe(
179+
takeUntil(this.actions$.pipe(ofType('LOGGED_OUT')))
180+
)
181+
)
167182
);
168183
}
169184
}
@@ -172,9 +187,11 @@ export class UserEffects implements OnRunEffects {
172187
## Utilities
173188

174189
### mergeEffects
190+
175191
Manually merges all decorated effects into a combined observable.
176192

177193
Usage:
194+
178195
```ts
179196
import { mergeEffects } from '@ngrx/effects';
180197

Diff for: docs/effects/testing.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
## @ngrx/effects/testing
44

55
### provideMockActions
6+
67
Provides a mock test provider of the `Actions` Observable for testing effects. This works well with writing
78
marble tests and tests using the `subscribe` method on an Observable. The mock Actions will deliver a new Observable to subscribe to for each test.
89

910
Details on marble tests and their syntax, as shown in the `hot` and `cold` methods, can be found in [Writing Marble Tests](https://github.com/ReactiveX/rxjs/blob/master/doc/writing-marble-tests.md).
1011

1112
Usage:
13+
1214
```ts
1315
import { TestBed } from '@angular/core/testing';
1416
import { provideMockActions } from '@ngrx/effects/testing';
1517
import { ReplaySubject } from 'rxjs/ReplaySubject';
1618
import { hot, cold } from 'jasmine-marbles';
17-
import { Observable } from 'rxjs/Observable';
19+
import { Observable } from 'rxjs';
1820

1921
import { MyEffects } from './my-effects';
2022
import * as MyActions from '../actions/my-actions';
@@ -62,10 +64,12 @@ describe('My Effects', () => {
6264
```
6365

6466
### getEffectsMetadata
67+
6568
Returns decorator configuration for all effects in a class instance.
6669
Use this function to ensure that effects have been properly decorated.
6770

6871
Usage:
72+
6973
```ts
7074
import { TestBed } from '@angular/core/testing';
7175
import { EffectsMetadata, getEffectsMetadata } from '@ngrx/effects';

0 commit comments

Comments
 (0)