Automatic view model for solid-js
This package aims to provide reactive objects, is similiar to createMutable()
but with a few differences
- Seamless: It works with classes and, hopefully, any kind of JavaScript object in a completely transparent way
- Customizable: Greater control over the interactions with the proxy
- Scoped: It doesn't automatically apply reactivity to children of reactive objects
The module provides a set of ProxyHandler
s out-of-the-box that can be used to customize the reactive behaviours of objects.
These handlers are available through inheritable classes, since the default ones haven't got any instance field you can use their prototype directly.
Any instance field defined on handlers will be defined on their proxy, especially private fields.
Each handler also provides static methods for introspection, these works on both the raw object and its reactive proxy.
You should use the static methods provided by the handler you're actually using since they could be overridden adding more specific behaviours.
For example:
import { MemoHandler } from "solid-model";
const raw = { /* ... */ };
const reactive = MemoHandler.create(raw);
-
is()
(static): Tells whether the provided object is reactive -
getProxy()
(static): Gets the proxy of a reactive object -
setProxy()
(static): Sets the proxy of a reactive object -
getRaw()
(static): Gets the raw version of a reactive object -
create()
(static): Creates a proxy for an object using the current handler -
detach()
(static): Detaches the proxy from its target
Handler that makes an Atom
under the hood for each field of its target
-
getStore()
(static): Gets the object (Of typeStore
) that contains theAtom
s for each reactive property
It also provides a few custom overridable traps
-
createAtom()
: Method that's responsible for creating theAtom
for each property which hasn't got neither a getter nor a setter -
getComparator()
: Method that creates a comparison function for theSignal
of each newAtom
created by the current handler -
getPropertyTag()
: Method that generates a recognizable name for theSignal
of eachAtom
to help debugging
Handler that provides a general-purpose DisposableOwner
-
getOwner()
(static): Gets theDisposableOwner
that handles the reactive resources of the current object -
createOwner()
: Method that's responsible for creating theDisposableOwner
for each object that usesDisposableHandler
Handler that inherits the behaviours of ReactiveHandler
and memoizes every getter of its target
-
createMemo()
: Method that's responsible for creating theReadOnlyAtom
for each getter property
The module also exposes some of its internal utilities
-
nameOf()
: Utility function that powersAtom.prop()
The type of the output of ReactiveHandler.getStore()
Explicitly disposable version of a "solid-js" Owner
Represents a POSSIBLY read-only reactive state
-
trySet()
: Allows you to try to set the value of aReadOnlyAtom
in the hope that it's actually a normalAtom
-
update()
: Like theSetter
overload of aSignal
that takes a function with the previous value
Customizable and simplified wrappers for reactive states.
- (Everything
ReadOnlyAtom
has) -
memo()
: Creates a newAtom
with the setter of the current one and a memoized version of its getter -
convert()
: Creates a newAtom
that applies a conversion to the current one -
unwrap()
(static): Allows the use of anAccessor
of anAtom
without having to call theAccessor
each time -
from()
(static): Creates anAtom
based on aSignal
-
prop()
(static): Creates anAtom
based on an object property -
source()
(static): Similiar toAtom.unwrap()
, but if theAccessor
doesn't return anything it automatically creates an internalSignal
in which to store the value