Skip to content

Commit

Permalink
updated container
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislas Polu committed Apr 17, 2012
1 parent 7b7d0fd commit 3e74de0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
10 changes: 6 additions & 4 deletions cell-0.2.min.js

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

11 changes: 7 additions & 4 deletions src/cell.js
Expand Up @@ -62,11 +62,13 @@ CELL.cell = function(spec, my) {
var _super = {};
var my = my || {};

my.element = null; /* stores the HTML element handled by this cell */
my.path = spec.path || '/'; /* the current cell path */
my.container = spec.container; /* the top level container */

my.children = my.children || {}; /* cell children, created at build time */
my.json = my.json || {}; /* cell json, always up to date */
my.container = spec.container; /* the top level container */

my.element = null; /* stores the HTML element handled by this cell */

// public
var build; /* build(); */
Expand Down Expand Up @@ -134,8 +136,9 @@ CELL.cell = function(spec, my) {
my.json = json;

for(var c in my.children) {
if(my.children.hasOwnProperty(c))
my.children[c].refresh(json[c]);
if(my.children.hasOwnProperty(c) &&
typeof my.json[c] !== 'undefined')
my.children[c].refresh(my.json[c]);
}
bind();
};
Expand Down
29 changes: 26 additions & 3 deletions src/container.js
Expand Up @@ -50,17 +50,38 @@ CELL.container = function(spec, my) {
var my = my || {};

my.name = spec.name || ''; /* the container name */
my.children = {}; /* cell children, created at build time */

my.children = my.children || {}; /* container children, created at build time */
my.json = my.json || {}; /* container json */

// public
var find; /* find(path); */

// protected
var load; /* load(); */
var load; /* load(); */
var refresh; /* refresh(); */


var that = CELL.emitter({});

/**
* RECURSIVE FUNCTION
* Recursively refreshes the elements children. refresh should be implemented
* and `_super.refresh()` called when suited. The refresh function must be in
* charge of updating the UI with the updated json data passed recursively.
* @param data the update data to use to refresh the UI
*/
refresh = function(json) {
if(typeof json !== 'undefined')
my.json = json;

for(var c in my.children) {
if(my.children.hasOwnProperty(c) &&
typeof my.json[c] !== 'undefined')
my.children[c].refresh(json[c]);
}
};

/**
* RECURSIVE FUNCTION
* Recursively finds a cell by its path. useful to call a method exposed
Expand Down Expand Up @@ -90,11 +111,13 @@ CELL.container = function(spec, my) {



CELL.method(that, 'find', find, _super);
CELL.method(that, 'load', load, _super);
CELL.method(that, 'refresh', refresh, _super);
CELL.method(that, 'find', find, _super);

CELL.getter(that, 'children', my, 'children');
CELL.getter(that, 'name', my, 'name');
CELL.getter(that, 'json', my, 'json');

return that;
};

0 comments on commit 3e74de0

Please sign in to comment.