I have a State that I want to update every Step.
One can step forward, backward, or "play" which just does those every a certain amount of ms.
Therefore I had 3 appraoches
- Make a
stepForwardandstepBackwardmethods that logically manipulate theStateeach time they're called properly
- I tried that initially, and while it works, it can often be really annoying, some of those represent array sorting algorithms. Therefore, it's SO MUCH more elegant to just write the actual sort method as it is and record various
States than somehow make a weird version of it that makes 1 mutation every time it is called.
- Save a list of
States and just pick the one with the current index
- I didn't even try it. This will be the EASIEST of the bunch by far, however it could get very memory intensive. Imagine a
BubbleSortwith an array of length 30, you could potentially reach 900 steps, each containing a 30 long array(and even more data but you get my point)... Ik it's not the end of the world in this specific example but my point is it's really bad memory wise
- A "Delta" system that only records changes rather than the entire array
- So... I did do that. I made a generic, type-safe and dare I say robust Delta system... problem is it lacks in many fields... I struggled to make a type-safe way to modify nested objects/arrays, I struggled to deal with removal of elements from an array (and having the step backward un-do them) etc, and my specific system really started showing it wasn't up for the task...
I still believe a form of "Delta" system is the BEST appraoch for this method, but maybe there's just something I'm not thinking about...
My question is:
How would you handle the situation I am in rn? Do you have better solutions in mind?
(Btw you can write examples in whatever language I'll write it in TypeScript myself later, also if anyone needs extra context like code snippets or whatnot lmk I'll send, tho I think I covered quite a bit of context)