Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace computed.volatile with native getter #83

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions addon/services/features.js
@@ -1,9 +1,8 @@
/*eslint-disable no-extra-boolean-cast, no-console */
import Service from '@ember/service';
import { camelize } from '@ember/string';
import { computed } from '@ember/object';

export default Service.extend({
const FeaturesService = Service.extend({

init() {
this._super(...arguments);
Expand Down Expand Up @@ -47,10 +46,6 @@ export default Service.extend({
return isEnabled;
},

flags: computed(function () {
return Object.keys(this._flags);
}).volatile(),

_resetFlags() {
this._flags = Object.create(null);
},
Expand All @@ -77,5 +72,19 @@ export default Service.extend({
unknownProperty(key) {
return this.isEnabled(key);
}
});

// Use a native getter instead of a `volatile` computed property since those
// were deprecated as of Ember 3.9. The Object.defineProperty approach (from
// https://github.com/emberjs/ember.js/issues/17709#issuecomment-469941364 is
// used because defining native getters directly on EmberObject-based classes
// is only supported from Ember 3.9 on (https://github.com/emberjs/ember.js/pull/17710)
// and this preserves compatiblity until this addon drops support for older
// Ember versions.
Object.defineProperty(FeaturesService.prototype, 'flags', {
get() {
return Object.keys(this._flags);
}
});

export default FeaturesService;