项目作者: jtkDvlp

项目描述 :
A re-frame "effects handler" for performing async tasks via cljs-workers
高级语言: Clojure
项目地址: git://github.com/jtkDvlp/re-frame-worker-fx.git
创建时间: 2017-02-24T09:21:35Z
项目社区:https://github.com/jtkDvlp/re-frame-worker-fx

开源协议:MIT License

下载


Clojars Project
License: MIT
paypal

Web workers effect handler for re-frame

This re-frame library contains an web worker effect handler. The handler can be addressed by :worker and wraps the API of cljs-workers.

Getting started

Get it / add dependency

Add the following dependency to your project.cljs:

Clojars Project

Usage

See the following minimal code example or the test.cljs. For general usage of workers see cljs-workers.

The following example presupposes that there is already a worker pool and registered worker-handler.

  1. (ns your.project
  2. (:require [re-frame.core :as re-frame]
  3. [re-frame-worker-fx.core]))
  4. (re-frame/reg-event-fx
  5. :some-event
  6. (fn [coeffects _]
  7. (let [worker-pool
  8. (-> coeffects :db :worker-pool)]
  9. {:worker {:pool worker-pool
  10. ;; handler that will be called
  11. :handler :your-worker-handler
  12. ;; arguments applied to the handler
  13. :arguments {:a "Hallo Welt!" :b 10 :c (js/ArrayBuffer. 10)}
  14. ;; which arguments will be transfered instead of copied
  15. :transfer [:c]
  16. ;; dispatched on success conjoined with the result
  17. :on-success [:your-success-event]
  18. ;; dispatched on error conjoined with the result
  19. :on-error [:your-error-event]}})))

Appendix

I´d be thankful to receive patches, comments and constructive criticism.

Hope the package is useful :-)