{"id":29439255,"url":"https://github.com/jinmayamashita/enclosed","last_synced_at":"2025-10-16T09:12:40.167Z","repository":{"id":52546870,"uuid":"242722077","full_name":"jinmayamashita/enclosed","owner":"jinmayamashita","description":null,"archived":false,"fork":false,"pushed_at":"2022-03-26T13:51:28.000Z","size":10,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2023-10-20T21:00:16.749Z","etag":null,"topics":["closures","states","usestate"],"latest_commit_sha":null,"homepage":null,"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/jinmayamashita.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":"2020-02-24T11:45:32.000Z","updated_at":"2023-10-20T21:00:16.750Z","dependencies_parsed_at":"2022-08-27T19:50:09.568Z","dependency_job_id":null,"html_url":"https://github.com/jinmayamashita/enclosed","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/jinmayamashita/enclosed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinmayamashita%2Fenclosed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinmayamashita%2Fenclosed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinmayamashita%2Fenclosed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinmayamashita%2Fenclosed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jinmayamashita","download_url":"https://codeload.github.com/jinmayamashita/enclosed/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinmayamashita%2Fenclosed/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265119815,"owners_count":23714410,"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":["closures","states","usestate"],"created_at":"2025-07-13T09:30:16.682Z","updated_at":"2025-10-16T09:12:35.135Z","avatar_url":"https://github.com/jinmayamashita.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enclosed\n\nEnclosed is a easy way of managing your small state in plain JavaScript.\nyou can think of Enclosed as [`React.useState`](https://reactjs.org/docs/hooks-reference.html#usestate).\n\n(JavaScript closures have always been a bit of a mystery to me.)\n\n## Examples\n\n```js\nimport { enclosed } from \"./src/enclosed\";\n\nconst [getState, setState] = enclosed(10);\n\ngetState();\n// 10\n\nsetState(s =\u003e s + 10);\ngetState();\n// 100\n```\n\n### More examples\n\n```ts\nimport { enclosed } from \"./src/enclosed\";\n\ntype Todo = { id: number; name: string };\n\nconst [getState, setState] = enclosed([{ id: 1, name: \"foo\" }]);\n\n// your custom functions\nconst push = (t: Todo) =\u003e setState(s =\u003e [...s, t]);\nconst update = (t: Todo) =\u003e setState(s =\u003e s.map(e =\u003e (t.id === e.id ? t : e)));\nconst remove = (id: Todo[\"id\"]) =\u003e setState(s =\u003e s.filter(e =\u003e id !== e.id));\n\ngetState();\n// [{id: 1, name: \"foo\"}]\n\npush({ id: 9, name: \"foo9\" });\ngetState();\n// [{id: 1, name: \"foo\"}, { id: 9, name: \"foo9\" }]\n\nupdate({ id: 1, name: \"boo\" });\ngetState();\n// [{id: 1, name: \"boo\"}, { id: 9, name: \"foo9\" }]\n\nremove(9);\ngetState();\n// [{id: 1, name: \"foo\"}]\n```\n\n## Todos\n\n- [ ] Add a test spec later :pray:\n- [ ] Documenting APIs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinmayamashita%2Fenclosed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjinmayamashita%2Fenclosed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinmayamashita%2Fenclosed/lists"}