Ember Octane Route类是否支持使用mixins? [英] Does Ember Octane Route class support using mixins?

查看:75
本文介绍了Ember Octane Route类是否支持使用mixins?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在升级到Ember Octane,并且我知道不推荐使用mixins。在确定替换方法之前,我将继续使用它们。同时,我想将路线切换为使用新的类语法,而不是 Route.extend 。新的路由类语法是否支持路由混合?如果是,怎么办?

I am upgrading to Ember Octane and I understand that mixins have been deprecated. 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. Does the new route class syntax support route mixins? If yes, how?

这与 Ember辛烷值升级如何将值从组件传递到控制器

辛烷值:

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

export default Route.extend(AbcAuthenticatedRouteMixin, {

    model() {

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

后琥珀辛烷:

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


推荐答案

本机类语法没有与Ember mixin直接对应的语法系统。如果要在转换为Octane时继续使用mixins,可以通过将经典类扩展语法与本机类语法混合来实现:

Native class syntax does not directly have an equivalent for the Ember mixin system. 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:

尝试

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: ''
        };
    }
}

此外,还有一些新的框架类,例如Glimmer组件,根本不支持Ember mixins。将来,mixin将从框架中删除,并且不会直接替换。对于使用mixin的应用程序,建议的路径是将mixin重构为其他模式,包括:

In addition, some new framework classes, such as Glimmer components, do not support Ember mixins at all. In the future, mixins will be removed from the framework, and will not be replaced directly. For apps that use mixins, the recommended path is to refactor the mixins to other patterns, including:


纯本地类,通过类共享功能遗产。
可以导入并在多个类中使用的实用程序函数。
可以注入到多个类中的服务,可以共享
的功能并在它们之间共享状态。

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.

这篇关于Ember Octane Route类是否支持使用mixins?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆