Skip to content

Instantly share code, notes, and snippets.

@grzm
Created September 21, 2016 21:32
Show Gist options
  • Save grzm/5ccc3ddb648a1de8a35fad2401f00adc to your computer and use it in GitHub Desktop.
Save grzm/5ccc3ddb648a1de8a35fad2401f00adc to your computer and use it in GitHub Desktop.
untangled-client log out/app state reset
(ns myapp.client.core
(:require
[om.next :as om]
[myapp.client.ui :as ui]
[myapp.client.ui.user :as user]
[untangled.client.core :as uc]
[untangled.client.data-fetch :as df]))
(defn on-start
[{:keys [reconciler]}]
(let [state (om/app-state reconciler)
;;; load query
]
(df/load-data reconciler load-query
:post-mutation 'fetch/initial-load
:refresh [:untangled/force-root])))
(defonce app (atom (uc/new-untangled-client
:started-callback on-start)))
(defn initial-state []
{:ui/tab (uc/initial-state ui/TabSwitcher {})
:ui/current-user (uc/initial-state user/CurrentUser {})})
(defn setup [app]
(swap! app update-in [:initial-state] #(merge % (initial-state))))
(setup app)
(defonce mounted-app (reset! app (uc/mount @app ui/Root "app")))
(ns myapp.client.mutations
(:require
[myapp.client.core :as core]
[untangled.client.core :as uc]
[untangled.client.mutations :as um]
[om.next.cache :as c]))
(defn reset-history [history]
(let [size (.-size history)]
(c/cache size)))
(defmethod um/mutate 'myapp.client/log-out
[{:keys [state] :as env} _ _]
{:action (fn []
;; reset history cache
(swap! core/app
(fn [a]
(update-in a [:reconciler :config :history] #(reset-history %))))
;; first try: (swap! state (fn [s] (core/initial-state))
(uc/reset-state! @core/app (core/initial-state)))
:remote true})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment