Update @on and @observes to work with native class syntax
This commit is contained in:
parent
b229e7a865
commit
217abaf446
@ -1,4 +1,9 @@
|
||||
import { on as emberOn } from "@ember/object/evented";
|
||||
import {
|
||||
observes as emberObservesDecorator,
|
||||
on as emberOnDecorator,
|
||||
} from "@ember-decorators/object";
|
||||
|
||||
import { observer } from "@ember/object";
|
||||
import {
|
||||
alias as EmberAlias,
|
||||
@ -37,6 +42,8 @@ import handleDescriptor from "discourse-common/utils/handle-descriptor";
|
||||
import isDescriptor from "discourse-common/utils/is-descriptor";
|
||||
import macroAlias from "discourse-common/utils/macro-alias";
|
||||
import discourseDebounce from "discourse-common/lib/debounce";
|
||||
import CoreObject from "@ember/object/core";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
|
||||
export default function discourseComputedDecorator(...params) {
|
||||
// determine if user called as @discourseComputed('blah', 'blah') or @discourseComputed
|
||||
@ -112,11 +119,39 @@ export function debounce(delay, immediate = false) {
|
||||
};
|
||||
}
|
||||
|
||||
export const on = decoratorAlias(emberOn, "Can not `on` without event names");
|
||||
export const observes = decoratorAlias(
|
||||
observer,
|
||||
"Can not `observe` without property names"
|
||||
);
|
||||
export function on(...onParams) {
|
||||
return function (target) {
|
||||
if (target instanceof CoreObject) {
|
||||
deprecated(
|
||||
`Using 'on' from 'discourse-common/utils/decorators' as a class property decorator is deprecated. You should import it from '@ember-decorators/object' instead.`,
|
||||
{ id: "discourse.utils-decorators-import-on" }
|
||||
);
|
||||
return emberOnDecorator(...onParams)(...arguments);
|
||||
} else {
|
||||
return decoratorAlias(
|
||||
emberOn,
|
||||
"Can not `on` without event names"
|
||||
)(...onParams)(...arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function observes(...observeParams) {
|
||||
return function (target) {
|
||||
if (target instanceof CoreObject) {
|
||||
deprecated(
|
||||
`Using 'observes' from 'discourse-common/utils/decorators' as a class property decorator is deprecated. You should import it from '@ember-decorators/object' instead.`,
|
||||
{ id: "discourse.utils-decorators-import-on" }
|
||||
);
|
||||
return emberObservesDecorator(...observeParams)(...arguments);
|
||||
} else {
|
||||
return decoratorAlias(
|
||||
observer,
|
||||
"Can not `observe` without property names"
|
||||
)(...observeParams)(...arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const alias = macroAlias(EmberAlias);
|
||||
export const and = macroAlias(EmberAnd);
|
||||
|
||||
Reference in New Issue
Block a user