Skip to content

Commit

Permalink
Merge pull request #321 from glimmerjs/fixup-destroyables-for-3.22+
Browse files Browse the repository at this point in the history
Ensure stability of destroyable APIs in Ember 3.22+.
  • Loading branch information
rwjblue committed Dec 10, 2020
2 parents 7567ca7 + 620eade commit 796b672
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/@glimmer/component/addon/-private/destroyables.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOTE: DO NOT MODIFY
//
// This module is clobbered by ember-addon-main when used in Ember >= 3.20.0-beta.4
const DESTROYING = new WeakMap<object, boolean>();
const DESTROYED = new WeakMap<object, boolean>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const scheduledDestroyComponent = gte('3.20.0-beta.4')
};

const destroy = gte('3.20.0-beta.4')
// @ts-ignore
? Ember.__loader.require('@glimmer/runtime').destroy
? Ember.destroy
: (component: GlimmerComponent) => {
if (component.isDestroying) {
return;
Expand All @@ -55,7 +54,10 @@ const destroy = gte('3.20.0-beta.4')
};


const registerDestructor = gte('3.20.0-beta.4')
const registerDestructor = gte('3.22.0-beta')
// @ts-ignore
? Ember._registerDestructor
: gte('3.20.0-beta.4')
// @ts-ignore
? Ember.__loader.require('@glimmer/runtime').registerDestructor
: undefined;
Expand Down
17 changes: 16 additions & 1 deletion packages/@glimmer/component/ember-addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,22 @@ module.exports = {
let checker = new VersionChecker(this.project);
let dep = checker.for('ember-source');

if (dep.gte('3.20.0-beta.4')) {
// Ember shipped public API directly, this is more likely to be stable over time
if (dep.gte('3.22.0-beta.1')) {
let destroyablesOverride = writeFile(
'-private/destroyables.ts',
`
import Ember from 'ember';
export const isDestroying = Ember._isDestroying;
export const isDestroyed = Ember._isDestroyed;
`
);

trees.push(destroyablesOverride);
} else if (dep.gte('3.20.0-beta.4')) {
// using internals to access from `@glimmer/runtime`

let destroyablesOverride = writeFile(
'-private/destroyables.ts',
`
Expand Down

0 comments on commit 796b672

Please sign in to comment.