Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bugs related to #each blocks #162

Closed
wants to merge 8 commits into from
13 changes: 11 additions & 2 deletions .gitignore
@@ -1,5 +1,14 @@
/bin/lib /bin/lib
node_modules
test-output.tmp test-output.tmp
*swp *swp
*un~ /node_modules/stylus
/node_modules/nib
/node_modules/mkdirp
/node_modules/MD5
/node_modules/less
/node_modules/html-util
/node_modules/dom-shim
/node_modules/commander
/node_modules/chokidar
/node_modules/up
/node_modules/.bin
7 changes: 7 additions & 0 deletions .gitmodules
@@ -0,0 +1,7 @@
[submodule "node_modules/racer"]
path = node_modules/racer
url = https://github.com/reneclaus/racer

[submodule "node_modules/tracks"]
path = node_modules/tracks
url = https://github.com/reneclaus/tracks
13 changes: 10 additions & 3 deletions lib/Dom.js
Expand Up @@ -442,10 +442,17 @@ function setRemove(el, ignore, index) {
if (!el.nodeType) { if (!el.nodeType) {
// Range // Range
index += el.startOffset; index += el.startOffset;
el = el.startContainer; var container = el.startContainer;
var n_remove = el.endOffset - el.startOffset ;
for (var i = 0 ; i < n_remove ; i++) {
var child = container.childNodes[index];
if (child) container.removeChild(child);
}
}
else {
var child = el.childNodes[index];
if (child) el.removeChild(child);
} }
var child = el.childNodes[index];
if (child) el.removeChild(child);
} }
function setMove(el, ignore, from, to, howMany) { function setMove(el, ignore, from, to, howMany) {
var child, fragment, nextChild, offset, ref, toEl; var child, fragment, nextChild, offset, ref, toEl;
Expand Down
8 changes: 4 additions & 4 deletions lib/View.js
Expand Up @@ -36,7 +36,7 @@ var defaultCtx = {


var defaultGetFns = { var defaultGetFns = {
equal: function(a, b) { equal: function(a, b) {
return a === b; return a == b;
} }
, not: function(value) { , not: function(value) {
return !value; return !value;
Expand Down Expand Up @@ -64,8 +64,8 @@ var defaultGetFns = {
}; };


var defaultSetFns = { var defaultSetFns = {
equal: function(value, a) { equal: function(value, a, b) {
return value ? [a] : []; return value ? [void 0, a] : [void 0];
} }
, not: function(value) { , not: function(value) {
return [!value]; return [!value];
Expand Down Expand Up @@ -672,7 +672,7 @@ function createComponent(view, model, Component, scope, ctx, macroCtx) {
var scoped = model.at(scope) var scoped = model.at(scope)
, marker = '<!--' + scope + '-->' , marker = '<!--' + scope + '-->'
, prefix = scope + '.' , prefix = scope + '.'
, component = new Component(scoped, scope) , component = new Component(view.app, scoped, scope)
, parentFnCtx = model.__fnCtx || ctx.$fnCtx , parentFnCtx = model.__fnCtx || ctx.$fnCtx
, silentModel = model.silent() , silentModel = model.silent()
, i, key, path, value, instanceName, instances , i, key, path, value, instanceName, instances
Expand Down
3 changes: 2 additions & 1 deletion lib/component.js
Expand Up @@ -74,7 +74,8 @@ function createLibrary(config, options) {
view._selfLibrary = library; view._selfLibrary = library;


for (id in scripts) { for (id in scripts) {
Component = function(model, scope) { Component = function(app, model, scope) {
view.app = app ;
this.view = view; this.view = view;
this.model = model; this.model = model;
this.scope = scope; this.scope = scope;
Expand Down
2 changes: 2 additions & 0 deletions lib/derby.Model.js
Expand Up @@ -30,6 +30,8 @@ Model.prototype.at = function(node, absolute) {
if ((blockPath.type === 'each') && last) { if ((blockPath.type === 'each') && last) {
i = 0; i = 0;
while (node = node.nextSibling) { while (node = node.nextSibling) {
if (node.nodeName == '#text')
continue;
if (node === last) { if (node === last) {
path = path + '.' + i; path = path + '.' + i;
break; break;
Expand Down
5 changes: 4 additions & 1 deletion lib/derby.browser.js
Expand Up @@ -7,6 +7,8 @@ var racer = require('racer')


module.exports = derbyBrowser; module.exports = derbyBrowser;


global = window ;

function derbyBrowser(derby) { function derbyBrowser(derby) {
// This assumes that only a single instance of this module can run at a time, // This assumes that only a single instance of this module can run at a time,
// which is reasonable in the browser. This is written like this so that // which is reasonable in the browser. This is written like this so that
Expand Down Expand Up @@ -61,7 +63,8 @@ function createApp(appModule) {
if (!page._routing) { if (!page._routing) {
view._beforeRoute(); view._beforeRoute();
tracks.render(page, { tracks.render(page, {
url: page.params.previous url: page.params.url,
previous: page.params.previous
, method: 'exit' , method: 'exit'
, noNavigate: true , noNavigate: true
}); });
Expand Down
9 changes: 6 additions & 3 deletions lib/derby.server.js
Expand Up @@ -116,21 +116,24 @@ function createApp(appModule) {
return app; return app;
} }


function createStatic(root) { function createStatic(root, init_view) {
return new Static(root, this._libraries); return new Static(root, this._libraries, init_view);
} }


function Static(root, libraries) { function Static(root, libraries, init_view) {
this.root = root; this.root = root;
this.libraries = libraries; this.libraries = libraries;
this.views = {}; this.views = {};
this.init_view = init_view ;
} }
Static.prototype.render = function(name, res, model, ns, ctx, status) { Static.prototype.render = function(name, res, model, ns, ctx, status) {
var view = this.views[name]; var view = this.views[name];
if (!view) { if (!view) {
view = this.views[name] = new View(this.libraries); view = this.views[name] = new View(this.libraries);
view._root = this.root; view._root = this.root;
view._clientName = name; view._clientName = name;
if (this.init_view)
this.init_view (view) ;
} }
view.render(res, model, ns, ctx, status, true); view.render(res, model, ns, ctx, status, true);
}; };
3 changes: 1 addition & 2 deletions lib/viewPath.js
Expand Up @@ -338,10 +338,9 @@ function setBoundFn(view, ctx, model, name, value) {
out = set(value); out = set(value);
} }
if (!out) return; if (!out) return;

for (i = 0, len = out.length; i < len; i++) { for (i = 0, len = out.length; i < len; i++) {
value = out[i]; value = out[i];
arg = args[i + numInputs]; arg = args[i];
if (~arg.indexOf('(')) { if (~arg.indexOf('(')) {
setBoundFn(view, ctx, model, arg, value); setBoundFn(view, ctx, model, arg, value);
continue; continue;
Expand Down
1 change: 1 addition & 0 deletions node_modules/racer
Submodule racer added at 2df416
1 change: 1 addition & 0 deletions node_modules/tracks
Submodule tracks added at 7d262e
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -14,8 +14,8 @@
"dependencies": { "dependencies": {
"dom-shim": ">=0.1.0", "dom-shim": ">=0.1.0",
"html-util": ">=0.1.3", "html-util": ">=0.1.3",
"tracks": ">=0.1.10", "tracks": "git://github.com/reneclaus/tracks",
"racer": "0.3.13", "racer": "git://github.com/reneclaus/racer#master",
"chokidar": ">=0.2.6", "chokidar": ">=0.2.6",
"stylus": ">=0.25.0", "stylus": ">=0.25.0",
"less": ">=1.3.0", "less": ">=1.3.0",
Expand Down