Coder Social home page Coder Social logo

Get actual data by cursor? about om HOT 8 CLOSED

omcljs avatar omcljs commented on July 17, 2024
Get actual data by cursor?

from om.

Comments (8)

swannodette avatar swannodette commented on July 17, 2024

The only time you need this is if some reason the cursor is "stale". I think we need to think through preventing the likelihood of this case. What are you trying to do that made you need actualize?

from om.

amakurin avatar amakurin commented on July 17, 2024

Ok. I have range-editor component, with slider and textboxes. Two handles of slider and two textboxes are subcomponents themself, and puts updates in common channel. Editor handles change events by handle-change function

(defn range-editor [range-value {:keys [min-bottom max-top] :as opts}]
  (let [config {:bottom (fn [v] (min (max min-bottom v) (:top (actualize range-value))))
                :top (fn [v] (max (min max-top v) (:bottom (actualize range-value))))}

        handle-change (fn[{:keys [bound value] :as e}]
                        (when (not(js/isNaN value))
                          (om/update! range-value [bound] (fn [_] ((bound config) value)))))]
  (reify
...

where i have updated bound and its new value. I found that after updating the cursor is always "stale", but in other cases i could solve this without actualize by restructuring my code.

from om.

swannodette avatar swannodette commented on July 17, 2024

Ok this appears to be true because you are closing over the cursor for some reason? I suspected early on this might be an issue, I'm inclined to make update! error out if given a stale cursor because it's likely to be too large a source of confusion. Needs more thought.

from om.

amakurin avatar amakurin commented on July 17, 2024

I'm using cursor this way:
first, on render of root component:

...
(om/build uire/range-editor app {:path [:monthly-cost-range] 
                                :opts {:min-bottom 0 :max-top 80000 :step 500 }})
...

then, on render of range-editor i'm giving whole range to subcomponents, cuz cant split it to leafs, which are numbers (subcomponents only reads cursor to render)

...
(om/build slider-handle range-value {:opts bottom-opts})
...

and the only place where i update! is in range-editor's handle-change (snippet in prev comment).
Am i doing not as designed?

from om.

swannodette avatar swannodette commented on July 17, 2024

I still can't see why your design requires you to dereference cursors. It seems like the range-editor should be storing and accessing its bounds in local component state via om.core/set-state!, om.core/get-state which would allow you to avoid these issues.

from om.

amakurin avatar amakurin commented on July 17, 2024

Yes.. i can do so and this allow to avoid troubles but i want changes of bounds to affect my app-state, cuz range editors are parts of more complex, let's say "filter". Filter has its actual state which i can use without composing it by controls-state... Of course i can duplicate range data in editor's state but... actualize seems to be pretty.
By the way updated actualize (may be helpful for somebody)

(defn actualize [cursor]
  (let [state (.-state cursor)
        path (.-path cursor)]
    (if (empty? path)
      @state
      (get-in @state path))))

Actually i do not meaningly dereference cursor. I thought dereferencing happens when range data updates on DRAG event of google.fx.Dragger, cuz it is out of React scope or something like that...

from om.

swannodette avatar swannodette commented on July 17, 2024

I'm pretty convinced actualize is a bad idea and I will likely make update! throw on stale cursors.

from om.

swannodette avatar swannodette commented on July 17, 2024

Ok after further consideration this actually supported now that I have a better feel for the semantics. You can only read from cursors from within a React render pass. Asynchronous operations like event handlers are no longer allowed to do any operations on cursors as they are outside of render, to read the latest value of a cursor you may use om.core/read in master.

from om.

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.