Permalink
Browse files

create refs to each bound attribute when creating a component

  • Loading branch information...
nateps committed May 15, 2012
1 parent 269b628 commit 242b67cb28d374535659a40fc89ac613aa7c584a
Showing with 16 additions and 9 deletions.
  1. +16 −9 lib/View.js
View
@@ -265,13 +265,18 @@ View.prototype = {
doc.title = title;
}
-, _createComponent: function(view, model, scope, script, ctx) {
+, _createComponent: function(view, model, scope, script, ctx, boundMacro) {
var elements = ctx.$elements
- , id;
- for (name in elements) {
- id = elements[name];
+ , prefix = scope + '.'
+ , key, path, id;
+ for (key in boundMacro) {
+ path = ctxPath(ctx, boundMacro[key]);
+ model.ref(prefix + key, path, null, true);
+ }
+ for (key in elements) {
+ id = elements[key];
if (typeof id !== 'string') continue;
- elements[name] = document.getElementById(id);
+ elements[key] = document.getElementById(id);
}
script.create(model, model.at(scope), view.dom, elements);
}
@@ -510,7 +515,7 @@ function partialValue(view, ctx, model, name, value, listener, macro) {
return name ? dataValue(view, ctx, model, name, macro) : true;
}
-function partialFn(view, name, type, alias, render, macroCtx, macro) {
+function partialFn(view, name, type, alias, render, macroCtx, macro, boundMacro) {
function conditionalRender(ctx, model, triggerPath, value, index, condition) {
if (condition) {
var renderCtx = extendCtx(ctx, value, name, alias, index);
@@ -536,7 +541,7 @@ function partialFn(view, name, type, alias, render, macroCtx, macro) {
library = view._libraries[name[0]];
script = library && library.scripts[name[1]];
if (script) {
- setTimeout(createComponent, 0, view, model, scope, script, renderCtx);
+ setTimeout(createComponent, 0, view, model, scope, script, renderCtx, boundMacro);
}
}
renderCtx.$fnCtx = script;
@@ -731,7 +736,7 @@ function pushVar(view, ns, stack, events, boundMacro, remainder, match, fn) {
, partialName = arr[1]
, alias = partialNs === view._selfNs ? '' : 'self'
render = arr[2]._find(partialName, ns, boundMacro);
- fn = partialFn(view, arr, 'partial', alias, render, match.macroCtx);
+ fn = partialFn(view, arr, 'partial', alias, render, match.macroCtx, null, boundMacro);
}
if (isBound(boundMacro, match, name)) {
@@ -987,7 +992,9 @@ function parse(view, viewName, template, isString, onBind, boundMacro) {
for (attr in attrs) {
value = attrs[attr];
bound = parsePartialAttr(view, viewName, events, attrs, attr, value);
- if (bound) boundMacro[attr] = true;
+ if (bound) {
+ boundMacro[attr] = attrs[attr].$macroVar;
+ }
}
block = {

0 comments on commit 242b67c

Please sign in to comment.