There appears to be some strange timing issue in my application.
I am using a variation on the sortable example, but instead of using internal
state to represent the order of the items, I am using a sort-by function over
the app-state.
I suspect that externalizing this ordering is the source of my issue, but have
yet to create a "minimum example" of the behaviour.
Here's what's happening :
When I re-order the items in the list via the drag/drop, I send a message to
change the sorted-by key over an async channel. (The key is not invisible, it's
data the user cares about, which is why I'm doing this instead of just using
local state).
The sortable component uses this sorted app-state in it's render function
directly (as part of om/build <line item component>)
e.g.
apply dom/ul #js {:className "sortable" :ref "sortable"}
(map
(fn [item]
(if-not (= item ::spacer)
(om/build line-item item {:opts opts
:key :id} )
(sortable-spacer (second
(:cell-dimensions state)))))
(sorting-state (util/sorted-list items)
owner))))))
where sorting-state injects the spacer "on the fly"
(defn sorting-state [init-list owner]
(if (ux/dragging? owner)
(let [state (om/get-state owner)
drop-index (:drop-index state)
drag-id (:id (:dragging state))]
(util/insert-at ::spacer drop-index drag-id init-list))
init-list))
Re-ordering appears to work as expected, but every now and then, there's a
mismatch between the cursor as dereferenced by event handlers and the
parameters passed into the function by destructuring e.g. (defn line-item
[{:keys ... :as item} ...]
For example :
(defn line-item [{:keys [id name] :as item} owner opts]
(reify ...
... :onClick #(set-selected % id item )
with
(defn set-selected [e id item ]
(prn "selecting " id (:id @item) )
(om/update! item assoc :selected (not (:selected @item)))
When I click on the line item, id and the dereferenced id (:id @item) do not
match!
(this doesn't happen all the time, which is why I believe it's a timing thing
based on the moment between the component creation (where destructuring is
taking place) and the injection of the atom into the click handler.
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.