Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yetanalytics/sse-fx
re-frame FX and CoFX for working with EventSource connections in the browser
https://github.com/yetanalytics/sse-fx
Last synced: 8 days ago
JSON representation
re-frame FX and CoFX for working with EventSource connections in the browser
- Host: GitHub
- URL: https://github.com/yetanalytics/sse-fx
- Owner: yetanalytics
- License: epl-1.0
- Created: 2018-03-13T21:53:37.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-05T20:40:47.000Z (over 6 years ago)
- Last Synced: 2024-11-28T12:43:44.910Z (about 1 month ago)
- Language: Clojure
- Size: 12.7 KB
- Stars: 9
- Watchers: 6
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# sse-fx
`sse-fx` provides a set of [re-frame](https://github.com/Day8/re-frame) [fx](https://github.com/Day8/re-frame/blob/master/docs/Effects.md) and [cofx](https://github.com/Day8/re-frame/blob/master/docs/Coeffects.md) handlers for working with [EventSource](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) objects and [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).
## Usage
```clojure
(ns re-frame-app.events
(:require [re-frame.core :as re-frame]
[com.yetanalytics.sse-fx.events :refer [register-all!]]
[com.yetanalytics.sse-fx.event-source :as event-source]
));; Register all fx/cofx
(register-all!);; Just the event source handlers
;; (event-source/register!);; Use one in a handler
(re-frame/reg-event-fx
::init-event-source
(fn [{:keys [db] :as ctx} _]
{::event-source/init
{:uri "/query"
;; handle-* args are re-frame event handlers
:handle-open [::sse-open] ;; re-frame app handler to dispatch
;; messages are transit-decoded by default
;; supply your own with :decode-msg-fn
:handle-message [::sse-message]
;; Errors can be actual EventSource errors, or handling/dispatch errors.
;; either way, they're wrapped in an ex-info
:handle-error [::sse-error]
;; This isn't an event, but rather fires when you close the EventSource with the ::event-source/close fx handler
:handle-close [::sse-close]}}))```
## LicenseCopyright © 2018 Yet Analytics Inc.
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.