Skip to content

Commit

Permalink
separate willDestroyElement logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed May 17, 2017
1 parent 4726579 commit 7fc16f8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions addon/create-class-computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ const { defineProperty } = Ember;
const PROPERTIES = new WeakMap();

function findOrCreatePropertyInstance(context, propertyClass, key) {
let isComponent = context instanceof Component;

let propertiesForContext = PROPERTIES.get(context);
if (isNone(propertiesForContext)) {
propertiesForContext = {};
PROPERTIES.set(context, propertiesForContext);

if (isComponent) {
context.one('willDestroyElement', () => {
PROPERTIES.delete(context);
});
}
}

let property = propertiesForContext[key];
Expand All @@ -38,13 +46,10 @@ function findOrCreatePropertyInstance(context, propertyClass, key) {

propertiesForContext[key] = property;

if (context instanceof Component) {
if (isComponent) {
context.one('willDestroyElement', () => {
property.destroy();
delete propertiesForContext[key];
if (!Object.getOwnPropertyNames(propertiesForContext).length) {
PROPERTIES.delete(context);
}
});
}

Expand Down

0 comments on commit 7fc16f8

Please sign in to comment.