简体   繁体   English

Ember Octane Route 类是否支持使用 mixins?

[英]Does Ember Octane Route class support using mixins?

I am upgrading to Ember Octane and I understand that mixins have been deprecated.我正在升级到 Ember Octane,我知道 mixin 已被弃用。 I will continue to use them until I figure out how to replace them.我将继续使用它们,直到我弄清楚如何更换它们为止。 In the meantime, I would like to switch my route over to using the new class syntax, as opposed to Route.extend .与此同时,我想将我的路线切换到使用新的类语法,而不是Route.extend Does the new route class syntax support route mixins?新的路由类语法是否支持路由混合? If yes, how?如果是,如何?

This is related to Ember Octane Upgrade How to pass values from component to controller这与Ember Octane Upgrade How to pass values from component to controller 有关

Pre-ember Octane:余烬前辛烷值:

import Route from '@ember/routing/route';
import AbcAuthenticatedRouteMixin from '../../mixins/abc-authenticated-route-mixin';

export default Route.extend(AbcAuthenticatedRouteMixin, {

    model() {

        return {
            oldPassword: '',
            newPassword: '',
            confirmPassword: ''
        };
    },
})

Post-ember Octane:余烬后辛烷值:

import Route from '@ember/routing/route';
import AbcAuthenticatedRouteMixin from '../../mixins/abc-authenticated-route-mixin';

export default class ChangePasswordRoute extends Route(AbcAuthenticatedRouteMixin, {

    model() {

        return {
            oldPassword: '',
            newPassword: '',
            confirmPassword: ''
        };
    },
}) // I get an error here that says: '{' expected

Native class syntax does not directly have an equivalent for the Ember mixin system.本机类语法没有直接与 Ember 混合系统等效。 If you want to continue using mixins as you convert to Octane, you can do so by mixing classic class extension syntax with native class syntax:如果您想在转换为 Octane 时继续使用 mixins,可以通过将经典类扩展语法与本机类语法混合来实现:

Try尝试

import Route from '@ember/routing/route';
import AbcAuthenticatedRouteMixin from '../../mixins/abc-authenticated-route-mixin';

export default class ChangePasswordRoute extends Route.extend(AbcAuthenticatedRouteMixin) {

    model() {

        return {
            oldPassword: '',
            newPassword: '',
            confirmPassword: ''
        };
    }
}

In addition, some new framework classes, such as Glimmer components, do not support Ember mixins at all.此外,一些新的框架类,例如 Glimmer 组件,根本不支持 Ember mixins。 In the future, mixins will be removed from the framework, and will not be replaced directly.未来,mixin 将被从框架中移除,不会被直接替换。 For apps that use mixins, the recommended path is to refactor the mixins to other patterns, including:对于使用 mixins 的应用程序,推荐的路径是将 mixin 重构为其他模式,包括:

Pure native classes, sharing functionality via class inheritance.纯原生类,通过类继承共享功能。 Utility functions which can be imported and used in multiple classes.可以在多个类中导入和使用的实用函数。 Services which can be injected into multiple classes, sharing functionality and state between them.可以注入多个类的服务,在它们之间共享功能和状态。

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

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