Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix bug in model.at(el) lookup inside of a non-each array block

  • Loading branch information...
commit 8166301af03b30185c5f07c1c32f3f977550fb94 1 parent 4f8b496
Nate Smith nateps authored
Showing with 14 additions and 17 deletions.
  1. +6 −5 lib/View.js
  2. +8 −12 lib/derby.Model.js
11 lib/View.js
View
@@ -426,10 +426,12 @@ function bindEvents(events, macro, name, partial, params) {
}
}
-function bindEventsById(events, macro, name, partial, attrs, method, prop, isBlock) {
+function bindEventsById(events, macro, name, partial, attrs, method, prop, blockType) {
function params(triggerId, blockPaths, pathId) {
var id = attrs._id || attrs.id;
- if (isBlock && pathId) blockPaths[id] = pathId;
+ if (blockType && pathId) {
+ blockPaths[id] = {id: pathId, type: blockType};
+ }
return [id, method, prop];
}
bindEvents(events, macro, name, partial, params);
@@ -927,7 +929,7 @@ function pushVar(view, ns, stack, events, macroAttrs, remainder, match, fn) {
, partial = match.partial
, macro = match.macro
, escapeFn = match.escaped && escapeHtml
- , attr, attrs, boundOut, last, tagName, wrap, render, isBlock;
+ , attr, attrs, boundOut, last, tagName, wrap, render;
if (partial) {
var arr = splitPartial(view, partial, ns)
@@ -961,8 +963,7 @@ function pushVar(view, ns, stack, events, macroAttrs, remainder, match, fn) {
addId(view, attrs);
if (!boundOut) {
- isBlock = !!match.type;
- bindEventsById(events, macro, name, fn, attrs, 'html', !fn && escapeFn, isBlock);
+ bindEventsById(events, macro, name, fn, attrs, 'html', !fn && escapeFn, match.type);
}
}
20 lib/derby.Model.js
View
@@ -5,10 +5,6 @@ var EventDispatcher = require('./EventDispatcher')
exports.init = init;
-function isArrayPath(pathMap, model, path) {
- return pathMap.arrays[path] || Array.isArray(model.get(path));
-}
-
// Add support for creating a model alias from a DOM node or jQuery object
Model.prototype.__at = Model.prototype.at;
Model.prototype.at = function(node, absolute) {
@@ -20,17 +16,17 @@ Model.prototype.at = function(node, absolute) {
var blockPaths = this.__blockPaths
, pathMap = this.__pathMap
, root = this._root
- , child, i, id, last, path, pathId, children, len;
+ , child, i, id, last, path, blockPath, children, len;
while (node) {
if (node.$derbyMarkerParent && last) {
node = last;
while (node = node.previousSibling) {
if (!(id = node.$derbyMarkerId)) continue;
- pathId = blockPaths[id];
- if (node.$derbyMarkerEnd || !pathId) break;
+ blockPath = blockPaths[id];
+ if (node.$derbyMarkerEnd || !blockPath) break;
- path = pathMap.paths[pathId];
- if (isArrayPath(pathMap, root, path) && last) {
+ path = pathMap.paths[blockPath.id];
+ if ((blockPath.type === 'each') && last) {
i = 0;
while (node = node.nextSibling) {
if (node === last) {
@@ -46,9 +42,9 @@ Model.prototype.at = function(node, absolute) {
node = last.parentNode;
continue;
}
- if ((id = node.id) && (pathId = blockPaths[id])) {
- path = pathMap.paths[pathId];
- if (isArrayPath(pathMap, root, path) && last) {
+ if ((id = node.id) && (blockPath = blockPaths[id])) {
+ path = pathMap.paths[blockPath.id];
+ if ((blockPath.type === 'each') && last) {
children = node.childNodes;
for (i = 0, len = children.length; i < len; i++) {
child = children[i];
Please sign in to comment.
Something went wrong with that request. Please try again.