Giter Club home page Giter Club logo

Comments (4)

 avatar commented on May 13, 2024

I encountered the same problem when implementing todo-mvc application (https://github.com/ITEdge/todo-mvc-pedestal), but i think it's actually a domina library bug, not the pedestal one. As a workaround i recommend wrappoing every dynamic html content div in a appropriate wrapper outer html tag and place listeners to this outer tag, this is for example how i solved it in todo-mvc:

<label>
<span field="content:text">Create a TodoMVC template</span>
</label>

A attached a double-click handler to the label field and it's working, but a template under would experience the problem mentioned above:

<label field="content:text">Create a TodoMVC template</label>

from pedestal.

taylorSando avatar taylorSando commented on May 13, 2024

The offending code in domina is here:
https://github.com/levand/domina/blob/master/src/cljs/domina.cljs#L371-#L397

The problem is here:

(doseq [node (nodes content)]
            (events/removeAll node)
            (set! (. node -innerHTML) value))

It's removing all events for all the nodes.

You can grab all the event listeners on an object if you use domina.events/get-listeners

You have to supply the node, event type, so I'd thinking something like:

(let [evt-listeners (map #(domina.events/get-listeners node %) 
                           [:click :dblclick :keydown ...etc] )                                
;; Call to domina/set-html!
;; Put the evt-listeners back on the node

from pedestal.

taylorSando avatar taylorSando commented on May 13, 2024
(defn update-template [t m]
  (doseq [[k v] t {:keys [id type attr-name]} v]
    (case type
      :attr (cond (and (contains? m k) (nil? (get m k)))
                  (d/remove-attr! (d/by-id id) attr-name)
                  (contains? m k)
                  (d/set-attrs! (d/by-id id) {attr-name (get m k)}))
      :content (when (contains? m k)
                 ;; Save any previous event handlers, the call to set-html! wipes out previous event handlers
                 ;; Have to use doall to force evaluation of the lazy seq.  When the handlers are wiped, they
                 ;; can lead to the functions getting garbage collected, this stops it by making sure a reference
                 ;; remains
                 (let [handlers (doall (flatten
                                        (map (fn [evt-type]
                                               ;; Save the listener function and its event type
                                               (map (fn [x] {:fn (.-listener x) :type (.-type x)})
                                                    ;; Get all the listeners given the event type
                                                    (de/get-listeners (d/by-id id) evt-type)))
                                             ;; This is all the possible event types
                                             de/builtin-events)))]
                   ;; Reset the template's html
                   (d/set-html! (d/by-id id) (get m k))
                   ;; Put the event handlers back
                   (when (seq handlers)
                     (doseq [handler handlers]
                       (de/listen! (d/by-id id)  (:type handler)
                                   (:fn handler)))))
                 )
      nil)))

Make sure to include a require for domina.events

[domina.events :as de]

This works, and the tests pass.

from pedestal.

avescodes avatar avescodes commented on May 13, 2024

It’s with a heavy ❤️ that we’ve decided to put pedestal-app on hold for now.

You'll find a replica of this issue at pedestal/pedestal-app#16

from pedestal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.