-
Notifications
You must be signed in to change notification settings - Fork 2
Description
I have a HB helper, let's call data-bind. It's being used as:
<input {{data-bind name="value" prop="myprop"}}>
it creates two-way data-binding between an DOM-element and an object. During template execution it return html string. Like " id='x1' ". So the above code become <input id='x1'>. It allows later after template executed and its html inserted into DOM find the element and initialize binding.
I understand that with incremeanl-dom two-way binding can be unneeded. But it's just an example of such a helper.
So I'm trying to understand what helper should return in case of ibars backend.
At first attempt I just tried to call: IncrementalDOM.attr("id", <generated_id>); in my helper. But it does nothing.
In debugger I can see generated template 's code as:
IncrementalDOM.elementOpen("div", "idom-430", null, ""
+ (helpers['data-bind'] || (depth0 && HBX.get(depth0, 'data-bind')) || helpers.helperMissing).call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"data-bind","hash":{"prop":"myprop","name":"value",},"data":data})
+ "", ""))
So after my helper returned then IncrementalDOM.elementOpen is called with "undefined" in its last argument. Like: IncrementalDOM.elementOpen("div", "idom-430", null, "undefined")
So ibars expects that helper returns a string for a single attr name. No more.
But the last argument of elementOpen according to the docs is a dynamic list like ...args - http://google.github.io/incremental-dom/#api/elementOpen
It seems logically to support returning an array and convert it into method's args.
Anyway what would be a possible workaround for such a case? What should helper return?
It's mentioned in READ that:
It is however totally possible to create an ad-hoc 'attribute' helper that does that directly on the DOM element. This is again something I never do as in my opionion returning html artifacts from templates smells of anti-pattern.
How such ad-hoc helper could be implemented?