2016-11-27 21:53:12 +01:00
|
|
|
;; 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
|
2016-11-27 21:53:12 +01:00
|
|
|
|
2020-08-18 19:26:37 +02:00
|
|
|
(ns app.main.store
|
2020-10-05 18:20:39 +02:00
|
|
|
(:require-macros [app.main.store])
|
2020-04-11 19:22:24 +02:00
|
|
|
(:require
|
2021-05-04 15:18:59 +02:00
|
|
|
[beicon.core :as rx]
|
|
|
|
[okulary.core :as l]
|
|
|
|
[potok.core :as ptk]))
|
2019-07-03 09:30:59 +02:00
|
|
|
|
2016-11-27 21:53:12 +01:00
|
|
|
(enable-console-print!)
|
|
|
|
|
2020-04-14 17:00:52 +02:00
|
|
|
(defonce loader (l/atom false))
|
2021-09-30 13:56:07 +02:00
|
|
|
(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))
|
2016-11-27 21:53:12 +01:00
|
|
|
|
2021-05-08 14:59:58 +02:00
|
|
|
(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))
|
|
|
|
|
2016-11-27 21:53:12 +01:00
|
|
|
(defn emit!
|
2020-04-02 17:08:24 +02:00
|
|
|
([] nil)
|
2016-11-27 21:53:12 +01:00
|
|
|
([event]
|
2020-12-21 09:47:50 +01:00
|
|
|
(ptk/emit! state event)
|
2019-08-08 16:27:37 +02:00
|
|
|
nil)
|
2016-11-27 21:53:12 +01:00
|
|
|
([event & events]
|
2020-12-21 09:47:50 +01:00
|
|
|
(apply ptk/emit! state (cons event events))
|
2019-08-08 16:27:37 +02:00
|
|
|
nil))
|
2016-11-27 21:53:12 +01:00
|
|
|
|
2020-09-25 14:51:21 +02:00
|
|
|
(defn emitf
|
|
|
|
[& events]
|
2020-12-21 09:47:50 +01:00
|
|
|
#(apply ptk/emit! state events))
|
2020-09-25 14:51:21 +02:00
|
|
|
|
2020-09-28 15:29:54 +02:00
|
|
|
|