What do I do if I have to wait for things to happen, meanwhile define extra state or what
this piece of code come up as crucial functionality all over the place for me, for an interactive application of solidjs
So I set something, and wait for user to acknowledge it, then I go to next state.
While I am waiting some kind of pending state happening.
Do I keep track of these waiting states, because I have some timing related bugs creeping in my code I don't know how to fix. Not considering waiting for some asynchronous processes on the way.
9 Replies
What does waiting for the user to acknowledge it look like? Is it a button they have to press?
No just mentally give it a time. Like a chess app, they make a move, I give them a second to see the move on the board. Then I take back the move, because they have to make another move on the previous position.
You could use resource to take care of the tracking for you?
Everytime
uci
changes waiting
will set its pending state to pending
for 1000ms.
With anything async, resource is probably the answer.
because I have some timing related bugs creeping in my code I don't know how to fixWhat kind of bugs are you facing?
in these pending states i make the board not movable, but sometimes when i click buttons to get a fresh new state, board is still not movable, it happens rarely though, can't reproduce.
about using the resource maybe I want to cancel the timeout how do I handle, that maybe some good abstraction comes out of this.
you could pass a delta to timeout: https://playground.solidjs.com/anonymous/ee800b38-8f26-4f79-9047-239016f0bf4a
using resource only as a pending-state setter is probably not completely using the full potential of that api. most likely you could move a lot of logic into
createResource
as wellI don't understand how is that clear the timeout with clearTimeout, instead setTimeout(resource, 0) will trigger the timeout immediately
a i see, you want to be pending forever
i don't really know all the logic you want to implement, but as my example shows, you can use signals as ways to trigger resources.
ok ok thank you
ur welcome!