Helpful re-frame events for manipulating and fetching store data
Read a value from db by k
, not-found
or nil
if value not present.
(morley.core/get :my-store-key)
Read a value from db by path
, not-found
or nil
if value not present.
(morley.core/get-in [:my-store-key :nested-key])
Applies assoc to app-db with args
.
(morley.core/assoc :my-store-key {:my "cool new value"})
Applies assoc-in to app-db with args
.
(morley.core/assoc-in [:my-store-key :nested-key] {:my "cool new value"})
Applies update to app-db with args
.
(morley.core/update :my-store-key inc)
Applies update-in to app-db with args
.
(morley.core/update-in [:my-store-key :nested-key] inc)
Applies dissoc to app-db with args
.
(morley.core/dissoc :my-store-key)
Applies dissoc-in to app-db with args
.
(morley.core/dissoc-in [:my-store-key :nested-key] :some-key)
Clears the store. Useful for testing.
(morley.core/reset)
Allows you to pass a get
or get-in
value instead of a full subscription, so that it feels more like all the other utils.
(morley.core/watch [:my-store-key :nested-key] (fn [_] (do-something)))
Given a subscription, call on-change-fn when it changes, passing the old-value and the new-value. Returns an unwatch function for cleanup. This is basically a convenience function around add-watch/remove-watch on re-frame subscriptions.
(morley.core/watch-sub (rf/subscribe [:my-subscription])
(fn [old new] (do-something)))
A re-frame interceptor that, after an event, will persist to local storage anything in the app-db that exists under the :local-storage
key. If the :sync-before
flag is passed, the interceptor will read from local storage and reset the value at the :local-storage
key to what was read before running the event handler. This is applied to any Morley 'change' function
(morley.core/assoc-in [:local-storage :nested-key] {:my "value"})
Copyright © 2018 Workframe, Inc.
Distributed under the Apache License, Version 2.0.