Reactivity powers the interactivity in React applications. This programming paradigm refers to a system's ability to respond to changes in data or state automatically. In React, this is natively built into the JSX render engine which means that when state changes, React re-renders any component that either defines or consumes it.
Cerberus Signals remove that constraint and provide a way to control to define and consume state without causing re-renders when updates happen.
This example shows the diversity of just one of the APIs the signals library provide:
Here the Demo component will re-render only on updates. However, the ReactiveText
component will never re-render on updates to ensure fine-grained reactivity.
This is just one of many ways to achieve fine-grained reactivity with Cerberus Signals.
There are two core elements in a reactive system: Signals and Subscribers.
Signals serve as core elements in reactive systems, playing an important role in data management and system responsiveness. They are responsible for storing and managing data, as well as triggering updates across the system.
This is done through the use of accessors (a.k.a. getters) and setters.
There are two ways to create signals:
createSignal: create signals outside of components in any scenariouseSignal: create signals inside of componentsSubscribers are the other core element in reactive systems. They are responsible for tracking changes in signals and updating the system accordingly. They are automated responders that keep the system up-to-date with the latest data changes.
Most importantly: this lives outside of the React render engine
This enables Cerberus Signals to allow creating global, local, external/local component state updates without affecting the VDOM renders.
Subscribers work based on two main actions:
There are multiple APIs that subscribe to signals:
createEffect: watch for state updates without affecting the React lifecyclebatch: batch signal updatesSynchronous reactivity is Cerberus' default reactivity mode, where a system responds to changes in a direct and linear fashion. When a signal changes, any corresponding subscribers are immediately updated in an ordered manner.
With synchronous reactivity, the system is able to respond to changes in a predictable manner. This is useful in scenarios where the order of updates is important. For example, if a subscriber depends on another signal, it is important that the subscriber is updated after the signal it depends on.
In this example, the double signal will always be updated after count due to
synchronous reactivity. This ensures that double is always up-to-date with the
latest value of count.
0
0