{"id":19139695,"url":"https://github.com/adamringhede/signal","last_synced_at":"2025-07-23T13:06:56.868Z","repository":{"id":199713141,"uuid":"703650276","full_name":"adamringhede/signal","owner":"adamringhede","description":"A reactive primitive for updating state in Typescript applications ","archived":false,"fork":false,"pushed_at":"2023-10-15T17:22:50.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-09T15:08:09.812Z","etag":null,"topics":["reactive","signals","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adamringhede.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2023-10-11T16:28:51.000Z","updated_at":"2023-10-11T17:09:19.000Z","dependencies_parsed_at":"2024-10-23T07:17:49.890Z","dependency_job_id":"5000f6e6-f63c-490c-928a-9e43340449eb","html_url":"https://github.com/adamringhede/signal","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"3c5bbd33fb97be05cd35e3c951e89865cfb5a6cb"},"previous_names":["adamringhede/signal"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/adamringhede/signal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamringhede%2Fsignal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamringhede%2Fsignal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamringhede%2Fsignal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamringhede%2Fsignal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adamringhede","download_url":"https://codeload.github.com/adamringhede/signal/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamringhede%2Fsignal/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266682625,"owners_count":23967837,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"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":["reactive","signals","typescript"],"created_at":"2024-11-09T07:14:46.175Z","updated_at":"2025-07-23T13:06:56.819Z","avatar_url":"https://github.com/adamringhede.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Signal\n\nA reactive primitive for updating state in an application. \n\nSignals represent state which can be derived using computations. \nThese computations will hold on to the last computed value until signals it depend\non change value. Signals and the reuslt of computations are functions that can be\ncalled to return their current value. \n\nEffects can be used to subscribe to signals or computations and be triggered \nautomatically whenever signals it or any of its upstream computations depend on\nchange value. \n\nThe syntax is inspired by [Angular Signals](https://angular.io/guide/signals).\n\n## Install\n\n```\nnpm i @adamringhede/signal\n```\n\n## Usage\n\n### Creating signals\nSignals are created using the `signal\u003cT\u003e(value: T)` function. This returns a function. \n\n### Reading signals\nThe value from a signal can be extrated by invoking the signal function. \n\n```ts\nconst amount = signal(5)\namount() // 5\n```\n\n### Updating signals\nThe signal can \n\n```ts\nconst amount = signal(5)\namount.set(10)\namount() // 10\n```\n\nThe signal can also be updated with regards to its current value using the `.update(updateFn: (value) =\u003e T)` method.\n\n```ts\nconst amount = signal(5)\namount.update(value =\u003e value + 1)\namount() // 6\n```\n\nIf the signal contains an object that you just want to update, you can use the `.mutate(mutateFn: (value) =\u003e void)` method to change the value. Note that this will not trigger effects to be called. \n\n```ts\nconst amount = signal({a: 1})\namount.update(value =\u003e value.a += 1)\namount().a // 2\n```\n\n### Computations\nYou can apply computations on one or more signals or even other computations by using the `compute(fn: () =\u003e void)` function. The computation will hold on to the most recently computed value.\n\n### Effects\nYou can trigger any kind of side effect whenever any upstream signal changes value. This is illustrated in the code below. \n\n```ts\nconst a = signal(1)\nconst b = signal(2)\nconst c = computed(() =\u003e a() + b())\n\nlet effectResult: number[] = []\nconst e = effect(() =\u003e effectResult.push(c()))\n\nexpect(effectResult).toEqual([3])\n\na.set(3)\nb.set(4)\nexpect(effectResult).toEqual([3,5,7])\n\ne.destroy()\n```\nRemember to destroy effects when you want it to stop reacting to changes in signals. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamringhede%2Fsignal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamringhede%2Fsignal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamringhede%2Fsignal/lists"}