Skip to content

keajs/kea-subscriptions

Repository files navigation

NPM Version minified minified + gzipped Backers on Open Collective Sponsors on Open Collective

kea-subscriptions

Subscribe to changes in values. Works with kea 3.0.0 and up.

Sample usage

Read the documentation

import { kea, actions, reducers } from 'kea'
import { subscriptionsPlugin, subscriptions } from 'kea-subscriptions'

// once per app
resetContext({ plugins: [subscriptionsPlugin] }) // hook into redux

const 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' }

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published