{"_id":"@alwatr/on","_rev":"6-f2ae446e0263cf4300edebef4ea9e982","name":"@alwatr/on","dist-tags":{"latest":"9.11.1"},"versions":{"9.9.0":{"name":"@alwatr/on","version":"9.9.0","keywords":["action","alwatr","browser-api","declarative-ui","decorator","directive","dom","esm","event","frontend","javascript","lightweight","module","nanolib","signal","spa","typescript","ui-library","vanilla-js","web-development"],"author":{"url":"https://ali.mihandoost.com","name":"S. Ali Mihandoost","email":"ali.mihandoost@gmail.com"},"license":"MPL-2.0","_id":"@alwatr/on@9.9.0","maintainers":[{"name":"alimd","email":"ali.mihan.doost@gmail.com"}],"homepage":"https://github.com/Alwatr/alwatr/tree/next/pkg/nanolib/on#readme","bugs":{"url":"https://github.com/Alwatr/alwatr/issues"},"dist":{"shasum":"31f31703c03f4cb5d4ff809bffc78dc265d6ccdd","tarball":"https://registry.npmjs.org/@alwatr/on/-/on-9.9.0.tgz","fileCount":17,"integrity":"sha512-aoWvUGQBSFFGc9cgZW47YRdbk2Ed0tQxLFeCgb8x/eJUDijcAzPB1drATbrxHGI/FyKQHL/R2xW4AQqOg0wrUQ==","signatures":[{"sig":"MEUCIQCcgL0bsQpCsYTcVpZBNxFmDoEh5H6t8PHfMPll00iViwIgTmxwRO7xwDSza6mpY7ggKOFJgMEVKyl9SUir383uVnI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":42144},"type":"module","exports":{".":{"types":"./dist/main.d.ts","import":"./dist/main.js","default":"./dist/main.js"}},"gitHead":"ddf2d42c90a5dd90cccd0351d106833c80726136","scripts":{"b":"bun run build","t":"bun run test","w":"bun run watch","cl":"bun run clean","lint":"eslint src/ --ext .ts","test":"ALWATR_DEBUG=0 bun test","build":"bun run build:ts && bun run build:es","clean":"rm -rfv dist *.tsbuildinfo","watch":"bun run watch:ts & bun run watch:es","format":"prettier --write \"src/**/*.ts\"","build:es":"nano-build --preset=module src/main.ts","build:ts":"tsc --build","watch:es":"bun run build:es --watch","watch:ts":"bun run build:ts --watch --preserveWatchOutput"},"_npmUser":{"name":"alimd","email":"ali.mihan.doost@gmail.com"},"repository":{"url":"git+https://github.com/Alwatr/alwatr.git","type":"git","directory":"pkg/nanolib/on"},"_npmVersion":"lerna/5.0.0/node@v20.20.2+x64 (linux)","description":"Declarative DOM action-dispatch — bridge HTML attributes to typed signal handlers.","directories":{},"sideEffects":false,"_nodeVersion":"20.20.2","dependencies":{"@alwatr/signal":"9.9.0","@alwatr/directive":"9.9.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^6.0.2","@alwatr/standard":"9.7.0","@alwatr/nano-build":"9.3.0","@alwatr/type-helper":"9.1.1","@happy-dom/global-registrator":"^20.9.0"},"_npmOperationalInternal":{"tmp":"tmp/on_9.9.0_1776193931224_0.45208430692458457","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Package renamed to @alwatr/action. Please update your project."},"9.10.0":{"name":"@alwatr/on","version":"9.10.0","keywords":["action","alwatr","browser-api","declarative-ui","decorator","directive","dom","esm","event","frontend","javascript","lightweight","module","nanolib","signal","spa","typescript","ui-library","vanilla-js","web-development"],"author":{"url":"https://ali.mihandoost.com","name":"S. Ali Mihandoost","email":"ali.mihandoost@gmail.com"},"license":"MPL-2.0","_id":"@alwatr/on@9.10.0","maintainers":[{"name":"alimd","email":"ali.mihan.doost@gmail.com"}],"homepage":"https://github.com/Alwatr/alwatr/tree/next/pkg/nanolib/on#readme","bugs":{"url":"https://github.com/Alwatr/alwatr/issues"},"dist":{"shasum":"282b17bcb1bd0377c7cd2e462f2c7632a4a5b7c0","tarball":"https://registry.npmjs.org/@alwatr/on/-/on-9.10.0.tgz","fileCount":17,"integrity":"sha512-HVH6qxOFTzebz/zg1ihMRJWy1nG9OvDNMH58MVpz1ShWOYj+aCeMc7zkyFqTv3X4KebmfTvOJkkBVcuc4rIrXA==","signatures":[{"sig":"MEQCIE+3UCG0W3UCWiBzuVO+AXo0HRReuWBmFLOzQ0Z9rqMvAiBflK0Qh9pPrwgaRy7wXw3sTKX7mVnlNoiH0C+kGmcU+g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":42153},"type":"module","exports":{".":{"types":"./dist/main.d.ts","import":"./dist/main.js","default":"./dist/main.js"}},"gitHead":"b88ae5cd72935e76e019e3765c36eb633ece2910","scripts":{"b":"bun run build","t":"bun run test","w":"bun run watch","cl":"bun run clean","lint":"eslint src/ --ext .ts","test":"ALWATR_DEBUG=0 bun test","build":"bun run build:ts && bun run build:es","clean":"rm -rfv dist *.tsbuildinfo","watch":"bun run watch:ts & bun run watch:es","format":"prettier --write \"src/**/*.ts\"","build:es":"nano-build --preset=module-web src/main.ts","build:ts":"tsc --build","watch:es":"bun run build:es --watch","watch:ts":"bun run build:ts --watch --preserveWatchOutput"},"_npmUser":{"name":"alimd","email":"ali.mihan.doost@gmail.com"},"repository":{"url":"git+https://github.com/Alwatr/alwatr.git","type":"git","directory":"pkg/nanolib/on"},"_npmVersion":"lerna/5.0.0/node@v20.20.2+x64 (linux)","description":"Declarative DOM action-dispatch — bridge HTML attributes to typed signal handlers.","directories":{},"sideEffects":false,"_nodeVersion":"20.20.2","dependencies":{"@alwatr/signal":"9.10.0","@alwatr/directive":"9.10.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^6.0.2","@alwatr/standard":"9.7.0","@alwatr/nano-build":"9.10.0","@alwatr/type-helper":"9.1.1","@happy-dom/global-registrator":"^20.9.0"},"_npmOperationalInternal":{"tmp":"tmp/on_9.10.0_1776278452425_0.09303549425098279","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Package renamed to @alwatr/action. Please update your project."},"9.10.1":{"name":"@alwatr/on","version":"9.10.1","keywords":["action","alwatr","browser-api","declarative-ui","decorator","directive","dom","esm","event","frontend","javascript","lightweight","module","nanolib","signal","spa","typescript","ui-library","vanilla-js","web-development"],"author":{"url":"https://ali.mihandoost.com","name":"S. Ali Mihandoost","email":"ali.mihandoost@gmail.com"},"license":"MPL-2.0","_id":"@alwatr/on@9.10.1","maintainers":[{"name":"alimd","email":"ali.mihan.doost@gmail.com"}],"homepage":"https://github.com/Alwatr/alwatr/tree/next/pkg/nanolib/on#readme","bugs":{"url":"https://github.com/Alwatr/alwatr/issues"},"dist":{"shasum":"b10cd4618d717be63e5e8705e6f140f34def081d","tarball":"https://registry.npmjs.org/@alwatr/on/-/on-9.10.1.tgz","fileCount":17,"integrity":"sha512-EO5CfRI/m+aW0YdvOyZ3HafEk21Dp/eEPdGrNqcojE2/b8V6zt+jpaMOH6GJEcj2UYIDM3sprIj05kJFK2lYng==","signatures":[{"sig":"MEQCID9ftuqnep/dq+D0iWlT1AT2NspBaQRH7FVJNXIqBW5VAiAp9wMrHpCqZr5EDXsV+gbuAzFI5Q1arvSDVwg04uIG+Q==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":42153},"type":"module","exports":{".":{"types":"./dist/main.d.ts","import":"./dist/main.js","default":"./dist/main.js"}},"gitHead":"602a7b285b0cf6d799d97e44db81265ff73e47a2","scripts":{"b":"bun run build","t":"bun run test","w":"bun run watch","cl":"bun run clean","lint":"eslint src/ --ext .ts","test":"ALWATR_DEBUG=0 bun test","build":"bun run build:ts && bun run build:es","clean":"rm -rfv dist *.tsbuildinfo","watch":"bun run watch:ts & bun run watch:es","format":"prettier --write \"src/**/*.ts\"","build:es":"nano-build --preset=module-web src/main.ts","build:ts":"tsc --build","watch:es":"bun run build:es --watch","watch:ts":"bun run build:ts --watch --preserveWatchOutput"},"_npmUser":{"name":"alimd","email":"ali.mihan.doost@gmail.com"},"repository":{"url":"git+https://github.com/Alwatr/alwatr.git","type":"git","directory":"pkg/nanolib/on"},"_npmVersion":"lerna/5.0.0/node@v20.20.2+x64 (linux)","description":"Declarative DOM action-dispatch — bridge HTML attributes to typed signal handlers.","directories":{},"sideEffects":false,"_nodeVersion":"20.20.2","dependencies":{"@alwatr/signal":"9.10.1","@alwatr/directive":"9.10.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^6.0.2","@alwatr/standard":"9.7.0","@alwatr/nano-build":"9.10.1","@alwatr/type-helper":"9.1.1","@happy-dom/global-registrator":"^20.9.0"},"_npmOperationalInternal":{"tmp":"tmp/on_9.10.1_1776541379570_0.9950363095932595","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Package renamed to @alwatr/action. Please update your project."},"9.11.0":{"name":"@alwatr/on","version":"9.11.0","keywords":["action","alwatr","browser-api","declarative-ui","decorator","directive","dom","esm","event","frontend","javascript","lightweight","module","nanolib","signal","spa","typescript","ui-library","vanilla-js","web-development"],"author":{"url":"https://ali.mihandoost.com","name":"S. Ali Mihandoost","email":"ali.mihandoost@gmail.com"},"license":"MPL-2.0","_id":"@alwatr/on@9.11.0","maintainers":[{"name":"alimd","email":"ali.mihan.doost@gmail.com"}],"homepage":"https://github.com/Alwatr/alwatr/tree/next/pkg/nanolib/on#readme","bugs":{"url":"https://github.com/Alwatr/alwatr/issues"},"dist":{"shasum":"93e39523e6e07e11882fc0d62e387842df348ecb","tarball":"https://registry.npmjs.org/@alwatr/on/-/on-9.11.0.tgz","fileCount":17,"integrity":"sha512-K2oGL92CYlJ1mF8M5TXKEf1l+Q4EfGiwI2t3ihJ2fSzYw50cOLsCUjcB5CvRK3Wjop9tjWr0H1obC1uzMntkKw==","signatures":[{"sig":"MEUCIQCjih0lnB7ak3KjWmEAORYFJc5bCc8a0qu5Ea9pQVL1XQIgUEB+UGLAQYZLYCewRuE05tISEdmxxgVkURjMz9W64dc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":45573},"type":"module","exports":{".":{"types":"./dist/main.d.ts","import":"./dist/main.js","default":"./dist/main.js"}},"gitHead":"29a71f04aff78a80f55c57fa771af89cc0867cf6","scripts":{"b":"bun run build","t":"bun run test","w":"bun run watch","cl":"bun run clean","lint":"eslint src/ --ext .ts","test":"ALWATR_DEBUG=0 bun test","build":"bun run build:ts && bun run build:es","clean":"rm -rfv dist *.tsbuildinfo","watch":"bun run watch:ts & bun run watch:es","format":"prettier --write \"src/**/*.ts\"","build:es":"nano-build --preset=module-web src/main.ts","build:ts":"tsc --build","watch:es":"bun run build:es --watch","watch:ts":"bun run build:ts --watch --preserveWatchOutput"},"_npmUser":{"name":"alimd","email":"ali.mihan.doost@gmail.com"},"repository":{"url":"git+https://github.com/Alwatr/alwatr.git","type":"git","directory":"pkg/nanolib/on"},"_npmVersion":"lerna/5.0.0/node@v20.20.2+x64 (linux)","description":"Declarative DOM action-dispatch — bridge HTML attributes to typed signal handlers.","directories":{},"sideEffects":false,"_nodeVersion":"20.20.2","dependencies":{"@alwatr/signal":"9.10.1","@alwatr/directive":"9.11.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^6.0.2","@alwatr/standard":"9.7.0","@alwatr/nano-build":"9.10.1","@alwatr/type-helper":"9.1.1","@happy-dom/global-registrator":"^20.9.0"},"_npmOperationalInternal":{"tmp":"tmp/on_9.11.0_1776608454919_0.22823527437439628","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Package renamed to @alwatr/action. Please update your project."},"9.11.1":{"name":"@alwatr/on","version":"9.11.1","keywords":["action","alwatr","browser-api","declarative-ui","decorator","directive","dom","esm","event","frontend","javascript","lightweight","module","nanolib","signal","spa","typescript","ui-library","vanilla-js","web-development"],"author":{"url":"https://ali.mihandoost.com","name":"S. Ali Mihandoost","email":"ali.mihandoost@gmail.com"},"license":"MPL-2.0","_id":"@alwatr/on@9.11.1","maintainers":[{"name":"alimd","email":"ali.mihan.doost@gmail.com"}],"homepage":"https://github.com/Alwatr/alwatr/tree/next/pkg/nanolib/on#readme","bugs":{"url":"https://github.com/Alwatr/alwatr/issues"},"dist":{"shasum":"c3c2bbb45a9da2c3a10b0230b90e61d10f2151df","tarball":"https://registry.npmjs.org/@alwatr/on/-/on-9.11.1.tgz","fileCount":17,"integrity":"sha512-CwAuQakcG3h3BCICMob4/LmTKqnWwjpv5MoiE41PCQx4ISKfCltdqMi8Mz2qBHefmgT30elmlD95DUlJow6r3g==","signatures":[{"sig":"MEYCIQCwa+CrYzjSsnxTet0eCuBsmOzcmnRHReSqVGrxALz9VwIhAOQjT8NLtHGSAWyy23a9F7M+fEDX0yM7gMVp4bTjQPEh","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":45867},"type":"module","exports":{".":{"types":"./dist/main.d.ts","import":"./dist/main.js","default":"./dist/main.js"}},"gitHead":"3a199acf20e1821f4d6f1c1884d5fee821dbaf66","scripts":{"b":"bun run build","t":"bun run test","w":"bun run watch","cl":"bun run clean","lint":"eslint src/ --ext .ts","test":"ALWATR_DEBUG=0 bun test","build":"bun run build:ts && bun run build:es","clean":"rm -rfv dist *.tsbuildinfo","watch":"bun run watch:ts & bun run watch:es","format":"prettier --write \"src/**/*.ts\"","build:es":"nano-build --preset=module-web src/main.ts","build:ts":"tsc --build","watch:es":"bun run build:es --watch","watch:ts":"bun run build:ts --watch --preserveWatchOutput"},"_npmUser":{"name":"alimd","email":"ali.mihan.doost@gmail.com"},"repository":{"url":"git+https://github.com/Alwatr/alwatr.git","type":"git","directory":"pkg/nanolib/on"},"_npmVersion":"lerna/5.0.0/node@v20.20.2+x64 (linux)","description":"Declarative DOM action-dispatch — bridge HTML attributes to typed signal handlers.","directories":{},"sideEffects":false,"_nodeVersion":"20.20.2","dependencies":{"@alwatr/signal":"9.10.1","@alwatr/directive":"9.11.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^6.0.2","@alwatr/standard":"9.7.0","@alwatr/nano-build":"9.10.1","@alwatr/type-helper":"9.1.1","@happy-dom/global-registrator":"^20.9.0"},"_npmOperationalInternal":{"tmp":"tmp/on_9.11.1_1776609312561_0.29741288790156206","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Package renamed to @alwatr/action. Please update your project."}},"time":{"created":"2026-04-14T19:12:11.150Z","modified":"2026-04-21T20:14:45.497Z","9.9.0":"2026-04-14T19:12:11.350Z","9.10.0":"2026-04-15T18:40:52.561Z","9.10.1":"2026-04-18T19:42:59.827Z","9.11.0":"2026-04-19T14:20:55.072Z","9.11.1":"2026-04-19T14:35:12.703Z"},"bugs":{"url":"https://github.com/Alwatr/alwatr/issues"},"author":{"url":"https://ali.mihandoost.com","name":"S. Ali Mihandoost","email":"ali.mihandoost@gmail.com"},"license":"MPL-2.0","homepage":"https://github.com/Alwatr/alwatr/tree/next/pkg/nanolib/on#readme","keywords":["action","alwatr","browser-api","declarative-ui","decorator","directive","dom","esm","event","frontend","javascript","lightweight","module","nanolib","signal","spa","typescript","ui-library","vanilla-js","web-development"],"repository":{"url":"git+https://github.com/Alwatr/alwatr.git","type":"git","directory":"pkg/nanolib/on"},"description":"Declarative DOM action-dispatch — bridge HTML attributes to typed signal handlers.","maintainers":[{"name":"alimd","email":"ali.mihan.doost@gmail.com"}],"readme":"# @alwatr/on\n\n**Declarative DOM action-dispatch — without a framework.**\n\n`@alwatr/on` bridges HTML attributes to typed signal handlers. Add an `alwatr-on` attribute to any element, and the library automatically listens for the specified DOM event, resolves the payload, and dispatches a named action signal. Subscribe to actions anywhere in your app with `alwatrOn`.\n\n---\n\n## Why `@alwatr/on`?\n\n| Approach                               | Problem                                                  |\n| -------------------------------------- | -------------------------------------------------------- |\n| Inline `addEventListener` everywhere   | Scattered, hard to trace, breaks on dynamic content      |\n| Framework event bindings (React, Vue…) | Requires full framework buy-in                           |\n| Custom events + `dispatchEvent`        | Verbose, no typed payload, no central subscription point |\n| **`@alwatr/on`**                       | ✅ Declarative, typed, zero-coupling, SPA-friendly       |\n\n---\n\n## Installation\n\n```bash\nbun add @alwatr/on\n# or\nnpm i @alwatr/on\n```\n\n---\n\n## Attribute Syntax\n\n```\nalwatr-on=\"eventType->actionId\"\nalwatr-on=\"eventType->actionId:payload\"\n```\n\n| Segment     | Description                                                  | Example                       |\n| ----------- | ------------------------------------------------------------ | ----------------------------- |\n| `eventType` | Any DOM event name, or `init` for one-shot dispatch          | `click`, `input`, `init`      |\n| `actionId`  | Identifier your handler subscribes to                        | `open-drawer`, `search-query` |\n| `:payload`  | Optional literal string, or `$value` to read `element.value` | `:main`, `:$value`            |\n\n### Special values\n\n- **`init`** — dispatches the action immediately on bootstrap, then destroys the directive. No persistent listener.\n- **`$value`** — resolves to the element's `.value` at dispatch time (ideal for `<input>`, `<select>`, `<textarea>`).\n\n---\n\n## Quick Start\n\n### 1. Register the directive and bootstrap\n\n```typescript\nimport {bootstrapDirectives} from '@alwatr/directive';\nimport '@alwatr/on'; // importing registers AlwatrActionDirective\n\nbootstrapDirectives();\n```\n\n### 2. Subscribe to actions\n\n```typescript\nimport {alwatrOn} from '@alwatr/on';\n\n// Fires whenever any element with alwatr-on=\"click->open-drawer:*\" is clicked\nalwatrOn('open-drawer', (payload) => {\n  openDrawer(payload); // payload === 'main'\n});\n\n// Fires on every keystroke in an input with alwatr-on=\"input->search-query:$value\"\nalwatrOn('search-query', (query) => {\n  performSearch(query);\n});\n\n// Fires once on page load from alwatr-on=\"init->page-loaded\"\nalwatrOn('page-loaded', () => {\n  console.log('Page is ready');\n});\n```\n\n### 3. Add attributes to HTML\n\n```html\n<!-- Dispatches 'open-drawer' with payload 'main' on click -->\n<button alwatr-on=\"click->open-drawer:main\">Open Drawer</button>\n\n<!-- Dispatches 'open-drawer' with payload 'settings' on click -->\n<button alwatr-on=\"click->open-drawer:settings\">Settings</button>\n\n<!-- Dispatches 'search-query' with the input's live value -->\n<input\n  type=\"search\"\n  alwatr-on=\"input->search-query:$value\"\n  placeholder=\"Search…\"\n/>\n\n<!-- Dispatches 'page-loaded' once, immediately on bootstrap -->\n<div alwatr-on=\"init->page-loaded\"></div>\n```\n\n---\n\n## API Reference\n\n### `alwatrOn(actionId, handler)`\n\nSubscribes to a named action dispatched by any `alwatr-on` directive.\n\n```typescript\nfunction alwatrOn(actionId: string, handler: (payload: string) => void): SubscribeResult;\n```\n\n| Parameter  | Type                        | Description                             |\n| ---------- | --------------------------- | --------------------------------------- |\n| `actionId` | `string`                    | The action identifier to listen for     |\n| `handler`  | `(payload: string) => void` | Called with the resolved payload string |\n\nReturns a `SubscribeResult` with an `unsubscribe()` method.\n\n```typescript\nconst sub = alwatrOn('open-drawer', (payload) => {\n  /* … */\n});\n\n// Stop listening when no longer needed (prevents memory leaks)\nsub.unsubscribe();\n```\n\n---\n\n### `AlwatrActionDirective`\n\nThe directive class registered under the `alwatr-on` attribute. Extends `DirectiveBase` from `@alwatr/directive`.\n\nYou rarely need to interact with this class directly — importing `@alwatr/on` registers it automatically.\n\n---\n\n## Lifecycle\n\n```\nbootstrapDirectives()\n  │\n  └─ finds element with alwatr-on=\"click->open-drawer:main\"\n       │\n       └─ new AlwatrActionDirective(element, 'alwatr-on')\n            │\n            └─ after one macrotask → init_()\n                 │\n                 ├─ parse attributeValue with syntaxRegex\n                 ├─ if invalid → log accident, return\n                 ├─ if eventType === 'init' → dispatch once, destroy()\n                 └─ else → addEventListener(eventType, dispatch_)\n                            addDestroyHook(removeEventListener)\n```\n\n---\n\n## Cleanup & Memory Management\n\nEvery `addEventListener` registered by the directive has a corresponding `removeEventListener` in a destroy hook. Call `autoDestructDirectives()` periodically (or on route changes) to clean up directives whose elements have been removed from the DOM.\n\n```typescript\nimport {autoDestructDirectives} from '@alwatr/directive';\n\n// Clean up on every SPA navigation\nrouter.on('navigate', autoDestructDirectives);\n```\n\n---\n\n## Contributing\n\nContributions are welcome! Please read our [contribution guidelines](https://github.com/Alwatr/.github/blob/next/CONTRIBUTING.md) before submitting a pull request.\n\n## License\n\nMPL-2.0 — see [LICENSE](./LICENSE).\n","readmeFilename":"README.md"}