Skip to content

Commit

Permalink
added addProperty and subscribeChanges on Change
Browse files Browse the repository at this point in the history
  • Loading branch information
Narendra Sisodiya committed Dec 16, 2014
1 parent c9e2d76 commit f486464
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules
.idea


bower_components
38 changes: 37 additions & 1 deletion dist/choona.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@
}
}
},
addProperty: function(obj, prop, getCallback, setCallback) {
var v;
//var v = obj[prop]; //Initialise with Old Property Value
Object.defineProperty(obj, prop, {
enumerable: true,
configurable: true,
get: function() {
getCallback(v);
return v;
},
set: function(value) {
v = value;
setCallback(v);
}
});

},
loadHTML: function(ele, str) {
ele.innerHTML = str;
//TODO - find any submodule
Expand Down Expand Up @@ -192,7 +209,26 @@
"use strict";
choona.Model = choona.EventBus.extend({
initialize: function() {
choona.EventBus.call(this);
choona.EventBus.apply(this, arguments);
this.loadDefaults();
},
loadDefaults: function() {
var self = this;
choona.Util.for(this.defaults, function(v, key) {
self.addProperty(key);
});
},
addProperty: function(key) {
var self = this;
choona.Util.addProperty(this,
key,
function() {
//Get Callback
},
function(val) {
//Set Callback
this.publish("change:" + key);
});
},
publishChange: function() {
this.publish("change");
Expand Down
2 changes: 1 addition & 1 deletion dist/choona.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/Todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
* loading submodule using html syntax inside dom

<subModule id="posts", data-module="window.modules.postModule", data-config="{a:'asd'}"></subModule>
* Think for adding it to xtag

* Full Documentation, API Docs, Demos

* Create underscore template support !
* 2 way binding using underscore template

* If Id is not given then it will append new subModule into current module !!
* Todo video
21 changes: 20 additions & 1 deletion src/choona.Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,26 @@
"use strict";
choona.Model = choona.EventBus.extend({
initialize: function() {
choona.EventBus.call(this);
choona.EventBus.apply(this, arguments);
this.loadDefaults();
},
loadDefaults: function() {
var self = this;
choona.Util.for(this.defaults, function(v, key) {
self.addProperty(key);
});
},
addProperty: function(key) {
var self = this;
choona.Util.addProperty(this,
key,
function() {
//Get Callback
},
function(val) {
//Set Callback
this.publish("change:" + key);
});
},
publishChange: function() {
this.publish("change");
Expand Down
17 changes: 17 additions & 0 deletions src/choona.Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@
}
}
},
addProperty: function(obj, prop, getCallback, setCallback) {
var v;
//var v = obj[prop]; //Initialise with Old Property Value
Object.defineProperty(obj, prop, {
enumerable: true,
configurable: true,
get: function() {
getCallback(v);
return v;
},
set: function(value) {
v = value;
setCallback(v);
}
});

},
loadHTML: function(ele, str) {
ele.innerHTML = str;
//TODO - find any submodule
Expand Down

0 comments on commit f486464

Please sign in to comment.