{"id":16140777,"url":"https://github.com/octod/thestate","last_synced_at":"2025-09-02T18:33:11.268Z","repository":{"id":97949177,"uuid":"395344042","full_name":"OctoD/thestate","owner":"OctoD","description":"Global state for your react apps, made with Rescript","archived":false,"fork":false,"pushed_at":"2023-07-19T07:26:43.000Z","size":99,"stargazers_count":9,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-16T18:06:55.640Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"ReScript","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/OctoD.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["OctoD"]}},"created_at":"2021-08-12T14:21:15.000Z","updated_at":"2023-03-07T15:51:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"fe74b283-a07f-4ed6-a622-265a3054abd0","html_url":"https://github.com/OctoD/thestate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"OctoD/rescript-module-template","purl":"pkg:github/OctoD/thestate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctoD%2Fthestate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctoD%2Fthestate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctoD%2Fthestate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctoD%2Fthestate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OctoD","download_url":"https://codeload.github.com/OctoD/thestate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctoD%2Fthestate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261632033,"owners_count":23187268,"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":[],"created_at":"2024-10-09T23:53:47.845Z","updated_at":"2025-06-24T08:02:36.114Z","avatar_url":"https://github.com/OctoD.png","language":"ReScript","funding_links":["https://github.com/sponsors/OctoD"],"categories":[],"sub_categories":[],"readme":"Thestate\n========\n\nYet another global state manager.\n\nYes, it's done with push/sub\n\nYes, it's simple\n\nYes, it's made with Rescript\n\nWhy chosing it?\n\n- Simple, really simple\n- It's made with Rescript! ❤️\n- It's very tiny\n- Has `.d.ts` files for your js/ts apps\n- Built both for commonjs and es6 spec\n\n## install\n\n```bash\nyarn add @octod/thestate\n```\n\nIf you are a js/ts dev, it's done. If you are using rescript (and I recommend it!), add the dependency to your *bsconfig.json* file\n\n```json\n\"bs-dependencies\": [\n  \"@octod/thestate\"\n]\n```\n\n## creating your first store (rescript)\n\nYou have four functions to know: \n\n- make, creates a store\n- getstate, returns a store's value\n- mutation, registers a mutation and returns a mutating function\n- listen, adds a listener to all mutations in a single store\n\n```rescript\nlet store = 100-\u003eThestate.make\nlet increment = store-\u003eThestate.mutation((state, payload) =\u003e state + payload)\nlet unsubscribelistener = store-\u003eThestate.listen(state =\u003e Js.Console.log(state))\n\nincrement(100) // logs 200\nstore-\u003eThestate.getstate-\u003eJs.Console.log // logs 200\n\nunsubscribelistener()\n\nincrement(100) // does not log anymore, we have unsubscribed before\n```\n\n## creating your first store (js/ts)\n\n```ts\nimport * as thestate from 'thestate';\n\nconst store = thestate.make(100);\nconst increment = thestate.mutation(store, (state: number, payload: number) =\u003e state + payload);\nconst unsubscribelistener = thestate.listen(store, console.log);\n\nincrement(100) // logs 200\nconsole.log(thestate.getstate(store)) // logs 200\n\nunsubscribelistener()\nincrement(100) // does not log anymore, we have unsubscribed before\n```\n\n## using it with react (rescript)\n\n```rescript\n// create your store normally\nlet store = 100-\u003eThestate.make\n// maybe with some mutations is better\nlet increment = store-\u003eThestate.mutation((state, payload) =\u003e state + payload)\n\nmodule Increment = {\n  @react.component\n  let make = () =\u003e \u003cbutton onClick={_ =\u003e increment(1)}\u003e {\"increment\"-\u003eReact.string} \u003c/button\u003e\n}\n\nmodule Count = {\n  @react.component \n  let make = () =\u003e {\n    let count = store-\u003eThestate.useState\n\n    \u003cReact.Fragment\u003e\n      {`current state is ${count-\u003eBelt.Int.toString}`-\u003eReact.string}\n    \u003c/React.Fragment\u003e\n  }\n}\n\nmodule Counter = {\n  @react.component\n  let make = () =\u003e {\n    \u003cdiv\u003e\n      \u003cCount /\u003e\n      \u003cIncrement /\u003e\n    \u003c/div\u003e\n  }\n}\n```\n\n## using it with react (js/ts)\n\n```tsx\nimport React, { useState, useEffect } from 'react';\nimport * as thestate from '@octod/thestate';\n\nconst store = thestate.make(100)\nconst increment = thestate.mutation(store, (a: number, b: number) =\u003e a + b);\n\nconst Increment = () =\u003e {\n  return (\n    \u003cbutton onClick={() =\u003e increment(1)}\u003e\n      increment\n    \u003c/button\u003e\n  )\n}\n\nconst Count = () =\u003e {\n  const count = thestate.useState(store)\n  \n  return (\n    \u003c\u003e{`current state is ${count}`}\u003c/\u003e\n  )\n}\n\nconst Counter = () =\u003e {\n  return (\n    \u003cdiv\u003e\n      \u003cCount /\u003e\n      \u003cIncrement /\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n## Contributions are really welcome\n\nAny kind of contribution is really welcome, so don't be shy! \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctod%2Fthestate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foctod%2Fthestate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctod%2Fthestate/lists"}