Some state is the server's and outlives a page: a user's toasts, which every tab of theirs shows, and the page a
navigation opens still has; who has a document open. An island's own state ends with the page, and a def never ends.
co.multiply.tropical.shared keeps state between them, for as long as an island reads it.
(defshared toasts
"The toasts a user's tabs show."
{:init []})
(defisland toast-list
[]
(let [{:keys [uid]} (use-session)
[messages swap-messages!] (use-shared toasts uid)]
[:ul (for [m messages] [:li (:text m)])]))
;; Anywhere: an action, a resource, a task of the app's own.
(shared/swap! toasts uid conj {:text "Saved."})
:init, ready in that render. Each change renders every island
reading it again.:linger-ms, 5 s by default), so a page load finds it as the last page left it. Then it is gone,
and a swap! finds nothing to change and returns false.shared/swap! applies a fn under the instance's lock, from an action, a resource, or a
task of the app's own. The swap-value! that use-shared returns is the same, bound to its state and key.observe.use-session's :uid, never from
signals or an action's value.Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |