DEV: Enable @cached decorator for themes and plugins (#19261)

`ember-cached-decorator-polyfill` uses a Babel transformation to apply this polyfill in core. Adding that Babel transformation to themes and plugins will be complex, so we use this to patch it at runtime. This can be removed once `@glimmer/tracking` is updated to a version
with native `@cached` support.
This commit is contained in:
David Taylor 2022-11-30 15:53:54 +00:00 committed by GitHub
parent b0839ccf27
commit 2b53c2cfca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -31,3 +31,18 @@ define("ember-jquery-legacy", ["exports"], function (exports) {
return e.__originalEvent || e.originalEvent;
};
});
// ember-cached-decorator-polyfill uses a Babel transformation to apply this polyfill in core.
// Adding that Babel transformation to themes and plugins will be complex, so we use this to
// patch it at runtime. This can be removed once `@glimmer/tracking` is updated to a version
// with native `@cached` support.
const glimmerTracking = require("@glimmer/tracking");
if (glimmerTracking.cached) {
console.error(
"@glimmer/tracking natively supports the @cached decorator. The polyfill can be removed."
);
} else {
Object.defineProperty(glimmerTracking, "cached", {
get: () => require("ember-cached-decorator-polyfill").cached,
});
}

View File

@ -1,9 +1,11 @@
import Component from "@glimmer/component";
import { inject as service } from "@ember/service";
import { cached } from "@glimmer/tracking";
export default class ReviewableChatMessage extends Component {
@service store;
@cached
get chatChannel() {
return this.store.createRecord(
"chat-channel",