{"id":22731323,"url":"https://github.com/sno2/deact","last_synced_at":"2026-05-18T09:33:02.973Z","repository":{"id":62421756,"uuid":"306045942","full_name":"sno2/deact","owner":"sno2","description":"A type enforced Deno module for state management with hooks.","archived":false,"fork":false,"pushed_at":"2020-10-21T14:28:36.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-14T05:42:46.651Z","etag":null,"topics":["deno","deno-module","state","state-management"],"latest_commit_sha":null,"homepage":"https://deno.land/x/deact","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/sno2.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-10-21T14:10:18.000Z","updated_at":"2021-04-25T11:57:19.000Z","dependencies_parsed_at":"2022-11-01T17:32:12.872Z","dependency_job_id":null,"html_url":"https://github.com/sno2/deact","commit_stats":null,"previous_names":["codingcarter/deact"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sno2/deact","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fdeact","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fdeact/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fdeact/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fdeact/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sno2","download_url":"https://codeload.github.com/sno2/deact/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sno2%2Fdeact/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33172586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"ssl_error","status_checked_at":"2026-05-18T09:27:28.300Z","response_time":71,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["deno","deno-module","state","state-management"],"created_at":"2024-12-10T19:21:28.685Z","updated_at":"2026-05-18T09:33:02.955Z","avatar_url":"https://github.com/sno2.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deact\n\nA type enforced Deno module for state management.\n\n## Announcement\n\nThis module is in development and is not recommended for production use. If you would like to contribute, then please make sure you clone the repo and have Prettier installed. Also, run `deno test` before submitting an PRs. Furthermore, deact's behavior is much like to the Vue Composition API. Thank you!\n\n## Getting Started\n\nFirst, install and setup Deno on your environment by [following their setup guide](https://deno.land/#installation). After that, you can import the deacivity module via the following code:\n\n```ts\nimport { ref } \"https://deno.land/x/deact/mod.ts\";\n```\n\nObviously, you should know what the above code does already before using a state management framework for Deno, so let's get started!\n\n## Usage\n\nThe `ref` is a function that creates a stateful object. That basically means that you can observe changes to `ref`s using functions. Here is a basic counter app with the module:\n\n```ts\nimport { ref } from \"https://deno.land/x/deact/mod.ts\";\n\nconst counter = ref(0); // initial value is `0`\nconsole.log(counter.value); // logs out `0`\n```\n\nAs you can see, the value that you enter as a parameter for the `ref` function is the initial value. An important thing to note is that the current value of the `ref` is always going to be in the `value` property. This means that you are able to set and get the value of the ref by accessing the `value` property.\n\nNow, you may be remembering that we said above that this module is type-enforced, well let's just see what happens when we try to assign different types to our `counter` `ref`.\n\n```ts\nimport { ref } from \"https://deno.land/x/deact/mod.ts\";\n\nconst counter = ref(0); // value is implicitly a `number` type\n\nconsole.log(counter.value); // logs out `0`\ncounter.value = 5;\n\nconsole.log(counter.value); // logs out `5`\ncounter.value = \"a string\";\n```\n\nAfter that last line, our console spits out the following error:\n\n```sh\n\u003e error: TS2322 [ERROR]: Type 'string' is not assignable to type 'number'.\n\u003e counter.value = \"a string\";\n\u003e ~~~~~~~~~~~~~\n\u003e   at Deno.cwd()\n```\n\nAs you can see, Typescript automatically infers the type of the `ref.value` via generics; therefore, you can also pass in the type of the `ref` with generics! I advise you to always keep a type variable for the type of your `ref`s, as it makes it a lot easier to edit and use the `ref` later. Here's a working counter that can be a `number` or `string`:\n\n```ts\nimport { ref } from \"https://deno.land/x/deact/mod.ts\";\n\ntype CounterType = number | string;\nconst counter = ref\u003cCounterType\u003e(0); // value is explicitly a `number | string` type\nconsole.log(counter.value); // logs out `0`\n\ncounter.value = 5;\nconsole.log(counter.value); // logs out `5`\n\ncounter.value = \"a string\";\nconsole.log(counter.value); // logs out `\"a string\"`\n```\n\nNow, our code is working beautifully and is perfectly typed! Now, let's actually get into the lifecycle hooks with deact! Currently, we only have one that is called `watch`; it runs a callback function with the old and new values of the given `ref` as parameters. Here is an example:\n\n```ts\nimport { ref, watch } from \"https://deno.land/x/deact/mod.ts\"; // note that we imported `watch`\n\ntype CounterType = number;\nconst counter = ref\u003cCounterType\u003e(0);\n\nwatch(counter, (oldValue: CounterType, newValue: CounterType) =\u003e {\n  console.log(\n    `The score went from ${oldValue} to ${newValue} with a ${\n      newValue - oldValue\n    } point gain!`\n  );\n});\n\ncounter.value = 23;\n```\n\nAfter running the above code, the console will show `\"The score went from 0 to 23 with a 23 point gain!\"`. You're probably starting to understand the necessity of storing your types for `ref`s. Here is an example using an interval that increments `counter.value` by a random number between `5` and `20`:\n\n```ts\nimport { ref, watch } from \"https://deno.land/x/deact/mod.ts\";\n\ntype CounterType = number;\nconst counter = ref\u003cCounterType\u003e(0);\n\nwatch(counter, (oldValue: CounterType, newValue: CounterType) =\u003e {\n  console.log(\n    `The score went from ${oldValue} to ${newValue} with a ${\n      newValue - oldValue\n    } point gain!`\n  );\n});\n\nsetInterval(() =\u003e (counter.value += Math.floor(Math.random() * 15) + 5), 500);\n```\n\nAfter running the code, our console should show something like this:\n\n```sh\n\u003e The score went from 0 to 15 with a 15 point gain!\n\u003e The score went from 15 to 23 with a 8 point gain!\n\u003e The score went from 23 to 29 with a 6 point gain!\n\u003e The score went from 29 to 46 with a 17 point gain!\n\u003e The score went from 46 to 52 with a 6 point gain!\n\u003e The score went from 52 to 66 with a 14 point gain!\n\u003e The score went from 66 to 72 with a 6 point gain!\n\u003e The score went from 72 to 82 with a 10 point gain!\n\u003e The score went from 82 to 97 with a 15 point gain!\n\u003e The score went from 97 to 114 with a 17 point gain!\n\u003e The score went from 114 to 126 with a 12 point gain!\n\u003e The score went from 126 to 137 with a 11 point gain!\n\u003e The score went from 137 to 146 with a 9 point gain!\n```\n\nWe now know all of the basic usage of the deact module, but wait! There's more! Not really, you can just use `isRef` to check whether something is a `ref` or not. Obviously, though, this module is type-enforced, so there isn't really a point of using it unless if you are using boring old vanilla javascript.\n\nWhat? You want an example? Ok, sure, here's how you can use it:\n\n```ts\nimport { ref, isRef } from \"https://deno.land/x/deact/mod.ts\";\n\ntype CounterType = number;\nconst counter = ref\u003cCounterType\u003e(0);\n\nconsole.log(isRef(counter));\nconsole.log(isRef({})); // throws type error\nconsole.log(isRef(23)); // throws type error\n```\n\nAfter running that code, the console will show the following:\n\n```sh\n\u003e  error: TS2345 [ERROR]: Argument of type '{}' is not assignable to parameter of type 'Ref\u003cany\u003e'.\n\u003e    Type '{}' is missing the following properties from type 'Ref\u003cany\u003e': #value, #watchers, value, _watch\n\u003e    console.log(isRef({}));\n\u003e                      ~~\n\u003e    at Deno.cwd()\n\n\u003e  TS2345 [ERROR]: Argument of type 'number' is not assignable to parameter of type 'Ref\u003cany\u003e'.\n\u003e    console.log(isRef(23));\n\u003e                      ~~\n\u003e    at Deno.cwd()\n\n\u003e  Found 2 errors.\n```\n\nIf you were using vanilla javascript, though, then that function would be more useful. Another important thing to note is that all types, interfaces, and classes are exported from the module, so everything is open for you to use or extend.\n\nWell, you finished reading the Usage walkthrough. Bye and good luck coding!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsno2%2Fdeact","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsno2%2Fdeact","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsno2%2Fdeact/lists"}