0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-23 23:35:58 -05:00
penpot/frontend/src/app/main/store.cljs

55 lines
1.2 KiB
Text
Raw Normal View History

;; 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/.
;;
2021-04-10 09:43:04 +02:00
;; Copyright (c) UXBOX Labs SL
(ns app.main.store
2020-10-05 18:20:39 +02:00
(:require-macros [app.main.store])
(:require
[beicon.core :as rx]
[okulary.core :as l]
[potok.core :as ptk]))
(enable-console-print!)
2020-04-14 17:00:52 +02:00
(defonce loader (l/atom false))
(defonce on-error (l/atom identity))
(defonce state
(ptk/store {:resolve ptk/resolve
:on-error (fn [e] (@on-error e))}))
(defonce stream
(ptk/input-stream state))
(defonce last-events
(let [buffer (atom #queue [])
remove #{:potok.core/undefined
:app.main.data.workspace.notifications/handle-pointer-update}]
(->> stream
(rx/filter ptk/event?)
(rx/map ptk/type)
(rx/filter (complement remove))
(rx/map str)
(rx/dedupe)
(rx/buffer 20 1)
(rx/subs #(reset! buffer %)))
buffer))
(defn emit!
2020-04-02 17:08:24 +02:00
([] nil)
([event]
2020-12-21 09:47:50 +01:00
(ptk/emit! state event)
nil)
([event & events]
2020-12-21 09:47:50 +01:00
(apply ptk/emit! state (cons event events))
nil))
(defn emitf
[& events]
2020-12-21 09:47:50 +01:00
#(apply ptk/emit! state events))
2020-09-28 15:29:54 +02:00