From 6d5471c9bea9671dec7900a7bc548aea8ddd5a3e Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 11 Jan 2010 17:32:33 -0800 Subject: all files converted to prototype= {} --- src/Model.js | 82 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'src/Model.js') diff --git a/src/Model.js b/src/Model.js index 35f6a1c1..4a3a1806 100644 --- a/src/Model.js +++ b/src/Model.js @@ -1,12 +1,10 @@ -// Copyright (C) 2009 BRAT Tech LLC - // Single $ is special and does not get searched // Double $$ is special an is client only (does not get sent to server) -Model = function(entity, initial) { - this.$$entity = entity; +function Model(entity, initial) { + this['$$entity'] = entity; this.$loadFrom(initial||{}); - this.$entity = entity.title; + this.$entity = entity['title']; this.$migrate(); }; @@ -27,39 +25,41 @@ Model.copyDirectFields = function(src, dst) { } }; -Model.prototype.$migrate = function() { - merge(this.$$entity.defaults, this); - return this; -}; - -Model.prototype.$merge = function(other) { - merge(other, this); - return this; -}; - -Model.prototype.$save = function(callback) { - this.$$entity.datastore.save(this, callback === true ? undefined : callback); - if (callback === true) this.$$entity.datastore.flush(); - return this; -}; - -Model.prototype.$delete = function(callback) { - this.$$entity.datastore.remove(this, callback === true ? undefined : callback); - if (callback === true) this.$$entity.datastore.flush(); - return this; -}; - -Model.prototype.$loadById = function(id, callback) { - this.$$entity.datastore.load(this, id, callback); - return this; -}; - -Model.prototype.$loadFrom = function(other) { - Model.copyDirectFields(other, this); - return this; -}; - -Model.prototype.$saveTo = function(other) { - Model.copyDirectFields(this, other); - return this; -}; +Model.prototype = { + '$migrate': function() { + merge(this['$$entity'].defaults, this); + return this; + }, + + '$merge': function(other) { + merge(other, this); + return this; + }, + + '$save': function(callback) { + this['$$entity'].datastore.save(this, callback === true ? undefined : callback); + if (callback === true) this['$$entity'].datastore.flush(); + return this; + }, + + '$delete': function(callback) { + this['$$entity'].datastore.remove(this, callback === true ? undefined : callback); + if (callback === true) this['$$entity'].datastore.flush(); + return this; + }, + + '$loadById': function(id, callback) { + this['$$entity'].datastore.load(this, id, callback); + return this; + }, + + '$loadFrom': function(other) { + Model.copyDirectFields(other, this); + return this; + }, + + '$saveTo': function(other) { + Model.copyDirectFields(this, other); + return this; + } +}; \ No newline at end of file -- cgit v1.2.3