Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed bugs related to #each blocks #162

Closed
wants to merge 8 commits into from

3 participants

@reneclaus

When model.at() was used to get the path for an element in an #each block it would give an incorrect index if there was text or spaces between the #each block and the contained element.

The fix skips any text nodes in the #each block.

There was another bug where updates to #each blocks wouldn't remove all the right elements when there was space inside the #each block but outside the one element it can contain.

Both bugs could occur for code like:

{#each}
<li>{.}</li>
{/}
reneclaus added some commits
@reneclaus reneclaus When model.at() was used to get the path for an element in an #each b…
…lock it could give an incorrect index. If there was text or spaces between the #each block and the containing element it would give a wrong answer.

The #each block can still only contain one element. It may now contain text surrounding the single element. It may not have any variables outside the single element.
68b894f
@reneclaus reneclaus The setRemove function wasn't handling ranges correctly. This was cau…
…sing removes from #each blocks with ranges (for example some blank text before/after the element) to fail.

I originally used a while loop but the condition wasn't being reevaluated - maybe a browser optimization.
f0723d8
@reneclaus reneclaus Fixed bug in history.refresh resulting from commit cc5982d 0a2b8df
@reneclaus reneclaus Fixed a bug that prevented components from working. a345052
@reneclaus reneclaus Fixed the way settable reactive functions work for functions that req…
…uire multiple arguments.
49750dd
@reneclaus reneclaus Added racer and tracks as submodules. 80c08b4
@reneclaus reneclaus Merge branch 'master' of https://github.com/codeparty/derby
Update racer.
89ac6d4
@reneclaus reneclaus Added a hook to allow me to add my view helper functions for static p…
…ages.
23e2b91
@reneclaus reneclaus closed this
@juzerali

What just happened?

@reneclaus

Sorry, I'm new at using git. I felt bad having this pull request on my fork. When originally submitted it I just wanted to suggest a fix I made. Since then I've added some modifications to the fork that I needed for my project but don't think should be integrated into derby so I wanted to get rid of the pull request. What should I do instead?

@juzerali

Don't worry dude, I was just surprised to see you closing the pull request after making so many commits.

First of all welcome to git and github.

Secondly git users usually create feature branches. That is one branch for one unit of work that you are doing, later you can merge this branch in your main branch that is usually master branch in most cases. When you want to suggest a code change, you can create a branch for it in your repo and send a pull request from that branch. You can continue your personal development, that you don't wish to share, or that you think might not be useful for rest of the community in other branches

I know its all very confusing to a new git user. Git-scm.com is a good resource if you want to learn branching and Distributed workflow. For a quick start however you can skim through this blog.

@IvanGaravito

So what about this? I was having troubles with the each blocks, so I manually modified this to get it working again from the reneclaus@68b894f pull request.

@reneclaus thanks, it works soft again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 7, 2013
  1. @reneclaus

    When model.at() was used to get the path for an element in an #each b…

    reneclaus authored
    …lock it could give an incorrect index. If there was text or spaces between the #each block and the containing element it would give a wrong answer.
    
    The #each block can still only contain one element. It may now contain text surrounding the single element. It may not have any variables outside the single element.
  2. @reneclaus

    The setRemove function wasn't handling ranges correctly. This was cau…

    reneclaus authored
    …sing removes from #each blocks with ranges (for example some blank text before/after the element) to fail.
    
    I originally used a while loop but the condition wasn't being reevaluated - maybe a browser optimization.
  3. @reneclaus
  4. @reneclaus
  5. @reneclaus
  6. @reneclaus
Commits on Jan 15, 2013
  1. @reneclaus
  2. @reneclaus
This page is out of date. Refresh to see the latest.
View
13 .gitignore
@@ -1,5 +1,14 @@
/bin/lib
-node_modules
test-output.tmp
*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
View
7 .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
View
13 lib/Dom.js
@@ -442,10 +442,17 @@ function setRemove(el, ignore, index) {
if (!el.nodeType) {
// Range
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) {
var child, fragment, nextChild, offset, ref, toEl;
View
8 lib/View.js
@@ -36,7 +36,7 @@ var defaultCtx = {
var defaultGetFns = {
equal: function(a, b) {
- return a === b;
+ return a == b;
}
, not: function(value) {
return !value;
@@ -64,8 +64,8 @@ var defaultGetFns = {
};
var defaultSetFns = {
- equal: function(value, a) {
- return value ? [a] : [];
+ equal: function(value, a, b) {
+ return value ? [void 0, a] : [void 0];
}
, not: function(value) {
return [!value];
@@ -672,7 +672,7 @@ function createComponent(view, model, Component, scope, ctx, macroCtx) {
var scoped = model.at(scope)
, marker = '<!--' + scope + '-->'
, prefix = scope + '.'
- , component = new Component(scoped, scope)
+ , component = new Component(view.app, scoped, scope)
, parentFnCtx = model.__fnCtx || ctx.$fnCtx
, silentModel = model.silent()
, i, key, path, value, instanceName, instances
View
3  lib/component.js
@@ -74,7 +74,8 @@ function createLibrary(config, options) {
view._selfLibrary = library;
for (id in scripts) {
- Component = function(model, scope) {
+ Component = function(app, model, scope) {
+ view.app = app ;
this.view = view;
this.model = model;
this.scope = scope;
View
2  lib/derby.Model.js
@@ -30,6 +30,8 @@ Model.prototype.at = function(node, absolute) {
if ((blockPath.type === 'each') && last) {
i = 0;
while (node = node.nextSibling) {
+ if (node.nodeName == '#text')
+ continue;
if (node === last) {
path = path + '.' + i;
break;
View
5 lib/derby.browser.js
@@ -7,6 +7,8 @@ var racer = require('racer')
module.exports = derbyBrowser;
+global = window ;
+
function derbyBrowser(derby) {
// 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
@@ -61,7 +63,8 @@ function createApp(appModule) {
if (!page._routing) {
view._beforeRoute();
tracks.render(page, {
- url: page.params.previous
+ url: page.params.url,
+ previous: page.params.previous
, method: 'exit'
, noNavigate: true
});
View
9 lib/derby.server.js
@@ -116,14 +116,15 @@ function createApp(appModule) {
return app;
}
-function createStatic(root) {
- return new Static(root, this._libraries);
+function createStatic(root, init_view) {
+ return new Static(root, this._libraries, init_view);
}
-function Static(root, libraries) {
+function Static(root, libraries, init_view) {
this.root = root;
this.libraries = libraries;
this.views = {};
+ this.init_view = init_view ;
}
Static.prototype.render = function(name, res, model, ns, ctx, status) {
var view = this.views[name];
@@ -131,6 +132,8 @@ Static.prototype.render = function(name, res, model, ns, ctx, status) {
view = this.views[name] = new View(this.libraries);
view._root = this.root;
view._clientName = name;
+ if (this.init_view)
+ this.init_view (view) ;
}
view.render(res, model, ns, ctx, status, true);
};
View
3  lib/viewPath.js
@@ -338,10 +338,9 @@ function setBoundFn(view, ctx, model, name, value) {
out = set(value);
}
if (!out) return;
-
for (i = 0, len = out.length; i < len; i++) {
value = out[i];
- arg = args[i + numInputs];
+ arg = args[i];
if (~arg.indexOf('(')) {
setBoundFn(view, ctx, model, arg, value);
continue;
1  node_modules/racer
@@ -0,0 +1 @@
+Subproject commit 2df416ded538ca4976f2296d798aae2497c03c53
1  node_modules/tracks
@@ -0,0 +1 @@
+Subproject commit 7d262e30ef8ed34d1c2b2c743ae16c0ca20c1184
View
4 package.json
@@ -14,8 +14,8 @@
"dependencies": {
"dom-shim": ">=0.1.0",
"html-util": ">=0.1.3",
- "tracks": ">=0.1.10",
- "racer": "0.3.13",
+ "tracks": "git://github.com/reneclaus/tracks",
+ "racer": "git://github.com/reneclaus/racer#master",
"chokidar": ">=0.2.6",
"stylus": ">=0.25.0",
"less": ">=1.3.0",
Something went wrong with that request. Please try again.