Skip to content

Instantly share code, notes, and snippets.

@ohcibi
Last active January 18, 2016 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohcibi/321e6c1e40f3e73c4357 to your computer and use it in GitHub Desktop.
Save ohcibi/321e6c1e40f3e73c4357 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
foo() {
alert("called");
}
},
selection: [],
appName:'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{x-comp modelId=1 otherFn=(action "foo") selection=(mut selection)}}
{{x-comp modelId=2 otherFn=(action "foo") selection=(mut selection)}}
<br>
<br>
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.2.0",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "2.2.0"
}
}
import Ember from 'ember';
let i = 0;
const computed = Ember.computed;
export default Ember.Component.extend({
selected: computed("selection.[]", "modelId", function() {
return this.get("selection").contains(this.get("modelId"));
}),
click(e) {
this.get("otherFn")();
this.addOrRemoveFromSelection();
},
addOrRemoveFromSelection() {
let selection = this.get("selection"),
modelId = this.get("modelId");
if (selection.contains(modelId)) {
selection.removeObject(modelId);
} else {
selection.addObject(modelId);
}
this.setSelection(selection);
},
setSelection(selection) {
alert(this.get("selection.update"));
if (typeof this.attrs.selection.update === "function") {
this.attrs.selection.update(selection);
}
}
});
{{#if selected}}selected{{/if}}
Add me
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment