|
|
|
|
|
by strogonoff
703 days ago
|
|
> To perform any action on the DOM, you need access to the nodes Not really. With declarative approach you can just give HTML to the browser (or some templater) and get your page completely laid out without having any access to any nodes. In fact, declarative approach does also allow to connect handlers with ease (onclick and similar attributes are very much a thing). Using onclick handlers doesn’t scale well if we are talking about Web apps with complex GUIs, but then the naive imperative approach of createElement scales potentially even worse. The approaches that do scale tend to favour declarative approach with isolated imperative logic (such as in event handlers). |
|
Yup, but it's more limited: consider the modal: you can't — without relying on attributes, or worse, the page's structure — hide the modal when clicking on the little cross, in an onclick attribute.
> The approaches that do scale tend to favour declarative approach with isolated imperative logic
I think it's key regardless of the approach: you want to break down your pages in pieces (e.g. "components"), have them eventually communicate with each others, while keeping those communications as local as possible.
Very much in the same way we design programs over small units (procedure, function, object, etc.).