2

When calling om/build, one can send an fn option, which according to the documentation:

  `fn - a function to apply to x before invoking f.`

My question is, when applying om/transact! or om/update! to the cursor (x) that was manipulated by the fn, how does the original cursor get affected?

Asher
  • 1,267
  • 1
  • 12
  • 24

1 Answers1

0

(om/build comp1 (f cursor)) has the same effect as (om/build comp1 cursor {:fn f})

So the answer is that it really depends what f does. As long as (f x) (or its content) is still a cursor, you can om/transact! or om/update! on it (or its content).

For example, if x is {:x 1} and f is #(update-in % [:x] inc), f will apply on the value of the cursor; the underlying atom will not change. When you om/transact! or om/update! on (f x) it'll operate on the atom inside cursor x. On the next render, you'll once again get (f x) based on the updated x.

On the other hand, if f makes x not a cursor (e.g. f is om/value), then you won't be able to om/transact! or om/update! on it at all.

Hope that helps.

David L
  • 136
  • 6