mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
49 lines
1 KiB
JavaScript
49 lines
1 KiB
JavaScript
|
import Ember from 'ember';
|
||
|
|
||
|
const {
|
||
|
computed,
|
||
|
inject: {service},
|
||
|
Component
|
||
|
} = Ember;
|
||
|
|
||
|
const FeatureFlagComponent = Component.extend({
|
||
|
tagName: 'label',
|
||
|
classNames: 'checkbox',
|
||
|
attributeBindings: ['for'],
|
||
|
_flagValue: null,
|
||
|
|
||
|
feature: service(),
|
||
|
|
||
|
isVisible: computed.notEmpty('_flagValue'),
|
||
|
|
||
|
init() {
|
||
|
this._super(...arguments);
|
||
|
|
||
|
this.get(`feature.${this.get('flag')}`).then((flagValue) => {
|
||
|
this.set('_flagValue', flagValue);
|
||
|
});
|
||
|
},
|
||
|
|
||
|
value: computed('_flagValue', {
|
||
|
get() {
|
||
|
return this.get('_flagValue');
|
||
|
},
|
||
|
set(key, value) {
|
||
|
return this.set(`feature.${this.get('flag')}`, value);
|
||
|
}
|
||
|
}),
|
||
|
|
||
|
for: computed('flag', function () {
|
||
|
return `labs-${this.get('flag')}`;
|
||
|
}),
|
||
|
name: computed('flag', function () {
|
||
|
return `labs[${this.get('flag')}]`;
|
||
|
})
|
||
|
});
|
||
|
|
||
|
FeatureFlagComponent.reopenClass({
|
||
|
positionalParams: ['flag']
|
||
|
});
|
||
|
|
||
|
export default FeatureFlagComponent;
|