plumatic / dommy

A tiny ClojureScript DOM manipulation and event library
759 stars 73 forks source link

Extend DOM collection class *instances* with cljs protocols #76

Closed pangloss closed 7 years ago

pangloss commented 10 years ago

This is the replacement for pr #51. I've renamed the clobber library to synergize now that it works using specify! and doesn't need to modify the environment anymore.

I think it's a real improvement that the browser's built in lazy data structures aren't being forced and cloned anymore.

In addition, this makes other interesting functionality possible. For instance, I added an (attributes el) function that returns a 'synergized' NamedNodeMap that acts as a transient map to element attributes. If an attribute is associated or dissociated using assoc! or dissoc!, that attribute can be set directly on the node. It also allows you to get attributes from a node using destructuring: (let [{:keys [id class]} (attributes el)] ...). Similar functionality should be possible also with CSS style declarations, though I haven't looked in as much detail at those classes yet.

As before, feedback is welcome!

jeluard commented 10 years ago

I personally think this would be a bad move because it introduces an external dependency to just remove 2 calls to Array.prototype.slice. It introduces a risk if a project relies on both dommy and synergize either directly or through another dependency. I don't think ClojureScript has some mechanism to prevent collisions in such scenario.

A similar argument has already been done on the Clojure mailing list about low-level librairies and Java dependencies. I believe it applies here too.

@pangloss nothing specific about your library, I just don't believe dommy should depend on external libraries for such simple features.

An idea could be to provide some documentation to show how to use dommy and synergize together in your own project, if that makes sense.