Skip to content

Instantly share code, notes, and snippets.

@acestudiooleg
Last active June 19, 2018 15:43
Show Gist options
  • Select an option

  • Save acestudiooleg/86c2c6546876ad9573fc75d807f02fa8 to your computer and use it in GitHub Desktop.

Select an option

Save acestudiooleg/86c2c6546876ad9573fc75d807f02fa8 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
import { computed } from '@ember/object';
const stateA = 'A';
const stateB = 'B';
const computedSome = (propName, ...criterias) => computed(propName, function() {
const prop = this.get(propName);
return criterias.some(c => c === prop);
});
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
currentState: 'A',
IS_ACTIVE: computedSome('currentState', stateA, stateB),
actions: {
setState(s){
this.set('currentState', s);
}
}
});
<h1>Welcome to {{appName}}</h1>
currentState: {{currentState}}
{{#if IS_ACTIVE}} <br>
You should see it if is action
{{/if}}<br>
<button {{action 'setState' 'A'}}>A</button>
<button {{action 'setState' 'B'}}>B</button>
<button {{action 'setState' 'C'}}>C</button>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.14.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "2.18.2",
"ember-template-compiler": "2.18.2",
"ember-testing": "2.18.2"
},
"addons": {
"ember-data": "2.18.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment