Open viksit opened 9 years ago
Alright, I think I've figured this out for basics.
(def store1 (store/create))
(def idx1 (store/ordered-index (store/field-key :lastname) compare))
(store/ensure-index store1 :lastname idx1)
(store/insert! store1 #js {:id 1 :firstname "Joe" :lastname "Smith"})
(store/insert! store1 #js {:id 2 :firstname "Fred" :lastname "Savage"})
(store/insert! store1 #js {:id 3 :firstname "Larry" :lastname "Stooge"})
(store/insert! store1 #js {:id 4 :firstname "Curly" :lastname "Stooge"})
(store/insert! store1 #js {:id 5 :firstname "Mo" :lastname "Stooge"})
(store/insert! store1 #js {:id 6 :firstname "Reginald" :lastname "Quince"})
;; (store/cursor store1)
;; (println store1)
(println (get store1 1))
Looked like there was a bug in the first message, but I'm glad to see you've got it. NativeStore is a pretty sophisticated tool, not many seatbelts. Playing with the SimpleStore implementation in Derive to learn the model and try it out with React is probably the preferred approach for now.
Thanks @eslick - derive itself looks quite datalog like, with a pretty sophisticated query model (from what I could see here: https://github.com/vitalreactor/derive/blob/master/src/derive/examples.temp
I looked at https://github.com/vitalreactor/derive/blob/master/src/derive/simple.cljs already, and I can see utilizing it using Om.
Two questions here would be,
Thanks!
A cursor returns an object that implements IReducable. I did this on purpose so we wouldn't get lazy and constantly be turning it into a seq, but maybe I should add that for easy use at the Repl. Try:
(map :firstname (store/cursor store1))
This should reduce using sequence operations over the cursor and return a seq of first names. Think about these collections as primarily intended for use with transducers.
SimpleStore has nothing to do with om/root. Like NativeStore, the intended use is to be 'out of band' of the default om/root. If you use the on-changes macro in your render loop (see bottom of NativeStore file) then the component will be refreshed whenever state in SimpleStore changes, even if the cursors don't change. SimpleStore is a different way to handle data and selective updating, so it does add a bit to the complexity of an Om component.
Thanks for the reply. Could you point me to some sample code utilizing the on-changes macro?
Also, I've yet been unable to use derive - it seems the docs page is broken?
Are there any examples of using this with Om?
(solved, original issue)
I'm trying to use native store like the following,
and I get
What am I doing wrong here? Is this a bug?
I've git cloned this repo, and added the following deps to my project.clj,
[im.chit/purnam.native "0.4.3"] [prismatic/schema "0.2.6"] [com.vitalreactor/derive "0.2.0-SNAPSHOT"]
Thanks!