https://github.com/keajs/kea-subscriptions
https://github.com/keajs/kea-subscriptions
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/keajs/kea-subscriptions
- Owner: keajs
- License: mit
- Created: 2022-04-23T11:19:05.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-17T21:43:28.000Z (over 1 year ago)
- Last Synced: 2025-04-04T12:04:34.104Z (about 2 months ago)
- Language: TypeScript
- Size: 108 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/kea-subscriptions)
[](https://bundlephobia.com/result?p=kea-subscriptions)
[](https://bundlephobia.com/result?p=kea-subscriptions)
[](#backers)
[](#sponsors)# kea-subscriptions
Subscribe to changes in values. Works with kea `3.0.0` and up.
## Sample usage
[Read the documentation](https://keajs.org/docs/plugins/subscriptions)
```ts
import { kea, actions, reducers } from 'kea'
import { subscriptionsPlugin, subscriptions } from 'kea-subscriptions'// once per app
resetContext({ plugins: [subscriptionsPlugin] }) // hook into reduxconst logic = kea([
actions({ setMyValue: (value) => ({ value }) }),
reducers({ myValue: ['default', { setMyValue: (_, { value }) => value }] }),
subscriptions({ myValue: (value, oldValue) => console.log({ value, oldValue }) }),
])logic.mount()
// [console.log] { value: 'default', oldValue: undefined }
logic.actions.setMyValue('coffee')
// [console.log] { value: 'coffee', oldValue: 'default' }
logic.actions.setMyValue('bagels')
// [console.log] { value: 'bagels', oldValue: 'coffee' }
```