From 27b05c6e436c68a3ec9efd843b8c8bc93f3575ef Mon Sep 17 00:00:00 2001
From: "julien@igel.co.jp"
Date: Wed, 11 Apr 2012 12:49:13 +0900
Subject: [PATCH] Dynamic tree display; next up: property monitoring
---
bender.js | 29 ++++++++++++---------
index.html | 8 ++++++
lib/tree.html | 46 +++++++++++++++++++++++++++++++++
lib/tree.xml | 67 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/hello.xml | 4 +--
5 files changed, 140 insertions(+), 14 deletions(-)
create mode 100644 lib/tree.html
create mode 100644 lib/tree.xml
diff --git a/bender.js b/bender.js
index f628be2..877fa6f 100644
--- a/bender.js
+++ b/bender.js
@@ -50,6 +50,7 @@
context._refreshed_instance = function(instance)
{
flexo.remove_from_array(render_queue, instance);
+ flexo.notify(this, "@refresh", { instance: instance });
};
context._refresh_instance = function(instance)
{
@@ -255,8 +256,7 @@
// Render content: record the top-level target for this content,
// the node itself to fetch its attributes, the target
// instance (since we may switch instances to record ids inside
- // this node) and the parent content (TODO we don't use this at
- // the moment, but we should?)
+ // this node) and the parent content
content = { target: dest, node: ch, instance: this,
parent: content };
if (this.use.childNodes.length > 0) {
@@ -295,16 +295,21 @@
d.setAttribute(attr.localName, attr.value);
}
}, this);
- if (content && dest === content.target) {
- [].forEach.call(content.node.attributes, function(attr) {
- if (attr.name === "id") return;
- if (attr.name === "content-id") {
- content.instance.views[attr.value.trim()] = d;
- } else {
- d.setAttribute(attr.name, attr.value);
- }
- });
- }
+ var content_id = function(content) {
+ if (content && dest === content.target) {
+ flexo.log("content: node=", content.node, "parent=", content.parent);
+ content_id(content.parent);
+ [].forEach.call(content.node.attributes, function(attr) {
+ if (attr.name === "id") return;
+ if (attr.name === "content-id") {
+ content.instance.views[attr.value.trim()] = d;
+ } else {
+ d.setAttribute(attr.name, attr.value);
+ }
+ });
+ }
+ };
+ content_id(content);
dest.insertBefore(d, ref);
if (dest === this.target) {
[].forEach.call(this.use.attributes, function(attr) {
diff --git a/index.html b/index.html
index 646df7b..cc818f2 100644
--- a/index.html
+++ b/index.html
@@ -345,6 +345,8 @@ The component, app and context elements
href="https://github.com/bendr/bender/blob/master/lib/timer.xml">timer,
or larger components relying on other components like toolbars,
dialogs, all the way to complete applications.
+ Document @refresh event from context when
+ component instances are refreshed.