Closed GoogleCodeExporter closed 9 years ago
Maybe. What's the use case?
Original comment by dean.edw...@gmail.com
on 6 Jan 2008 at 3:58
For use with my templating system. Let me explain. MiniWeb is pretty cool, but
didn't suit my needs. So I made a
templating system that uses plain old javascript as a templating language.
I have an echo method to writing text a a "stream" (actually an Array, abused
as string builder). After a while, the
string-embedded javascript became awfull. So I dediced to use JSB for that, and
added the addCss method, which is
adding a selector/behaviour-combo to a RuleList.
With those primitives I can build nice template functions. The top-level
function is wrapped with a bindTo function,
which initializes stuff, afterwards is appending the string builder to the
innerHTML of an element, and binding the
RuleList to the element and it's children.
One problem with this system is keeping the id-attributes of elements unique.
This can be overcome with
conventions, and by not using them too much.
But binding rules on global level is cumbersome, because in that case
id-selectors have to be used (otherwise some
events may register twice). And it also doesn't make sense, since the template
text part is acting on an element's
innerHTML.
Original comment by doek...@gmail.com
on 6 Jan 2008 at 4:57
(changed typo in Title/Summary)
Original comment by doek...@gmail.com
on 6 Jan 2008 at 4:58
The changes you made to allow this introduce a bug. When you override
RuleList.create:
RuleList.create = function(selector, behaviour) {
return new Rule(selector, behaviour, context);
};
all new rules are now bound to this context. This applies to RuleLists that
have been
previously created.
I must admit that I don't like this idea. It introduces an unnecessary level of
complexity. I'm not totally against the idea though. Let me look into it some
more.
ps. I rolled back the changes you commited because of the bug you introduced.
Original comment by dean.edw...@gmail.com
on 6 Jan 2008 at 5:37
What about storing the context in the constructor as property, and pass it to
Rule in RuleList.refresh?
Original comment by doek...@gmail.com
on 6 Jan 2008 at 7:24
I think I have it (roll back if you don't like it). The weird thing is the call
to refresh within the constructor of Rule.
I moved it to the constructor of RuleList.
This is of course changing the behaviour of the Rule-class.
I still think the "auto-refresh" (applying the RuleList on construction-time)
is a bit weird, but understandable. I
also added the option to apply an instance of RuleList to another node.
Original comment by doek...@gmail.com
on 6 Jan 2008 at 8:23
I'm not sure about these changes yet so I'm going to roll them back.
Let me think about this issue for a while..
Original comment by dean.edw...@gmail.com
on 6 Jan 2008 at 9:27
I made a small change to the Rule object that makes it easier to extend JSB.
Rule can now take a Selector object in the constructor function. That means you
can
mess with the Selector object to achieve the result you wanted:
JSB.RuleList = JSB.RuleList.extend({
constructor: function(rules, context) {
extend(this, "put", function(selector, rule) {
selector = new DOM.Selector(selector);
extend(selector, "exec", function() {
return this.base(context);
});
return this.base(selector, rule);
});
this.base(rules);
}
});
Please mark this issue "fixed" if you are happy with this solution.
Original comment by dean.edw...@gmail.com
on 7 Jan 2008 at 12:31
Original comment by doek...@gmail.com
on 7 Jan 2008 at 7:49
Original issue reported on code.google.com by
doek...@gmail.com
on 6 Jan 2008 at 2:41