{"id":16788793,"url":"https://github.com/markmead/alpinejs-emit","last_synced_at":"2025-07-04T06:09:31.399Z","repository":{"id":98518927,"uuid":"560838232","full_name":"markmead/alpinejs-emit","owner":"markmead","description":"Emit `x-data` changes to other Alpine JS elements 📣","archived":false,"fork":false,"pushed_at":"2025-03-07T08:15:15.000Z","size":33,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T20:12:30.778Z","etag":null,"topics":["alpine-js","alpinejs","alpinejs-emit","alpinejs-emitter","alpinejs-plugin","javascript-emit"],"latest_commit_sha":null,"homepage":"https://js.hyperui.dev/examples/utility-emit","language":"JavaScript","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/markmead.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-02T11:36:31.000Z","updated_at":"2025-03-24T08:02:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"fbcced49-2d5b-4fdc-bf6b-98cca4e93e5d","html_url":"https://github.com/markmead/alpinejs-emit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"markmead/alpinejs-plugin-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-emit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-emit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-emit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-emit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markmead","download_url":"https://codeload.github.com/markmead/alpinejs-emit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248313628,"owners_count":21082888,"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":["alpine-js","alpinejs","alpinejs-emit","alpinejs-emitter","alpinejs-plugin","javascript-emit"],"created_at":"2024-10-13T08:24:47.875Z","updated_at":"2025-04-10T23:25:06.147Z","avatar_url":"https://github.com/markmead.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alpine JS Emit\n\nEmit data changes to other Alpine JS elements 📣\n\n## Install\n\n### With a CDN\n\n```html\n\u003cscript\n  defer\n  src=\"https://unpkg.com/alpinejs-emit@latest/dist/emit.min.js\"\n\u003e\u003c/script\u003e\n\n\u003cscript defer src=\"https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js\"\u003e\u003c/script\u003e\n```\n\n### With a Package Manager\n\n```shell\nyarn add -D alpinejs-emit\n\nnpm install -D alpinejs-emit\n```\n\n```js\nimport Alpine from 'alpinejs'\nimport emit from 'alpinejs-emit'\n\nAlpine.plugin(emit)\n\nAlpine.start()\n```\n\n## Example\n\n### Single Target\n\n```html\n\u003cbutton x-data x-on:click=\"$emit('#TargetEl', { isChecked: false })\"\u003e\n  Click\n\u003c/button\u003e\n\n\u003cdiv x-data=\"{ isChecked: false }\" id=\"TargetEl\"\u003e\n  \u003cbutton x-on:click=\"isChecked = !isChecked\"\u003eToggle\u003c/button\u003e\n\n  \u003cspan x-show=\"isChecked\"\u003eChecked\u003c/span\u003e\n\u003c/div\u003e\n```\n\nThe `$emit` will change the value of `isChecked` on the `TargetEl` element.\n\nYou'll notice within the `TargetEl` element it has its own method of changing\nthe `isChecked` value, this will still work.\n\nIf you wanted to toggle the value of `isChecked` you can do so with\n`{ isChecked: '!!' }`, this will check for `!!` and if found, toggle the value\nbased on the `isChecked` value on the `TargetEl` element.\n\n#### Multiple Targets with a Shared Selector\n\nThis has been handled before you behind the scenes.\n\n_`isChecked` is just an example, you don't need to call your Alpine JS data\nthat_\n\n### Multiple Targets\n\n```html\n\u003cdiv\n  x-data=\"{ isChecked: false }\"\n  x-init=\"$watch('isChecked', () =\u003e $emit([\n        ['#TargetEl', { isChecked }],\n        ['#TargetEl2', { userName: 'Doe' }]\n    ]))\"\n\u003e\n  \u003cbutton x-on:click=\"isChecked = !isChecked\"\u003eToggle\u003c/button\u003e\n\n  \u003cspan x-show=\"isChecked\"\u003eChecked\u003c/span\u003e\n\u003c/div\u003e\n\n\u003cdiv x-data=\"{ isChecked: false }\" id=\"TargetEl\"\u003e\n  \u003cbutton x-on:click=\"isChecked = !isChecked\"\u003eToggle\u003c/button\u003e\n\n  \u003cspan x-show=\"isChecked\"\u003eChecked\u003c/span\u003e\n\u003c/div\u003e\n\n\u003cdiv x-data=\"{ userName: 'John' }\" id=\"TargetEl2\"\u003e\n  \u003cspan x-text=\"userName\"\u003e\u003c/span\u003e\n\u003c/div\u003e\n```\n\nThis works exactly the same as the above but you pass an array of arrays\ninstead.\n\n```js\n$emit([\n  ['.select1', {}],\n  ['#select2', {}],\n])\n```\n\n## Stats\n\n![](https://img.shields.io/bundlephobia/min/alpinejs-emit)\n![](https://img.shields.io/npm/v/alpinejs-emit)\n![](https://img.shields.io/npm/dt/alpinejs-emit)\n![](https://img.shields.io/github/license/markmead/alpinejs-emit)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-emit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkmead%2Falpinejs-emit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-emit/lists"}