An open API service indexing awesome lists of open source software.

https://github.com/jtkdvlp/re-frame-tasks

A re-frame interceptor and helpers to register / unregister (background-)tasks
https://github.com/jtkdvlp/re-frame-tasks

re-frame tasks tasks-list

Last synced: 10 months ago
JSON representation

A re-frame interceptor and helpers to register / unregister (background-)tasks

Awesome Lists containing this project

README

          

[![Clojars Project](https://img.shields.io/clojars/v/jtk-dvlp/re-frame-tasks.svg)](https://clojars.org/jtk-dvlp/re-frame-tasks)
[![cljdoc badge](https://cljdoc.org/badge/jtk-dvlp/re-frame-tasks)](https://cljdoc.org/d/jtk-dvlp/re-frame-tasks/CURRENT)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/jtkDvlp/re-frame-tasks/blob/master/LICENSE)

# Tasks interceptor / helpers for re-frame

Interceptor and helpers to register and unregister (background-)tasks (FXs) in your app-state / app-db to list tasks and / or block single ui parts or the whole ui.

## Features

* register / unregister tasks / fxs via one line or global interceptor injection
* support multiple and any fx on-completion keys via registration
* subscriptions for tasks list and running task boolean
* running task boolean can be quick filtered by task name
* events to register / unregister tasks yourself
* helpers to register / unregister tasks into db yourself

Also works for async coeffect injections, see https://github.com/jtkDvlp/re-frame-async-coeffects.

## Getting started

### Get it / add dependency

Add the following dependency to your `project.clj`:

[![Clojars Project](https://img.shields.io/clojars/v/jtk-dvlp/re-frame-tasks.svg)](https://clojars.org/jtk-dvlp/re-frame-tasks)

### Usage

See api docs [![cljdoc badge](https://cljdoc.org/badge/jtk-dvlp/re-frame-tasks)](https://cljdoc.org/d/jtk-dvlp/re-frame-tasks/CURRENT)

```clojure
(ns ^:figwheel-hooks jtk-dvlp.your-project
(:require
[cljs.pprint]
[cljs.core.async :refer [timeout]]
[jtk-dvlp.async :refer [go > args
(apply some-async-stuff)
(
[:button {:on-click #(rf/dispatch [:some-event])}
"exec some event"]
[:button {:on-click #(rf/dispatch [:some-bad-event])}
"exec some bad event"]
[:button {:on-click #(rf/dispatch [:some-other-bad-event])}
"exec some other bad event"]

[:ul "task list " (count @tasks)
;; task is a map of `::tasks/id`, `:name`, `:event and the
;; data you carry via `::task` fx from within the event
(for [{:keys [::tasks/id] :as task} @tasks]
^{:key id}
[:li [:pre (with-out-str (cljs.pprint/pprint task))]])]

(when @block-ui?
[:div "this div blocks the UI if there are running tasks"])])))
```

## Appendix

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

Hope the package is useful :-)