bgio-effects
Version:
📤 Helpers for managing state effects in boardgame.io
65 lines (44 loc) • 1.85 kB
Markdown
[](https://www.npmjs.com/package/bgio-effects)
[](https://github.com/delucis/bgio-effects/actions?query=workflow%3ACI)
[](https://coveralls.io/github/delucis/bgio-effects?branch=latest)
> 📤 Helpers for managing state effects in [boardgame.io][bgio].
This package provides a structured approach to triggering ephemeral “effects”
in game code that can be consumed from state on the client. It provides a game
plugin and a client-side extension that emits events for your effects.
```sh
npm i bgio-effects
```
Call effects from your moves or other game code:
```js
function move(G, ctx) {
ctx.effects.explode();
}
```
Listen for effects on the client:
```js
const onExplode = () => {
// render explosion/play sound/etc.
};
// With the plain JS emitter
emitter.on('explode', onExplode);
// With the React hook
useEffectListener('explode', onExplode, []);
```
**[See the full documentation website →][docs]**
This is an experimental project and feedback is welcome. Please
[][bugs] if you run into any problems, have a question, or want
to suggest features/improvements. PRs are welcome too 😊.
Please also note [the code of conduct][coc] and be kind to each other.
The code in this repository is provided under the terms of
[][license].
[]: https://boardgame.io/
[]: https://delucis.github.io/bgio-effects/
[]: https://github.com/delucis/bgio-effects/issues/new/choose
[]: CODE_OF_CONDUCT.md
[]: LICENSE