Comments (8)
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.
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.
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.
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.
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.
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.
I'm pretty convinced actualize is a bad idea and I will likely make update! throw on stale cursors.
from om.
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)
- Can't add custom children on remote ast
- Adding `index` as a parameter to `f` when using build-all HOT 1
- A component that implements IQuery needs data returned, otherwise even statically defined dom elements do not get rendered.
- [Wiki] Components, Identity, & normalization wiki link broken
- Bug on master: `mounted?` breaks in adv optimization
- No queries exist for component path HOT 4
- In reloadable workflow, "No queries exist for component path..."
- Specify :remote reads in transact! HOT 1
- Examples should use `defui`
- om.core and beta2 HOT 8
- Reconciler broken in ClojureScript 1.10.* HOT 6
- om.next Quickstart issues HOT 1
- Wiki Quick Start project.clj doesn't work with java 10 HOT 2
- [Wiki] Quick Start (om.next) - to see console logs Chrome users should enable Verbose output
- uri? already refers to: cljs.core/uri? being replaced by: cognitect.transit/uri? HOT 1
- Add support for componentDidCatch
- Arity exception when calling om.next/reader and om.next/writer with zero arguments in Clojure
- Advanced cljsbuild with default settings emits a warning
- Looks like the updates to GitHub have messed up the om.next docs HOT 1
- Readme Quick Start compilation fails @ bumping cljs version from 1.10.520 -> 1.10.597
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from om.