简体   繁体   English

在 Angular 4.3 项目中从 RxJS 5 迁移到 RxJS 6

[英]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?所以我有一个关于 Angular 4.3.1 和 RxJS 5.4.3 的项目? I need to move to RxJS 6 but keep existing version of Angular.我需要迁移到 RxJS 6 但保留现有的 Angular 版本。 I read this guide and steps that i should do is:我阅读了指南,我应该做的步骤是:

  1. Update rxjs to 5.5 version and fix possible errors.rxjs更新到 5.5版本并修复可能的错误。
  2. Update to rxjs 6 and install rxjs-compat for compatibility, fix possible error that not covered by rxjs-compat更新到rxjs 6并安装rxjs-compat以实现兼容性,修复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.几天前,我在我的项目中遇到了同样的问题,安装“rxjs-compat”暂时解决了这个问题。 But, within a week, the project started to throw rxjs errors.但是,在一周内,该项目开始抛出 rxjs 错误。 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! RxJS v5.x 到 v6 更新指南RxJS v6 来了! 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.虽然这是一个主要的版本更改(从 5.x 到 6.x),但我们已经投入了大量工作以将重大更改保持在最低限度。 In most cases, this allows application and library developers to update incrementally and use RxJS v6 without any modifications to their code.在大多数情况下,这允许应用程序和库开发人员增量更新并使用 RxJS v6,而无需对其代码进行任何修改。

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.更新到最新版本的 RxJS 5.5 并确保您已修复由错误修复引起的任何问题。

  2. Install RxJS v6 along with the backward-compatibility package, rxjs-compat.安装 RxJS v6 以及向后兼容包 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.如果您的应用程序受到 rxjs-compat 未涵盖的少数重大更改的影响,请根据下面提供的说明更新受影响的代码。

4.Eventually, you will want to drop the compatibility layer to complete the update to RxJS v6. 4.最终,您将需要删除兼容层以完成对 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.要重构 TypeScript 代码使其不依赖于 rxjs-compat,您可以使用 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.在 RxJS 发布 v7 之前,您需要删除并替换所有已弃用功能的使用。

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.向后兼容性为了尽量减少升级的影响,RxJS v6 发布了一个兄弟包,rxjs-compat,它提供了 v6 和 v5 API 之间的兼容层。 Most developers with existing applications should upgrade by installing both rxjs and rxjs-compat at ^6.0.0:大多数拥有现有应用程序的开发人员应该通过在 ^6.0.0 安装 rxjs 和 rxjs-compat 来升级:

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

For details about this package, see https://www.npmjs.com/package/rxjs-compat .有关此包的详细信息,请参阅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.如果您使用 4.0.0 之前的 Webpack 版本,则这种大小增加会加剧。 For a full explanation of what you will have to update in order to remove rxjs-compat, see Dropping the compatibility layer .有关删除 rxjs-compat 必须更新的内容的完整说明,请参阅删除兼容层 Note also that fully updating your application to v6 may expose existing type errors that were not previously shown.另请注意,将应用程序完全更新到 v6 可能会暴露之前未显示的现有类型错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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