Skip to content

Commit 577dfc2

Browse files
committed
adjust action
1 parent ff4d29b commit 577dfc2

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

packages/@ember/object/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,19 @@ export function observer<T extends AnyFn>(
321321

322322
function action2023(args: Parameters<Decorator>) {
323323
const dec = identifyModernDecoratorArgs(args);
324-
switch (dec.kind) {
325-
case 'method':
326-
dec.context.addInitializer(function (this: any) {
327-
Object.defineProperty(
328-
this,
329-
dec.context.name,
330-
setupAction(this, dec.context.name, dec.value)
331-
);
332-
});
333-
break;
334-
default:
335-
throw new Error(`unimplemented: action on ${dec.kind} ${dec.context.name?.toString()}`);
336-
}
324+
assert(
325+
'The @action decorator must be applied to methods when used in native classes',
326+
dec.kind === 'method'
327+
);
328+
let needsSetup = true;
329+
dec.context.addInitializer(function (this: any) {
330+
if (needsSetup) {
331+
Object.defineProperty(
332+
this.constructor.prototype,
333+
dec.context.name,
334+
setupAction(this.constructor.prototype, dec.context.name, dec.value)
335+
);
336+
needsSetup = false;
337+
}
338+
});
337339
}

0 commit comments

Comments
 (0)