Replies: 2 comments 3 replies
-
inspiration and feedback
The custom comparator will allow users to have custom comparators that works with JS Date objects |
Beta Was this translation helpful? Give feedback.
-
Thanks for the proposal and the discussion on Discord. I have no knowledge about the internals of Solid, but I here is what I can imagine as an ultimate DX.
I mean just a wild idea, but one can dream! This would be a beautiful DX. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
This proposal introduces two approaches for enabling user-defined signal creation and equality checks in
createStore
:Factory-Based Approach → Simple and modular, with minimal changes to SolidJS. The store logic is scoped within a factory, allowing each factory call to have its own dependencies provided by JavaScript scoping. However, dependency inheritance is not preserved, meaning behavior is determined by the setter function's execution path, which is scoped.
Dependency-Attached Approach → Ensures dependencies are inherited across store nodes, preserving behavior even in nested structures. This allows multiple store configurations to coexist, with child nodes inheriting behavior from their parent.
Both solutions aim to give developers finer control over store updates, signal tracking, debugging, and equality checks, while maintaining flexibility in how state updates are handled.
Approach 1: Factory-Based Store Creation (Emphasizing Simplicity & Minimal Changes)
This approach modifies
createStore
using a factory function, allowing users to inject custom signal behavior and equality logic in a straightforward manner.Example: Factory-Based Customization
Key Characteristics
✅ Easy to implement—Requires minimal changes to
createStore
.✅ Encapsulated behavior—Custom signals and equality functions are scoped within the factory-generated store.
✅ Scoped via JavaScript—Each factory call has its own dependencies provided by JS scoping.
✅ Direct control over updates—Developers can define store-specific signal handling easily.
🚫 No dependency inheritance—Each store defines its own behavior, meaning parent-child store relationships do not inherit configurations.
🚫 Behavior is tied to setter function execution paths, which are scoped—Store updates depend on where the setter is applied, rather than inherited globally.
Approach 2: Attaching Dependencies to Store Nodes (Preserving Inheritance & Mixed Configurations)
A more integrated approach involves attaching dependencies directly to store nodes, similar to how
$PROXY
metadata is handled in SolidJS. This ensures dependency inheritance across nested structures and allows mixed store configurations.Example: Dependency-Attached Store Configuration
Key Characteristics
✅ Dependency inheritance is preserved—Each node inherits configuration from its parent, ensuring consistent behavior across nested structures.
✅ Stores with mixed configurations can coexist—Custom behavior applies selectively based on parent dependency attachment. ✅ Signal hooks allow tracking—Users can monitor read/write operations, aiding debugging and performance optimization.
🚫 Requires deeper integration—Dependencies must propagate correctly across store nodes.
🚫 Behavior is inherited, meaning developers need to track how dependencies flow between store layers.
Proof of Concept
Approach 1 - is simply taking the store implementation wrap it in the factory function
and replace dependencies that are passed as arguments to the factory function.
Approach 2 ( Inherited Dependencies ) with store implementation adaptations
most of the changes is propagating the dependencies and make them accessible in the path that they are needed.
Playground Link ( Approach 2 )
Beta Was this translation helpful? Give feedback.
All reactions