Skip to content

Commit

Permalink
feat: compatibility with Ember canary (#39)
Browse files Browse the repository at this point in the history
* chore(deps): ember canary + ember-concurrency fix

* feat: compatibility with Ember canary

* fix: Ember 3.8

* Revert "chore(deps): ember canary + ember-concurrency fix"

This reverts commit d763efa.
  • Loading branch information
buschtoens committed Mar 6, 2019
1 parent fd1dfcd commit 1f08613
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,42 @@ export { default as lastValue } from './last-value';
* @returns {object|null}
* @private
*/
function extractValue(desc) {
if ('value' in desc.descriptor) {
return desc.descriptor.value;
}
if (typeof desc.initializer === 'function') {
const { initializer } = desc;
delete desc.initializer;
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 initializer();
}
// This somehow happens for Ember pre 3.9 🤷🏼‍
if (desc.initializer) {
const { initializer } = desc;
delete desc.initializer;
return initializer();
}

return null;
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);
}
}

/**
Expand Down Expand Up @@ -85,7 +109,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 1f08613

Please sign in to comment.