Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unobtrusive knockout without dom pollution

Are there any "unobtrusive knockout" plugins which do not reintroduce the data-bind attribute to the elements to the dom? I've tried a few like: http://userinexperience.com/?p=633 and the Jquery plugin.

The problem with all of them is that they keep introducing data-bind back into the dom. Is there anything other plugin which can do something more along the lines of putting data-bind in a expando like http://docs.jquery.com/Data

like image 805
maxfridbe Avatar asked Feb 21 '12 17:02

maxfridbe


2 Answers

The Knockout. Unobtrusive plugin was my initial attempt to move away from data-bind attributes, and back when I created it, adding binding model elements back to the DOM was about the only reasonable way I could come up with do do this.

As Ryan points out above, Knockout 2.0 allows the creation of custom bindings providers that replace data-bind attributes with your preferred strategy. As such, I'm currently in the process of updating my plugin to provide one of these providers, which would eliminate any writing to the DOM at runtime. You can checkout my progress on the ko-v2 branch here. Let me know if you have any comments or suggestions. And be warned, I'm just getting started, so nothing is working yet, but I should have another commit or two to share in the next day or so.


2-28-12 Update

I've added some additional tests and functionality at the branch above. The current functionality is basic, but so far meets your requirement of circumventing data-bind.

Let me know what you think. This may end up being spun off into a new project (with Knockout.Unobtrusive shutting down)

like image 117
Brandon Satrom Avatar answered Sep 18 '22 11:09

Brandon Satrom


Here is an article that shows how to create your own custom binding provider: http://www.knockmeout.net/2011/09/ko-13-preview-part-2-custom-binding.html.

It would be easy enough to create a custom binding provider that saves/loads its data from either jQuery $.data or as an expando property (can use ko.utils.domData.get/set).

The binding provider just needs to implement nodeHasBindings and getBindings functions.

If you need further help implementing something like this, then let me know.

like image 26
RP Niemeyer Avatar answered Sep 22 '22 11:09

RP Niemeyer