BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
856 stars 130 forks source link

convertMakers to inline attributes #362

Closed syarul closed 7 years ago

syarul commented 7 years ago

First, being using this lib for awhile which is great, thanks, really appreciate the works put into it.

Using script tags for convertMarkers to handle bindings.

this might suite a small template over a page, but for bigger templates with multiple reference sub templates together with the script tags might not be so sane since overall it increase number of lines twice.

How about inline attributes with generate ids something similar like how react/jsx does?

BorisMoore commented 7 years ago

There are many very big and complex sites using JsViews, and the generated script tag markers don't cause any problem from a performance point of view. (Microsoft Azure management portal, Outlook.com, Workspace.com, for example. Also jsviews.com).

Generally people don't need to inspect the DOM at run time, and so don't need to even be aware of the script tag markers. Also JsViews is designed for data-driven views, so it does not make a lot of sense in most cases to also use script to manipulate the DOM. Any given dynamic HTML content should either be driven by data-linking, with JsViews, or by script manipulation - not both. Therefore there is usually no need to traverse the JsViews marker nodes using code.

JsViews lets you data-link to text nodes, even without HTML elements being present, such as:

People: {^{for people}} Name: {^{:name}}{{/for}}

You can add or remove people, and observably (dynamically) change name properties, and the view will update incrementally. This is not possible (at least, not across all browsers) without some kind of marker nodes.

Some platforms force you to use HTML element markup, such as putting a <span> wrapper around the name, above.

From JsViews point of view, you as the page developer will decide on your element structure/hierarchy, and associated CSS styling, and also you choose whether to specify ids on elements. JsViews will never modify or restrict the HTML element hierarchy, or insert ids (overriding or conflicting with your ids). It will add private attributes to elements, and insert script block markers where necessary. But neither of these will affect layout or rendering, nor will they conflict with your own attributes, ids, names, etc.

syarul commented 7 years ago

Hmm, thanks for the explanation. I think the the complexity of the data-bindings and not to bind to element tags such as id, gives the strong reason for jsviews design.