Ember Octane Route class 是否支持使用 mixin?
Does Ember Octane Route class support using mixins?
我正在升级到 Ember Octane 并且我知道 mixin 已被弃用。我将继续使用它们,直到我弄清楚如何更换它们。与此同时,我想将我的路线切换为使用新的 class 语法,而不是 Route.extend
。新的路由 class 语法是否支持路由混合?如果是,怎么做?
这与
有关
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
原生 class 语法没有直接对应于 Ember mixin 系统。如果您想在转换为 Octane 时继续使用 mixins,您可以通过将 classic class 扩展语法与本机 class 语法混合来实现:
尝试
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: ''
};
}
}
此外,一些新框架 classes,例如 Glimmer 组件,根本不支持 Ember mixins。以后mixins会从framework中移除,不会直接替换。对于使用 mixins 的应用程序,推荐的路径是将 mixins 重构为其他模式,包括:
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 并且我知道 mixin 已被弃用。我将继续使用它们,直到我弄清楚如何更换它们。与此同时,我想将我的路线切换为使用新的 class 语法,而不是 Route.extend
。新的路由 class 语法是否支持路由混合?如果是,怎么做?
这与
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
原生 class 语法没有直接对应于 Ember mixin 系统。如果您想在转换为 Octane 时继续使用 mixins,您可以通过将 classic class 扩展语法与本机 class 语法混合来实现:
尝试
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: ''
};
}
}
此外,一些新框架 classes,例如 Glimmer 组件,根本不支持 Ember mixins。以后mixins会从framework中移除,不会直接替换。对于使用 mixins 的应用程序,推荐的路径是将 mixins 重构为其他模式,包括:
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.