createSignal with preexisting data store?

https://playground.solidjs.com/anonymous/5ab699c2-0e36-470c-9aae-a9fa62d15d75 Seems the UI will not update when the data is updated outside of createSignal; how can I add it in my data.tsx file please? The timer (while burning) should update the current state to empty when the fuel runs out to 0. TIA
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
5 Replies
peerreynders
peerreynders3w ago
const [fsmState, setFsmState] = createSignal(machine.state);
// patch trigger on machine
// @ts-expect-error
machine.nativeTrigger = machine.trigger;
machine.trigger = function (event, param) {
// @ts-expect-error
const result = this.nativeTrigger(event, param);
setFsmState(machine.state);
return result;
};
const [buttonNames, setButtonNames] = createSignal(Object.keys(machine.path));
const [fsmState, setFsmState] = createSignal(machine.state);
// patch trigger on machine
// @ts-expect-error
machine.nativeTrigger = machine.trigger;
machine.trigger = function (event, param) {
// @ts-expect-error
const result = this.nativeTrigger(event, param);
setFsmState(machine.state);
return result;
};
const [buttonNames, setButtonNames] = createSignal(Object.keys(machine.path));
Your machine doesn't seem to offer a way to subscribe to state change/transitions. So patching the trigger was the only way that the signal can be updated whenever the machine state (potentially) changes.
tombyrer
tombyrerOP3w ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
peerreynders
peerreynders3w ago
That said if you converted data.tsx to a store and published to most recent machine.state to it as well you could simply use that to drive the UI.
tombyrer
tombyrerOP3w ago
Yea, that was my initial reason to have a separate data.tsx; so the users can use any type of 'store' they want for the framework they're in. Exactly how would I do that in Soild please?
peerreynders
peerreynders3w ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template

Did you find this page helpful?