lume / classy-solid

Solid.js reactivity patterns for classes, and class components. See https://github.com/lume/element for a Custom Element system built with classy-solid.
MIT License
57 stars 2 forks source link

TypeError: this.__propsSetAtLeastOnce__.add is not a function #6

Closed MartinTale closed 1 year ago

MartinTale commented 1 year ago

Trying to create a signalified object using below code.

export type GameState = {
    count: number;
};

export let state: GameState = {
    count: 0,
};

signalify<GameState>(state);

Then, in component I import state and increment/display it

setInterval(() => {
    state.count = Math.floor(Math.random() * 100);
}, 1000);

return <strong>{state.count}</strong>

It then results in the error below

TypeError: this.__propsSetAtLeastOnce__.add is not a function
MartinTale commented 1 year ago

Issue wasn't related to solid nor classy-solid (kinda). I used JSON.stringify(state) which included __propsSetAtLeastOnce__ so when I called JSON.parse(stringifiedState) it broke things.

My solution was to omit that property when calling JSON.stringify(state) as below.

JSON.stringify(state, (key, value) => {
    if (key === '__propsSetAtLeastOnce__') {
        return undefined
    }

    return value;
});