{"id":19793563,"url":"https://github.com/darky/effector-async-local-storage","last_synced_at":"2026-06-09T04:03:26.272Z","repository":{"id":57219815,"uuid":"420466597","full_name":"darky/effector-async-local-storage","owner":"darky","description":"Effector Domain based on AsyncLocalStorage","archived":false,"fork":false,"pushed_at":"2021-11-20T11:22:35.000Z","size":73,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-23T20:47:19.132Z","etag":null,"topics":["async","asynclocalstorage","dependency","di","domain","effector","fp","functional","injection","local","storage","ts","ts-fp-di","typescript"],"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/darky.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":"2021-10-23T16:36:37.000Z","updated_at":"2024-04-07T07:26:35.000Z","dependencies_parsed_at":"2022-08-28T23:22:50.504Z","dependency_job_id":null,"html_url":"https://github.com/darky/effector-async-local-storage","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Feffector-async-local-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Feffector-async-local-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Feffector-async-local-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Feffector-async-local-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darky","download_url":"https://codeload.github.com/darky/effector-async-local-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241133146,"owners_count":19915347,"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","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":["async","asynclocalstorage","dependency","di","domain","effector","fp","functional","injection","local","storage","ts","ts-fp-di","typescript"],"created_at":"2024-11-12T07:10:20.902Z","updated_at":"2026-06-09T04:03:21.237Z","avatar_url":"https://github.com/darky.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# effector-async-local-storage\n\n[Effector](https://effector.dev/) Domain based on Node.js AsyncLocalStorage\n\n## Example\n\n```typescript\nimport { attach, createEffect, createEvent, createStore } from 'effector';\nimport { effectorAsyncLocalStorageFactory, effectorAsyncLocalStorageInit } from 'effector-async-local-storage';\nimport Koa from 'koa';\nimport Router from 'koa-router';\nimport Redis from 'ioredis';\n\nconst eff = effectorAsyncLocalStorageFactory({\n  onCreateEffect(sid, effect) {\n    effect.watch((val) =\u003e {\n      console.log(`Effect \"${sid}\" call with value: ${val}`);\n    });\n    effect.doneData.watch((val) =\u003e {\n      console.log(`Effect \"${sid}\" done with value: ${val}`);\n    });\n    effect.failData.watch((val) =\u003e {\n      console.log(`Effect \"${sid}\" fail with value: ${val}`);\n    });\n  },\n  onCreateEvent(sid, event) {\n    event.watch((val) =\u003e {\n      console.log(`Event \"${sid}\" call with value: ${val}`);\n    });\n  },\n  onCreateStore(sid, store) {\n    store.watch((state, val) =\u003e {\n      console.log(`Store \"${sid}\" mutation with value: ${val}`);\n      console.log(`Store \"${sid}\" mutation, current state: ${state}`);\n    });\n  },\n});\n\nconst increment = eff('increment', () =\u003e createEvent());\nconst decrement = eff('decrement', () =\u003e createEvent());\nconst reset = eff('reset', () =\u003e createEvent());\n\nconst pullCounterFx = eff('pullCounterFx', () =\u003e\n  createEffect\u003cvoid, number\u003e(async () =\u003e {\n    const count = await redis.get('counter');\n    return Number(count ?? 0);\n  })\n);\n\nconst pushCounterFx = eff('pushCounterFx', () =\u003e\n  attach({\n    source: $counter(),\n    effect: createEffect\u003cnumber, number\u003e(async (count) =\u003e {\n      await redis.set('counter', count);\n      return count;\n    }),\n  })\n);\n\nconst $counter = eff(\n  '$counter',\n  () =\u003e\n    createStore(0)\n      .on(increment(), (state) =\u003e state + 1)\n      .on(decrement(), (state) =\u003e state - 1)\n      .on(pullCounterFx().doneData, (_, value) =\u003e value)\n      .reset(reset())\n);\n\nconst app = new Koa();\nconst router = new Router();\nconst redis = new Redis();\n\napp.use(async (_, next) =\u003e {\n  await effectorAsyncLocalStorageInit(async () =\u003e {\n    await next();\n  });\n});\n\nrouter.post('/increment', async (ctx) =\u003e {\n  $counter();\n  await pullCounterFx()();\n  increment()();\n  ctx.body = await pushCounterFx()();\n});\n\nrouter.post('/decrement', async (ctx) =\u003e {\n  $counter();\n  await pullCounterFx()();\n  decrement()();\n  ctx.body = await pushCounterFx()();\n});\n\nrouter.post('/reset', async (ctx) =\u003e {\n  $counter();\n  await pullCounterFx()();\n  reset()();\n  ctx.body = await pushCounterFx()();\n});\n\napp.use(router.routes());\n\napp.listen(4000);\n```\n\n## Related\n\n* [effector-storify](https://github.com/darky/effector-storify) - Effector utils for storify Effect/Event\n\n* [ts-fp-di](https://github.com/darky/ts-fp-di) - Tiny TypeScript functional dependency injection, based on Node.js AsyncLocalStorage\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarky%2Feffector-async-local-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarky%2Feffector-async-local-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarky%2Feffector-async-local-storage/lists"}