Skip to content

Commit

Permalink
Todo model objects are now observable properties.
Browse files Browse the repository at this point in the history
Temporarily removing loading todos from storage.  Will bring them back shortly.
  • Loading branch information
pbouzakis committed Jun 14, 2012
1 parent 322be5c commit c2ddc31
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions lib/TodosModel.js
@@ -1,10 +1,31 @@
"use strict";
/*global WinJS: false */

var ko = require("knockoutify");

function Todo(name, hasCompleted) {
var that = this;
name = ko.observable(name);
hasCompleted = ko.observable(hasCompleted);

Object.defineProperties(that, {

This comment has been minimized.

Copy link
@domenic

domenic Jun 14, 2012

Contributor

IN-TER-EST-ING!!! I like it. Obviously we can extract into a wrapper, publish as sweet npm package.

name: {
get: function () { return name(); },
set: function (val) { name(val); },
enumerable: true
},
hasCompleted: {
get: function () { return hasCompleted(); },
set: function (val) { hasCompleted(val) },
enumerable: true
}
});
}

var sampleTodos = [
{ name: "Destroy Enemies.", hasCompleted: false },
{ name: "Make Friends.", hasCompleted: false },
{ name: "Conquer The World.", hasCompleted: false }
new Todo("Destroy Enemies.", false),
new Todo("Make Friends.", false),
new Todo("Conquer The World.", false)
];

// I envision the serialization happening by someone who listens to events triggered by this model?
Expand All @@ -19,7 +40,7 @@ module.exports = function TodosModel(initialItems) {
that.dataSource = bindingList.dataSource;

that.add = function (name) {
bindingList.push({ name: name });
bindingList.push(new Todo(name, false));
};

that.delete = function (key) {
Expand Down

0 comments on commit c2ddc31

Please sign in to comment.