{"id":15608602,"url":"https://github.com/hypercubed/mini-signals","last_synced_at":"2025-04-05T21:06:59.737Z","repository":{"id":1211118,"uuid":"41616339","full_name":"Hypercubed/mini-signals","owner":"Hypercubed","description":"signals, in JavaScript, fast","archived":false,"fork":false,"pushed_at":"2023-08-12T05:44:27.000Z","size":759,"stargazers_count":121,"open_issues_count":13,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-29T20:03:43.371Z","etag":null,"topics":[],"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/Hypercubed.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2015-08-30T04:10:56.000Z","updated_at":"2025-03-13T03:33:41.000Z","dependencies_parsed_at":"2024-06-18T13:43:41.296Z","dependency_job_id":"4132b865-94ac-4b82-8da7-4865711779a8","html_url":"https://github.com/Hypercubed/mini-signals","commit_stats":{"total_commits":88,"total_committers":5,"mean_commits":17.6,"dds":0.05681818181818177,"last_synced_commit":"1def77256f13457c604fffe8467fa4901bd46ea0"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2Fmini-signals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2Fmini-signals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2Fmini-signals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2Fmini-signals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hypercubed","download_url":"https://codeload.github.com/Hypercubed/mini-signals/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399873,"owners_count":20932876,"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-03T05:21:36.413Z","updated_at":"2025-04-05T21:06:59.709Z","avatar_url":"https://github.com/Hypercubed.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mini-signals\n\nsignals, in JavaScript, fast\n\n[![NPM](https://img.shields.io/npm/v/mini-signals.svg)](https://www.npmjs.com/package/mini-signals) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Hypercubed/mini-signals/blob/master/LICENSE)\n\n## Description\n\nCustom event/messaging system for TypeScript/JavaScript inspired by [js-signals](https://github.com/millermedeiros/js-signals) originally based on [EventEmitter3](https://github.com/primus/eventemitter3) code base.\n\nThere are several advantages to signals over event-emitters (see [Comparison between different Observer Pattern implementations](https://github.com/millermedeiros/js-signals/wiki/Comparison-between-different-Observer-Pattern-implementations)). However, the current implementation of [js-signals](https://github.com/millermedeiros/js-signals) is (arguably) slow compared to other implementations (see [EventsSpeedTests](https://github.com/Hypercubed/EventsSpeedTests)). `mini-signals` is a fast, minimal emitter, with an API similar to [js-signals](https://github.com/millermedeiros/js-signals).\n\n\u003e Note: Signals here are the type defined by Miller Medeiros in [js-signals](https://github.com/millermedeiros/js-signals) inspired by AS3-Signals.  They should not to be confused with [SolidJS](https://www.solidjs.com/tutorial/introduction_signals) or [Angular signals](https://github.com/angular/angular/discussions/49090).\n\n## mini-signals 2.0.0\n\nMiniSignals v2.0.0 has been rewritten in TypeScript and had it's API changed to improve performance and add type safety.\n\nNew features:\n\n- `.add` now returns a node reference which can be used to remove the listener directly from the signal.  Reduces memory leaks.\n- `.add` is now type safe.  The type of the listener is checked against the type variable in the constructor as well as an optional \"flavor\".\n\nBreaking changes:\n\n- `.add` now returns a node reference instead of an object.  The returned node cannot be removed directly; it must be from the signal using `MiniSignal#detach`.\n- `.once` has been removed.  Use `.add` instead with a call to `.detach` in the callback.\n- The `thisArg` parameter has been removed from `.add`.  Use `.add` with a call to `.bind` or (preferred) use an arrow function with a closure.\n- `.dispatch` now throws an error if the signal is already dispatching.\n`.detach` now throws an error if the node reference was not generated from the signal.\n\n## Install\n\n### npm:\n\n```sh\nnpm install mini-signals\n```\n\n## Examples\n\n```ts\nimport { MiniSignal } from 'mini-signals';\n\nconst mySignal = new MiniSignal\u003c[string, string]\u003e();  // the type variable optionally and defines the parameters to be dispatched\n\nconst binding = mySignal.add((foo: string, bar: string) =\u003e { // add listener, note the parameter types match the type variable in the constructor\n  console.log('signal dispatched');\n  assert(foo === 'foo');\n  assert(bar === 'bar');\n});\n\nmySignal.dispatch('foo', 'bar'); // dispatch signal passing custom parameters\nmySignal.detach(binding); // remove a single listener\n```\n\n### Another Example\n\n```ts\nconst myObject = {\n  foo: \"bar\",\n  updated: new MiniSignal\u003cnever\u003e() // in this case the type variable is never, since we are not passing any parameters\n};\n\nmyObject.updated.add(() =\u003e {\n  console.log('signal dispatched');\n  assert(myObject.foo === 'baz');\n});\n\nmyObject.foo = 'baz';\nmyObject.updated.dispatch(); // dispatch signal\n```\n\n### Flavoring the signal\n\n```ts\nimport { MiniSignal } from 'mini-signals';\n\nconst mySignal = new MiniSignal\u003c[string, string], 'mySignal'\u003e();\nconst myOtherSignal = new MiniSignal\u003c[string, string], 'myOtherSignal'\u003e();\n\nconst binding = mySignal.add((foo: string, bar: string) =\u003e {\n  // ...\n});\n\nmyOtherSignal.detach(binding); // TypeScript error: Argument of type 'MiniSignalBinding\u003c[string, string], \"mySignal\"\u003e' is not assignable to parameter of type 'MiniSignalBinding\u003c[string, string], \"myOtherSignal\"\u003e'.\n```\n\n## API\n\nSee [API.md](https://github.com/Hypercubed/mini-signals/blob/master/docs/classes/MiniSignal.md)\n\n## License\n\nCopyright (c) 2015-2023 Jayson Harshbarger\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypercubed%2Fmini-signals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhypercubed%2Fmini-signals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypercubed%2Fmini-signals/lists"}