{"id":32184531,"url":"https://github.com/maximgb/re-service","last_synced_at":"2025-10-21T23:51:44.196Z","repository":{"id":62433605,"uuid":"221328077","full_name":"MaximGB/re-service","owner":"MaximGB","description":"Re-frame supplementary library to easily declare services and dispatch co-effects/effects requests to service functions","archived":false,"fork":false,"pushed_at":"2019-11-17T12:23:07.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-21T23:51:12.899Z","etag":null,"topics":["clojurescript","co-effect","effect","re-frame","service","utility"],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MaximGB.png","metadata":{"files":{"readme":"README.adoc","changelog":"CHANGELOG.adoc","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":"2019-11-12T22:59:03.000Z","updated_at":"2021-02-16T09:11:12.000Z","dependencies_parsed_at":"2022-11-01T21:01:38.137Z","dependency_job_id":null,"html_url":"https://github.com/MaximGB/re-service","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/MaximGB/re-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximGB%2Fre-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximGB%2Fre-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximGB%2Fre-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximGB%2Fre-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaximGB","download_url":"https://codeload.github.com/MaximGB/re-service/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximGB%2Fre-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280354180,"owners_count":26316400,"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-10-21T02:00:06.614Z","response_time":58,"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":["clojurescript","co-effect","effect","re-frame","service","utility"],"created_at":"2025-10-21T23:51:38.916Z","updated_at":"2025-10-21T23:51:44.188Z","avatar_url":"https://github.com/MaximGB.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"= Re-service\n:source-highlighter: coderay\nifdef::env-github[]\n:tip-caption: :bulb:\n:note-caption: :information_source:\n:important-caption: :heavy_exclamation_mark:\n:caution-caption: :fire:\n:warning-caption: :warning\n:endif::[]\n\nimage:https://img.shields.io/clojars/v/maximgb/re-service.svg[link=https://clojars.org/maximgb/re-service]\nimage:https://img.shields.io/badge/License-MIT-yellow.svg[link=https://raw.githubusercontent.com/MaximGB/re-service/master/LICENSE]\n\nRe-frame supplementary library to easily declare services and dispatch co-effects/effects requests to implementing functions\n\n== TL;DR\n\nRe-service allows re-frame user to easily define services. A service here is a named set of functions which provide co-effects\nand execute effects required or issued by re-frame event handlers. What re-service does is it translates re-frame co-effects/effects\ndescriptors into service function calls return values.\n\n== Basic API\n\n=== Service definition\n\nA service can be defined using macros or function calls from `maximgb.re-service.core` namespace.\n\nTo define a service and it's implementation one have to:\n\n- define a service having  application unique id\n- define set of named commands by providing command id and implementing function for the service registed\n\n[source, clojure]\n----\n(ns my.service.core\n  (:require [maximgb.re-service.core :refer [def-re-service\n                                             def-re-service-command]\n                                     :include-macros true])) ;; \u003c1\u003e\n\n(def-re-service ::my-service) ;; \u003c2\u003e\n\n(def-re-service-command ::my-service ;; \u003c3\u003e\n                        :sum ;; \u003c4\u003e\n                        [cofx \u0026 args] ;; \u003c5\u003e\n                        (apply + args)) ;; \u003c6\u003e\n----\n\n\u003c1\u003e Require `maximgb.re-service.core` namespace and refer to service and command definition macros.\n\u003c2\u003e Define service with application unique id\n\u003c3\u003e Define service command with:\n\u003c4\u003e - id `:sum`\n\u003c5\u003e - variable list of arguments (non-variable lists are also allowed)\n\u003c6\u003e - implementing function body\n\n=== Service commands invocation\n\nWhen service is defined a corresponding re-frame's co-effect and effect are registered using provided service id as co-effect/effect id.\n\nThus each service command can be invoked as co-effect via re-frame's `(inject-cofx)` or as effect requested\nvia `(reg-event-fx)` or `(reg-event-ctx)` return value.\n\n==== Calling service command as co-effect\n\nTo call service command as co-effect a user have to use `(inject-cofx service-id [key? command-1-id [\u0026 args] command-2-id [\u0026 args]] ...)` syntax.\n\nCommands are executed in the order each command is called with the given arguments. The results will be added to re-frame's co-effects\nmap under `service-id` or `key?` (if one has been provided) key. The key value will be a map keyed by command ids, map values will be set to\ncorresponding command invokation results.\n\n[NOTE]\n====\nIf command is called as co-effect the first argument it recieves will be set to re-frame's co-effects map.\n====\n\n[source, clojure]\n----\n(reg-event-fx\n  ::my-command\n  [(inject-cofx ::my-service [:sum [1 2 3 4] :mul [1 2 3 4]])] ;; \u003c1\u003e\n  (fn [cofx]\n   (let [my-sum (get-in cofx [::my-service :sum])  ;; \u003c2\u003e\n         my-mul (get-in cofx [::my-service :mul])] ;; \u003c3\u003e\n     (is (= my-sum 10) \"Sum is correct\")\n     (is (= my-mul 24) \"Mul is correct\"))\n     {}))\n----\n\u003c1\u003e Injecting service co-effect, requesting two commands invokation (`:sum` and `:mul`) each will recieve the same list of parameters\n\u003c2\u003e Getting `:sum` command result\n\u003c3\u003e Getting `:mul` command result\n\n==== Calling service command as effect\n\nTo call service command as effect a user have to add to re-frame's effects map using `service-id` as effect id a value designating\nservice commands invokation request (the value syntax is the same as for co-effect case)\n\n[source, clojure]\n----\n(reg-event-fx\n  ::my-command\n (fn [cofx]\n  {::my-service [:sum [1 2 3 4] :mul [1 2 3 4]})) ;; \u003c1\u003e\n----\n\u003c1\u003e Of course `:sum` and `:mul` has no side-effects, thus calling'em as effects is meaningless, so here they are called for illustrative\n   reasons only.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximgb%2Fre-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximgb%2Fre-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximgb%2Fre-service/lists"}