An open API service indexing awesome lists of open source software.

https://github.com/markmead/alpinejs-emit

Emit `x-data` changes to other Alpine JS elements 📣
https://github.com/markmead/alpinejs-emit

alpine-js alpinejs alpinejs-emit alpinejs-emitter alpinejs-plugin javascript-emit

Last synced: 12 months ago
JSON representation

Emit `x-data` changes to other Alpine JS elements 📣

Awesome Lists containing this project

README

          

# Alpine JS Emit

Emit data changes to other Alpine JS elements 📣

## Install

### With a CDN

```html

```

### With a Package Manager

```shell
yarn add -D alpinejs-emit

npm install -D alpinejs-emit
```

```js
import Alpine from 'alpinejs'
import emit from 'alpinejs-emit'

Alpine.plugin(emit)

Alpine.start()
```

## Example

### Single Target

```html

Click


Toggle

Checked


```

The `$emit` will change the value of `isChecked` on the `TargetEl` element.

You'll notice within the `TargetEl` element it has its own method of changing
the `isChecked` value, this will still work.

If you wanted to toggle the value of `isChecked` you can do so with
`{ isChecked: '!!' }`, this will check for `!!` and if found, toggle the value
based on the `isChecked` value on the `TargetEl` element.

#### Multiple Targets with a Shared Selector

This has been handled before you behind the scenes.

_`isChecked` is just an example, you don't need to call your Alpine JS data
that_

### Multiple Targets

```html


Toggle

Checked


Toggle

Checked




```

This works exactly the same as the above but you pass an array of arrays
instead.

```js
$emit([
['.select1', {}],
['#select2', {}],
])
```

## Stats

![](https://img.shields.io/bundlephobia/min/alpinejs-emit)
![](https://img.shields.io/npm/v/alpinejs-emit)
![](https://img.shields.io/npm/dt/alpinejs-emit)
![](https://img.shields.io/github/license/markmead/alpinejs-emit)