An enhancer is a function that takes an object as an argument and returns a new object, which is an enhanced version of the original object.
Enhancers can be used to modify the properties of an object, add new properties, remove properties, or do other things. They offer a flexible way for users to extend functionalities without changing the existing code.
A simple example of an enhancer:
Reactive is designed to be framework-agnostic, and to adapt to a variety of functional scenarios, Reactive introduces the concept of enhancers. The internal differences in functionality between Vanilla and React are actually implemented by applying different enhancers.
For convenience and alignment with the original API, Reactive has built-in some enhancers and also provides some enhancer APIs, allowing users to enhance the functionality of stores. If needed, users can also write their own enhancers to expand the functionality of their stores.
VanillaStore is the initial form of the store returned by Reactive. It is a simple object containing mutate
and restore
methods, which include only the most basic functionalities and no enhancers.
The create
method is suitable for React and includes some built-in enhancers, such as:
subscribe
methoduseSubscribe
Hooksnapshot
methoduseSnapshot
HookThe createVanilla
method is suitable for Vanilla JavaScript and includes some built-in enhancers, such as:
subscribe
methodsnapshot
methodIn Vanilla scenarios, if you need to use internal enhancers, you should import them from /vanilla
.