{"id":23626345,"url":"https://github.com/yetanalytics/re-thread","last_synced_at":"2025-08-31T02:31:48.640Z","repository":{"id":62432125,"uuid":"76502668","full_name":"yetanalytics/re-thread","owner":"yetanalytics","description":"Communicate with re-frame in a Web Worker","archived":false,"fork":false,"pushed_at":"2017-10-08T06:15:48.000Z","size":34,"stargazers_count":29,"open_issues_count":1,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-01T10:35:41.114Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yetanalytics.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-14T22:33:53.000Z","updated_at":"2024-05-27T13:28:57.000Z","dependencies_parsed_at":"2022-11-01T21:00:42.395Z","dependency_job_id":null,"html_url":"https://github.com/yetanalytics/re-thread","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/yetanalytics/re-thread","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetanalytics%2Fre-thread","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetanalytics%2Fre-thread/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetanalytics%2Fre-thread/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetanalytics%2Fre-thread/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yetanalytics","download_url":"https://codeload.github.com/yetanalytics/re-thread/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetanalytics%2Fre-thread/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272931173,"owners_count":25017313,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-27T22:53:03.409Z","updated_at":"2025-08-31T02:31:48.358Z","avatar_url":"https://github.com/yetanalytics.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# re-thread\n\n[![Clojars Project](https://img.shields.io/clojars/v/com.yetanalytics/re-thread.svg)](https://clojars.org/com.yetanalytics/re-thread)\n\nA tiny Clojurescript library for interacting with re-frame when it's running in a Web Worker.\n\n## Why\n\nre-frame is great for heavy lifting in the browser, but sharing a single thread with the UI can still be problematic. By shoving re-frame's state and events (and any other event/comms stuff like websockets) into a worker thread, we can keep the main browser thread nice and responsive.\n\n## How\n\nre-thread abstracts re-frame's subscription process over the Web Workers API messaging system. View components in the main thread \"subscribe\" to re-frame subscriptions defined in the worker, where reagent's `track!` function is used to watch them and transmit updates back. Disposals of subscriptions in the main thread are monitored, resulting in disposal of the corresponding tracks in the worker thread.\n\n## Usage\n\nIn your Web Worker re-frame app:\n\n``` clojure\n(ns your-worker-app.core\n  (:require\n   [re-thread.worker :refer [listen!]]\n   ...))\n\n(listen!)\n\n```\n\nYour client/host application will consist of only views and handler calls, delegating everything else to the worker.\n\nTo initialize the worker, use `re-thread.client/init`:\n\n``` clojure\n(ns your-client-app.core\n  (:require\n   [re-thread.client :refer [init]]\n   ...))\n\n\n;; Remember, in reloadable environments, you only want to run init once.\n(defonce init-worker\n  (delay\n   ...\n   (init \"/js/compiled_worker.js\" render) ;; optional callback\n   ))\n\n@init-worker\n\n```\n\nThen, in your components, you can pretty much forget that things are happening in a worker, and use `re-thread.client/dispatch` and `re-thread.client/subscribe` in the manner to which you are accustomed:\n\n``` clojure\n(ns your-client-app.views.counter\n  (:require [re-thread.client :refer [dispatch subscribe]]))\n\n(defn counter []\n  (let [v (subscribe [:counter/value] 0)] ;; \u003c- note that you can provide a default value..\n    (fn []\n      [:div\n       [:p \"Counter Value: \" (str @v)\n        [:span\n         [:button\n          {:on-click #(dispatch [:counter/inc-value!])} ;; \u003c- registered in the worker\n          \"Increment\"]\n         [:button\n          {:on-click #(dispatch [:counter/reset-value!])}\n          \"Reset\"]]]])))\n\n```\n\n## Example App\n\nI set up the re-frame todomvc example in a webworker, try it out in the `examples` directory!\n\n## Gotchas\n\n* Since all of the app state is contained in the worker process, you should take care not to write view code that fails if a subscription returns nil. Using the optional second arg of `subscribe` can help with that.\n* Though you get all of re-frame's subscription caching + other goodness in the worker, remember that each novel subscription result has to be serialized and sent back from the worker (once per sub id, client subscriptions are also deduplicated). Large results may hurt performance.\n* Doesn't seem to work without advanced compilation on Safari 10, fine in Chrome/Firefox. The initial subscription messages to the worker are lost with no error. Minified builds work fine though.\n\n## TODO:\n\n* Docs\n* Batching/caching worker -\u003e client subscription results\n* Multiple Workers\n* Extensible Messaging\n\n\n## License\n\nCopyright © 2017 Yet Analytics Inc.\n\nDistributed under the Eclipse Public License either version 1.0 or (at\nyour option) any later version.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyetanalytics%2Fre-thread","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyetanalytics%2Fre-thread","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyetanalytics%2Fre-thread/lists"}