[英]Ember Octane How to convert custom mixins
This question is related to: Does Ember Octane Route class support using mixins?这个问题与: Ember Octane Route class support using mixins 有关吗? Mixins are officially deprecated in Ember Octane.
在 Ember Octane 中正式弃用了 Mixin。
Question:问题:
What is the best option to replace Ember mixins with and how do I implement it?用什么替换 Ember mixins 的最佳选择是什么,我如何实现它?
Context:语境:
I have custom mixins that expand functionality offered by ember-simple-auth (~v1.8.2), which was not available at the time the methods were created (see below).我有自定义 mixin 来扩展 ember-simple-auth (~v1.8.2) 提供的功能,在创建方法时它不可用(见下文)。 I am currently using ember-simple-auth 3.0.0 https://github.com/simplabs/ember-simple-auth .
我目前正在使用 ember-simple-auth 3.0.0 https://github.com/simplabs/ember-simple-auth 。 In the documentation on github, they appear to be using their own mixins on Ember Octane as you can see:
在 github 的文档中,他们似乎在 Ember Octane 上使用了自己的 mixin,如您所见:
// my-engine/addon/routes/index.js
import Route from '@ember/routing/route';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default class IndexRoute extends Route.extend(AuthenticatedRouteMixin) {
triggerAuthentication() {
this.transitionToExternal('login');
}
}
It appears that I am not the only one having this issue as Simple Auth doesn't know what route they want to go down either: https://github.com/simplabs/ember-simple-auth/issues/2185看来我不是唯一一个遇到此问题的人,因为 Simple Auth 不知道他们想要 go 向下的路线: https://github.com/simplabs/ember-simple-auth/issues/2185
Options:选项:
I have the following authentication mixins:我有以下身份验证混合:
Firstly I want to make very clear that mixins are not "officially deprecated" in Ember, and to my knowledge there's not even an active RFC about it.首先,我想非常清楚地表明,Ember 中的 mixin 并没有被“正式弃用”,据我所知,甚至没有关于它的有效 RFC 。 As the Upgrade Guides explain, Glimmer components do not support mixins due to not extending EmberObject, but the pre-existing framework classes (Route, Controller, etc) necessarily have to or it would be a breaking change.
正如升级指南所解释的,Glimmer 组件不支持 mixin,因为它没有扩展 EmberObject,但预先存在的框架类(Route、Controller 等)必须这样做,否则这将是一个重大变化。
There is no best option to replace mixins as it depends on the usage of the API.没有替代 mixins 的最佳选择,因为它取决于 API 的使用情况。 If you are asking how to replace ember-simple-auth mixins, my answer is that you can't until the addon itself provides alternative APIs.
如果您要问如何替换 ember-simple-auth mixins,我的回答是在插件本身提供替代 API 之前您不能。 Mixins and the example code you posted will continue working for the foreseeable future.
Mixins 和您发布的示例代码将在可预见的未来继续工作。
You can see an example of using class inheritance to share functionality in this PR .您可以在此 PR 中查看使用 class inheritance 共享功能的示例。
when i migrated to ember Octane i tried to replace ember-simple-auth mixins, i found that it would take me lot of time than rewriting my own authentication service, my example in this twiddle, i am using cookies, Auth service if you are not using cookies, you could customize your adapter to include a token in the headers当我迁移到 ember Octane 时,我尝试替换 ember-simple-auth mixins,我发现这比重写我自己的身份验证服务要花很多时间,我在这个 twiddle 中的示例,我正在使用 cookies,如果你是Auth 服务不使用 cookies,您可以自定义适配器以在标头中包含令牌
I circled back with ESA on Git, and the same issue I cited in my OP has been closed with a new issue that has subsequently been merged:我在 Git 上用 ESA 盘旋,我在我的 OP 中引用的同一问题已被一个随后合并的新问题关闭:
https://github.com/simplabs/ember-simple-auth/pull/2198 https://github.com/simplabs/ember-simple-auth/pull/2198
ESA has now updated their library to get rid of route mixins. ESA 现在更新了他们的库以摆脱路由混合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.