Skip to content

Commit

Permalink
docs(migration): Update migration docs and add example of injecting r…
Browse files Browse the repository at this point in the history
…educers (#100)
  • Loading branch information
brandonroberts authored and MikeRyanDev committed Jul 19, 2017
1 parent 5e5d7dd commit 1bbd5bf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
17 changes: 15 additions & 2 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@

This guide covers the changes between the ngrx projects migrating from V1.x/2.x to V4.

[@ngrx/core](#ngrxcore)
[@ngrx/store](#ngrxstore)
[@ngrx/effects](#ngrxeffects)
[@ngrx/router-store](#ngrxrouter-store)
[@ngrx/store-devtools](#ngrxstore-devtools)

## @ngrx/core
@ngrx/core is no longer used, and can conflict with @ngrx/store. You should remove it from your project.
@ngrx/core is no longer needed, and can conflict with @ngrx/store. You should remove it from your project.

BEFORE:

```ts
import { compose } from '@ngrx/core/compose';
```

AFTER:

```ts
import { compose } from '@ngrx/store';
```

## @ngrx/store

Expand Down Expand Up @@ -191,7 +204,7 @@ describe('My Effects', () => {

it('should work', () => {
actions = hot('--a-', { a: SomeAction, ... });

const expected = cold('--b', { b: AnotherAction });

expect(effects.someSource$).toBeObservable(expected);
Expand Down
3 changes: 2 additions & 1 deletion docs/store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export class MyAppComponent {
- [Selectors](./selectors.md)
- [State composition through feature modules](./api.md#feature-module-state-composition)
- [Providing initial state](./api.md#initial-state)
- [Reducer composition](./api.md#reducer-factory)
- [Meta-Reducers](./api.md#meta-reducers)
- [Injecting reducers](./api.md#injecting-reducers)

### Additional Material
- [From Inactive to Reactive with ngrx](https://www.youtube.com/watch?v=cyaAhXHhxgk)
Expand Down
34 changes: 33 additions & 1 deletion docs/store/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getInitialState() {
})
```

## Reducer Factory
## Meta Reducers

@ngrx/store composes your map of reducers into a single reducer. Use the `metaReducers`
configuration option to provide an array of meta-reducers that are composed from right to left.
Expand Down Expand Up @@ -91,3 +91,35 @@ import { reducers } from './reducers';
})
export class FeatureModule {}
```

## Injecting Reducers

To inject the root reducers into your application, use an `InjectionToken` and a `Provider` to register the reducers through dependency injection.

```ts
import { NgModule, InjectionToken } from '@angular/core';
import { StoreModule, ActionReducerMap } from '@ngrx/store';

import { SomeService } from './some.service';
import * as fromRoot from './reducers';

export const REDUCER_TOKEN = new InjectionToken<ActionReducerMap<fromRoot.State>>('Registered Reducers');

export function getReducers(someService: SomeService) {
return someService.getReducers();
}

@NgModule({
imports: [
StoreModule.forRoot(REDUCER_TOKEN),
],
providers: [
{
provide: REDUCER_TOKEN,
deps: [SomeService],
useFactory: getReducers
}
]
})
export class AppModule { }
```

0 comments on commit 1bbd5bf

Please sign in to comment.