pandell / Spagety

Other
0 stars 0 forks source link

Should container element be in same context as child nodes? #13

Open cjasinsk opened 10 years ago

cjasinsk commented 10 years ago

Currently the container element that the page data-binding is on, is in a different bindingContext than it's contents.

ex:

<div data-bind='page: {id: "test"}'> //context 0
    <h1>Main</h1> //context 1
    <div data-bind="page: {id: "test2"}"> //context 1
        <h2>SubPage</h2> //context 2
    </div>
</div>

In the example above, should the page with id test2 share the same context as the <h2> element?

Currently any events that occur on the node are supplied by the parent context. In other words, the viewModel that would get loaded into the context 2 does not control its own events.

Is this a problem?

If so, here is a reference of getting the outer-html to share bindingContext: https://github.com/mbest/knockout-repeat

If so, another custom binding could be created called something like: page-loader That specifies an html path that loads this other page and then replaces the page-loader with the page itself.