import { assert } from '@ember/debug'; import Component from '@ember/component'; import { set, get, computed } from '@ember/object'; import hbs from 'htmlbars-inline-precompile'; export default Component.extend({ // passed from outside onChange: null, wrapResponse: true, ttl: null, wrapTTL: computed('wrapResponse', 'ttl', function() { const { wrapResponse, ttl } = this.getProperties('wrapResponse', 'ttl'); return wrapResponse ? ttl : null; }), didRender() { this._super(...arguments); get(this, 'onChange')(get(this, 'wrapTTL')); }, init() { this._super(...arguments); assert('`onChange` handler is a required attr in `' + this.toString() + '`.', get(this, 'onChange')); }, layout: hbs`
{{#if wrapResponse}} {{ttl-picker data-test-wrap-ttl-picker=true labelText='Wrap TTL' onChange=(action (mut ttl))}} {{/if}}
`, actions: { changedValue(key, event) { const { type, value, checked } = event.target; const val = type === 'checkbox' ? checked : value; set(this, key, val); get(this, 'onChange')(get(this, 'wrapTTL')); }, }, });