Skip to content

Instantly share code, notes, and snippets.

@ugisozols
Forked from anonymous/jsbin.uJePUHe.html
Created October 14, 2013 13:39
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 ugisozols/6975759 to your computer and use it in GitHub Desktop.
Save ugisozols/6975759 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script>
<script src="http://builds.emberjs.com.s3.amazonaws.com/tags/v1.0.0/ember.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
</body>
</html>
Todo = Ember.Object.extend({
isDone: false
});
Todos = Ember.Object.extend({
todos: [],
remaining: function() {
return this.get("todos").filterBy("isDone", false).get("length");
}.property("todos.@each")
});
firstTodo = Todo.create();
secondTodo = Todo.create();
thirdTodo = Todo.create();
todos = Todos.create({
todos: [firstTodo, secondTodo]
});
console.log("First run");
console.log(todos.get("remaining"));
firstTodo.set("isDone", true);
console.log("After updating isDone property on firstTodo");
console.log(todos.get("remaining"));
console.log("After adding third todo");
todos.todos.pushObject(thirdTodo);
console.log(todos.get("remaining"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment