{"id":41343530,"url":"https://github.com/mylesj/immer-compose","last_synced_at":"2026-01-23T06:53:50.300Z","repository":{"id":40476832,"uuid":"488017959","full_name":"mylesj/immer-compose","owner":"mylesj","description":"A utility for composing concurrent operations, yet allowing state to be merged in series.","archived":false,"fork":false,"pushed_at":"2023-01-01T20:35:54.000Z","size":240,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-05T02:47:32.216Z","etag":null,"topics":["higher-order-function","immer"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/mylesj.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2022-05-02T23:15:04.000Z","updated_at":"2022-05-06T10:32:48.000Z","dependencies_parsed_at":"2023-02-01T00:47:31.289Z","dependency_job_id":null,"html_url":"https://github.com/mylesj/immer-compose","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/mylesj/immer-compose","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mylesj%2Fimmer-compose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mylesj%2Fimmer-compose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mylesj%2Fimmer-compose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mylesj%2Fimmer-compose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mylesj","download_url":"https://codeload.github.com/mylesj/immer-compose/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mylesj%2Fimmer-compose/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28682263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T05:48:07.525Z","status":"ssl_error","status_checked_at":"2026-01-23T05:48:07.129Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["higher-order-function","immer"],"created_at":"2026-01-23T06:53:50.249Z","updated_at":"2026-01-23T06:53:50.295Z","avatar_url":"https://github.com/mylesj.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM Package Version][shield-npm-version]][npm]\n[![GitHub Repository][shield-github]][repo]\n[![Changelog][shield-changelog]][releases]\n[![GitHub Workflow Status (main)][shield-ci-main]][status-ci-main]\n[![Test Coverage][shield-coverage]][codacy-dashboard]\n\n# immer-compose\n\n\u003e _A utility for composing concurrent operations, yet allowing state to be merged in series._\n\n## Install / Prerequisites\n\n[Immer][immer] is a required peer-dependency.\n\n```sh\nnpm install immer immer-compose\n```\n\n## Motivation\n\nI was looking for a neat way to merge async updates to an arbitrary document ([JSON Schema][json-schema])\nin a sequential order - in my use-case the updates may only be loosely related and I wanted to\nseparate concerns by expressing them as middleware, _e.g._\n\n```javascript\nconst pipeline = compose(middlewareOne, middlewareTwo, middleWareThree)\nconst newState = pipeline(initialState)\n```\n\nYes it's _another_ micro-library... but I found this idea somewhat complex to think through and\nfelt that it warranted an isolated module - no doubt there'll be alternatives, but I couldn't find\nwhat I was looking for - with immutability in mind.\n\n## Usage\n\nThe functions `compose` and `composeWithPatches` are exposed mirroring the _producer_ functions provided\nby immer. Note that to use patches, it is still required that you import `enablePatches` from `immer` -\nthis module assumes nothing about which version you are using.\n\nCompose arguments are higher-order functions that can execute any asynchronous task and in-turn\nreturn an immer recipe - where each recipe will consume a draft of the previous state in the chain.\n\n```typescript\nconst higherOrderRecipe = async (initialState) =\u003e {\n    const data = await task()\n    return (draftState) =\u003e {\n        draftState.foo = 'bar'\n    }\n}\n```\n\nAdditionally, any other input passed to the composed function will be passed through.\n\n```typescript\nconst higherOrderRecipe = async (initial, a, b, c) =\u003e (draft) =\u003e {}\nconst pipeline = compose(higherOrderRecipe /* [, 0..*] */)\nconst newState = pipeline(state, 1, 2, 3)\n```\n\n-   [StackBlitz Demo][stackblitz]\n\n## Experimental \u0026nbsp;⚠️\n\n```typescript\nconst experimental = async () =\u003e async () =\u003e {}\n```\n\nIf a recipe is returned as an async function, the compose function will prioritise the order of\nthe synchronous recipes before processing the remaining tasks on a first-come first-serve basis.\nEffectively allowing middleware to self-determine whether to keep a slot in the queue or go last.\n\nThe implementation should be reliable in modern environments however, should also be considered\nexperimental as I don't know where I want to take this idea yet and also don't know how much\nutility it really affords - I was just playing around.\n\nThis behaviour is reliant on native `async` functions and won't work with regular functions\nreturning promises - due to this, it also will not work if you are targeting `es5` through\ncode transpilers like Babel.\n\n\u003c!-- project links --\u003e\n\n[npm]: https://www.npmjs.com/package/immer-compose\n[repo]: https://github.com/mylesj/immer-compose\n[releases]: https://github.com/mylesj/immer-compose/releases\n[status-ci-main]: https://github.com/mylesj/immer-compose/actions/workflows/integration.yml?query=branch%3Amain\n[codacy-dashboard]: https://app.codacy.com/gh/mylesj/immer-compose/dashboard?branch=main\n\n\u003c!-- external links --\u003e\n\n[immer]: https://immerjs.github.io/immer/\n[json-schema]: https://json-schema.org/\n[stackblitz]: https://stackblitz.com/edit/immer-compose?file=index.mjs\u0026view=editor\n\n\u003c!-- images --\u003e\n\n[shield-github]: https://img.shields.io/badge/%20-Source-555555?logo=github\u0026style=for-the-badge\n[shield-changelog]: https://img.shields.io/badge/%20-Changelog-555555?logo=github\u0026style=for-the-badge\n[shield-ci-main]: https://img.shields.io/github/actions/workflow/status/mylesj/immer-compose/integration.yml?branch=main\u0026label=CI\u0026logo=github\u0026style=for-the-badge\n[shield-npm-version]: https://img.shields.io/npm/v/immer-compose?\u0026label=%20\u0026logo=npm\u0026style=for-the-badge\n[shield-coverage]: https://img.shields.io/codacy/coverage/f2547f2ac77e44f6a6190d813da6c8b9/main?logo=codacy\u0026style=for-the-badge\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmylesj%2Fimmer-compose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmylesj%2Fimmer-compose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmylesj%2Fimmer-compose/lists"}