Skip to content

Commit

Permalink
feat: compatibility with Ember canary
Browse files Browse the repository at this point in the history
  • Loading branch information
buschtoens committed Mar 6, 2019
1 parent d763efa commit 864e5d7
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,32 @@ export { default as lastValue } from './last-value';
* @returns {object|null}
* @private
*/
function extractValue(desc) {
if ('value' in desc.descriptor) {
return desc.descriptor.value;
function extractValue(desc, allowNoInitializer = false) {
switch (desc.kind) {
case 'method':
assert(
`'${desc.key}' has to be a method on the prototype, not 'static'.`,
desc.placement === 'prototype'
);
const { value } = desc.descriptor;
delete desc.descriptor.value;
desc.kind = 'field';
return value;
case 'field':
assert(
`'${desc.key}' has to be a field on the class instance, not 'static'.`,
desc.placement === 'own'
);
assert(
`'${desc.key}' has no initializer.`,
allowNoInitializer || typeof desc.initializer === 'function'
);
const { initializer } = desc;
delete desc.initializer;
return initializer ? initializer() : null;
default:
assert(`Unsupported kind '${desc.kind}' for '${desc.key}'.`, false);
}
if (typeof desc.initializer === 'function') {
const { initializer } = desc;
delete desc.initializer;

return initializer();
}

return null;
}

/**
Expand Down Expand Up @@ -85,7 +99,7 @@ function createTaskGroupFromDescriptor(desc) {
);
assert(
'ember-concurrency-decorators: Task groups can not accept values.',
!extractValue(desc)
!extractValue(desc, true)
);
return createTaskGroupProperty();
}
Expand Down

0 comments on commit 864e5d7

Please sign in to comment.