Skip to content

Instantly share code, notes, and snippets.

@offirgolan
Last active April 1, 2016 21:52
Show Gist options
  • Save offirgolan/b972368d3a07da5dba8986c39462168f to your computer and use it in GitHub Desktop.
Save offirgolan/b972368d3a07da5dba8986c39462168f to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
import CRUD from '../mixins/crud';
const { computed } = Ember;
export default Ember.Component.extend(CRUD, {
validations: computed(function() {
this._super(); // this is actually pointing to CRUD.actions.save instead of parent.validations
return {};
}),
init() {
this._super(...arguments);
this.set('emitted', []);
},
actions: {
save() {
// Get validations object which calls _super.
// _super should return the parent validation
// object but instead it calls the save action in
// the CRUD mixin
const validations = this.get('validations');
this.emitted.pushObject('[my-component] save');
this._super(...arguments);
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
export default Ember.Mixin.create({
actions: {
save(){
this.emitted.pushObject('[crud mixin] save');
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{my-component}}
<br>
<br>
<button {{action 'save'}}>Save</button>
{{emitted}}
{{#each emitted as |e|}}
<p>{{e}}</p>
{{/each}}
{
"version": "0.7.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment