Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Moving DOM Elements Containing Components

$
0
0
What you're trying to do sounds fishy. A DOMElement instance or fragment can only be in one node of the dom; appending DOMElements is an insert or move operation. If you make a document fragment, and append it multiple times, it'll move. The exception is if you're cloning, which might be automatically done for you.

In your case, you're actually creating a clone, which is why you're seeing two inserted events. There's no way around this, and each element is a different entity.

If you want to be more efficient, you can use a delegational approach to bubble events to an appropriate ancestor, and avoid the overhead of needing to add or remove event handlers for each element. This is what can.Control and can.Component do when you use the "{selector} {event}" syntax. Using the can-{event} syntax adds an event handler, so it's more costly, however with low volatility, or when passing scope is important, this is generally not an issue. 

Viewing all articles
Browse latest Browse all 3491

Trending Articles