[英]Ember Octane How to convert custom mixins
這個問題與: Ember Octane Route class support using mixins 有關嗎? 在 Ember Octane 中正式棄用了 Mixin。
問題:
用什么替換 Ember mixins 的最佳選擇是什么,我如何實現它?
語境:
我有自定義 mixin 來擴展 ember-simple-auth (~v1.8.2) 提供的功能,在創建方法時它不可用(見下文)。 我目前正在使用 ember-simple-auth 3.0.0 https://github.com/simplabs/ember-simple-auth 。 在 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');
}
}
看來我不是唯一一個遇到此問題的人,因為 Simple Auth 不知道他們想要 go 向下的路線: https://github.com/simplabs/ember-simple-auth/issues/2185
選項:
我有以下身份驗證混合:
首先,我想非常清楚地表明,Ember 中的 mixin 並沒有被“正式棄用”,據我所知,甚至沒有關於它的有效 RFC 。 正如升級指南所解釋的,Glimmer 組件不支持 mixin,因為它沒有擴展 EmberObject,但預先存在的框架類(Route、Controller 等)必須這樣做,否則這將是一個重大變化。
沒有替代 mixins 的最佳選擇,因為它取決於 API 的使用情況。 如果您要問如何替換 ember-simple-auth mixins,我的回答是在插件本身提供替代 API 之前您不能。 Mixins 和您發布的示例代碼將在可預見的未來繼續工作。
您可以在此 PR 中查看使用 class inheritance 共享功能的示例。
當我遷移到 ember Octane 時,我嘗試替換 ember-simple-auth mixins,我發現這比重寫我自己的身份驗證服務要花很多時間,我在這個 twiddle 中的示例,我正在使用 cookies,如果你是Auth 服務不使用 cookies,您可以自定義適配器以在標頭中包含令牌
我在 Git 上用 ESA 盤旋,我在我的 OP 中引用的同一問題已被一個隨后合並的新問題關閉:
https://github.com/simplabs/ember-simple-auth/pull/2198
ESA 現在更新了他們的庫以擺脫路由混合。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.