penpot/frontend/src/uxbox/view/store.cljs
Andrey Antukh 08b0a096eb
Minor structure refactor.
Make forms and messages modules independent of
store location (making them plugables).
2017-01-16 12:35:10 +01:00

42 lines
989 B
Clojure

;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.view.store
(:require [beicon.core :as rx]
[lentes.core :as l]
[potok.core :as ptk]))
(def ^:dynamic *on-error* identity)
(defonce state (atom {}))
(defonce loader (atom false))
(defonce store (ptk/store {:on-error #(*on-error* %)}))
(defonce stream (ptk/input-stream store))
(def auth-ref
(-> (l/key :auth)
(l/derive state)))
(defn emit!
([event]
(ptk/emit! store event))
([event & events]
(apply ptk/emit! store (cons event events))))
(defn- initial-state
[]
{:route nil
:project nil
:pages nil
:page nil
:flags #{:sitemap}
:shapes {}})
(defn init
"Initialize the state materialization."
[]
(emit! initial-state)
(rx/to-atom store state))