Is there a store-like type of memo? If not, what's a better workaround? #2101
-
Say there is a store named My goal is to create a memo which has a discrete version of the position such as the following: function normaliseAxis(axis: number): number {
return Math.ceil(axis / 100);
}
const normalisedPosition = createMemo(() => ({
x: normaliseAxis(mousePosition.x),
y: normaliseAxis(mousePosition.y)
})); Here, the memo makes all of its downstream objects react on every Question 1Is there a Question 2If there is no such structure as asked above, which of the following work-arounds would be a better choice and why? Choice 1const normalisedPositionX = createMemo(() => normaliseAxis(mousePosition.x));
const normalisedPositionY = createMemo(() => normaliseAxis(mousePosition.y)); Choice 2const normalisedPosition = createMemo(
(previousPosition) => {
const newPosition = {
x: normaliseAxis(mousePosition.x),
y: normaliseAxis(mousePosition.y)
};
if (newPosition.x === previousPosition.x && newPosition.y === previousPosition.y)
return previousPosition;
return newPosition;
},
{x: 0, y: 0}
); Here is a playground link illustrating the question: https://playground.solidjs.com/anonymous/a847c828-eab8-4ccb-a9af-789afdf45f18 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There is https://solid-primitives.netlify.app/package/static-store that is only reactive on one level and does not handle adding or removing properties. However, you can also just use multiple signals and put the accessors in an object or tuple. |
Beta Was this translation helpful? Give feedback.
There is https://solid-primitives.netlify.app/package/static-store that is only reactive on one level and does not handle adding or removing properties.
However, you can also just use multiple signals and put the accessors in an object or tuple.