简体   繁体   中英

Migration from RxJS 5 to RxJS 6 in Angular 4.3 project

So I have a project on Angular 4.3.1 with RxJS 5.4.3? I need to move to RxJS 6 but keep existing version of Angular. I read this guide and steps that i should do is:

  1. Update rxjs to 5.5 version and fix possible errors.
  2. Update to rxjs 6 and install rxjs-compat for compatibility, fix possible error that not covered by rxjs-compat

And I dont need to change existing code: imports, add pipes and other. Everything should work ?

I faced the same issue some days back in my project where installing 'rxjs-compat' fixed the problem temporarily. But, within a week, the project started to throw rxjs errors. Finally, I had to change imports and pipes also. I would strongly recommend to update your code sooner to avoid last minute errors.

RxJS v5.x to v6 Update Guide RxJS v6 has arrived! While this is a major version change (from 5.x to 6.x), we've put in a lot of work to keep the hard breaking changes to a minimum. In most cases, this allows application and library developers to update incrementally and use RxJS v6 without any modifications to their code.

A backward-compatibility layer eases the update process, allowing you to keep your apps working while you address most code changes at your own pace. The overall process can be carried out in stages:

  1. Update to the latest version of RxJS 5.5 and ensure that you've fixed any issues caused by bug fixes.

  2. Install RxJS v6 along with the backward-compatibility package, rxjs-compat.

  3. If your app is affected by the few breaking changes not covered by rxjs-compat, update the affected code according to the instructions provided below.

4.Eventually, you will want to drop the compatibility layer to complete the update to RxJS v6. Doing so will significantly decrease the size of your apps.

To refactor TypeScript code so that it doesn't depend on rxjs-compat, you can use rxjs-tslint.

npm i -g rxjs-tslint
rxjs-5-to-6-migrate -p [path/to/tsconfig.json]
  1. Before RxJS release v7, you will need to remove and replace all use of deprecated functionality.

Backwards compatibility In order to minimize the impact of the upgrade, RxJS v6 releases with a sibling package, rxjs-compat, which provides a compatibility layer between the v6 and v5 APIs. Most developers with existing applications should upgrade by installing both rxjs and rxjs-compat at ^6.0.0:

npm install rxjs@6 rxjs-compat@6 --save

For details about this package, see https://www.npmjs.com/package/rxjs-compat .

The compatibility package increases the bundle size of your application, which is why we recommend removing it as soon as your application and dependencies have been updated. This size increase is exacerbated if you are using a version of Webpack before 4.0.0. For a full explanation of what you will have to update in order to remove rxjs-compat, see Dropping the compatibility layer . Note also that fully updating your application to v6 may expose existing type errors that were not previously shown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM