1.2.0 • Published 1 year ago

react-ch v1.2.0

Weekly downloads
130
License
MIT
Repository
github
Last release
1 year ago

react-ch

The Channel class is used to achieve loose coupling between an event source and its subscribers. To notify subscribers, it must be called as a function.

The useChannel hook has two different use cases.

  • as a shortcut for useConstant(() => new Channel(name))

  • for subscribing to a channel

const didLogin = useChannel<User>()

// Listen for "didLogin" events while mounted.
useChannel(didLogin, (user: User) => {...})

// Send an event to subscribers.
didLogin(user)

Async decentralized work

Channels can be used to depend on arbitrary work performed by subscribers. Every event has a promise that resolves with an array of return values (from subscribers).

// Use a channel to orchestrate animations.
const willAppear = useChannel<[], void>()
await willAppear()

// In a deep descendant:
useChannel(willAppear, () => animate(...))
1.2.0

1 year ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.2

4 years ago

1.0.0

4 years ago

0.0.0

4 years ago