Skip to content

Commit f524e79

Browse files
committed
feat(docs): add migration from ngx-model section
1 parent 689a3a1 commit f524e79

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ multiple model support and immutable data exposed as RxJS Observable.
1212
- [Code of Conduct](https://github.com/angular-extensions/model/blob/master/CODE_OF_CONDUCT.md)
1313
- [Contributing](https://github.com/angular-extensions/model/blob/master/CONTRIBUTING.md)
1414
- [Changelog](https://github.com/angular-extensions/model/blob/master/CHANGELOG.md)
15-
- [Blog](https://medium.com/@tomastrajan/model-pattern-for-angular-state-management-6cb4f0bfed87) about introduction to Angular Model Pattern
15+
- [Blog](https://medium.com/@tomastrajan/model-pattern-for-angular-state-management-6cb4f0bfed87) about introduction to Angular Model Pattern
1616
- [Advanced Usage Patterns](https://tomastrajan.github.io/angular-model-pattern-example#/advanced) with more how-tos and examples
1717

1818
## Documentation
@@ -174,12 +174,26 @@ implementation to your project manually.
174174
One of the changes compared to `ngx-model` is that the `@angular-extensions/model` uses new
175175
`providedIn: 'root'` syntax (since Angular 6) so that we don't need to import `NgxModelModule`
176176
or anything similar to register `ModelFactory` into Angular dependency injection (DI) context.
177-
All we have to do is to import `ModelFactory` in the constructor of at least one service in our
177+
All we have to do is to import `ModelFactory` in the constructor of at least one service in our
178178
application like this `constructor(private modelFactory: ModelFactory<SomeType[]>) {}` and we're
179179
good to go. This new feature is called tree-shakeable providers:
180180
181181
> There is now a new, recommended, way to register a provider, directly inside the @Injectable() decorator, using the new providedIn attribute. It accepts 'root' as a value or any module of your application. When you use 'root', your injectable will be registered as a singleton in the application, and you don’t need to add it to the providers of the root module. Similarly, if you use providedIn: UsersModule, the injectable is registered as a provider of the UsersModule without adding it to the providers of the module ([source](https://blog.ninja-squad.com/2018/05/04/what-is-new-angular-6/))
182182
183+
#### Migration from `ngx-model`
184+
185+
Migration should be rather simple, please follow these steps:
186+
187+
1. remove dependency to `ngx-model`
188+
2. install `npm i -S @angular-extensions/model`
189+
3. remove `NgxModelModule` from imports of your `@NgModule` in `App` or `Core` module based on where you added it
190+
4. search and replace imports from `ngx-model` and replace them with `@angular-extensions/model`
191+
5. this should be it! The API didn't change so this should be all that it takes to migrate to the new package
192+
6. (optional) refactor your existing model services to use `@Injectable({ providedIn: 'root' })` (or other module instead of `root`)
193+
instead of `@Injectable()` and remove them from `@NgModule({ providers: [MyModelService] })` of your modules
194+
195+
The 6th step depends on your preferences, it is still possible to use new `@angular-extensions/model` with classic
196+
providers, just use `--module <relative-path-to-module>` flag when generating new model services using schematics
183197
184198
## Contributing
185199

0 commit comments

Comments
 (0)