gokatz
4/8/2016 - 2:05 PM

computed test - chain

computed test - chain

{
  "version": "0.7.2",
  "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.4/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.4/ember-template-compiler.js"
  }
}
{{remaining}}
<br>
<button {{action 'changeTodoFalse'}}>Add false</button>
<button {{action 'changeTodoTrue'}}>Add True</button>
<h1>Welcome to {{appName}}</h1>
{{my-component}}
<br>
<br>
import Ember from 'ember';

export default Ember.Controller.extend({
  appName: 'Ember Twiddle',
  fname: 'gokul',
  lname: 'kathir',
  fullname: Ember.computed('fname', 'lname', function(){
  	return `${this.get('fname')} ${this.get('lname')}`
  }),
  desc: Ember.computed('fullname', function(){
  	return `Hello ${this.get('fullname')}`
  }),
    todos: [
    Ember.Object.create({ isDone: false }),
    Ember.Object.create({ isDone: true }),
      Ember.Object.create({ isDone: true }),
    Ember.Object.create({ isDone: true })
  ],

  remaining: Ember.computed('todos.[]', function() {
    var todos = this.get('todos');
    return todos.filterBy('isDone', false).get('length');
  }),
  actions: {
  	setFullname() {
      alert('hai');
    	this.set('fullname', 'arun raj');
    }
  }
});
import Ember from 'ember';

export default Ember.Component.extend({
  todos: [
    Ember.Object.create({ isDone: true }),
    Ember.Object.create({ isDone: false }),
    Ember.Object.create({ isDone: false })
  ],

  remaining: Ember.computed('todos.[]', function() {
    var todos = this.get('todos');
    return todos.filterBy('isDone', false).get('length');
  }),
  
  actions: {
  	changeTodoFalse() {
    	var todos = this.get('todos');
      todos.pushObject(Ember.Object.create({ isDone: false }))
    },
    changeTodoTrue() {
    	var todos = this.get('todos');
      todos.pushObject(Ember.Object.create({ isDone: true }))
    }
  }
  
});