You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In our app, the user can initiate a confetti-like operation where multiple independent copies of some simple stateless view appear on the screen for some time and then disappear on their own. The view isn't exactly stateless but its state is set at initialisation time and is immutable, containing only a unique ID and how long the view is supposed to stay on screen before it disappears, as different instances of the view stay on the screen for different amounts of time. In other words, the view sends an animationStarted action when it appears and sends no other action.
The view state has 3 actions:
publicenumAction:Equatable{case animationStarted
case animationFinished
case timerTicked
}
The reducer associated with this view takes care of starting a timer when animationStarted is fired (on view appearing, as stated) and firing an animationFinished action when the time is up for the instance.
Somewhere higher in the view hierarchy, the scene supposed to manage these confetti-like views has a state that maintains a dictionary mapping instance IDs to their corresponding view state instances. Every time the user fires a new instance of these confetti-like views, a new view state instance is created (with a unique ID) and added to this dictionary, the idea being that when the instance's reducer fires its animationFinished action, the instance in question is removed from the dictionary, triggering a redraw that now does not contain the instance just removed.
My problem is two-fold:
Since I have a dictionary, ie, a collection, of view states, how do I manage the corresponding collection of associated reducers?
How can I make sure that a redraw triggered by the removal of a view state instance from the collection doesn't affect all the other instances already visible on screen? These confetti-like instances are moving on screen and I don't want the removal of one to trigger all the others to be redrawn from their starting position on screen.
So, in essence, what's the best way to model this scenario?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello 😄
In our app, the user can initiate a confetti-like operation where multiple independent copies of some simple stateless view appear on the screen for some time and then disappear on their own. The view isn't exactly stateless but its state is set at initialisation time and is immutable, containing only a unique ID and how long the view is supposed to stay on screen before it disappears, as different instances of the view stay on the screen for different amounts of time. In other words, the view sends an
animationStarted
action when it appears and sends no other action.The view state has 3 actions:
The reducer associated with this view takes care of starting a timer when
animationStarted
is fired (on view appearing, as stated) and firing ananimationFinished
action when the time is up for the instance.Somewhere higher in the view hierarchy, the scene supposed to manage these confetti-like views has a state that maintains a dictionary mapping instance IDs to their corresponding view state instances. Every time the user fires a new instance of these confetti-like views, a new view state instance is created (with a unique ID) and added to this dictionary, the idea being that when the instance's reducer fires its
animationFinished
action, the instance in question is removed from the dictionary, triggering a redraw that now does not contain the instance just removed.My problem is two-fold:
So, in essence, what's the best way to model this scenario?
Many thanks in advance!
Ahh... I guess the answer to 1. is to use the
forEach
version of a reducer pullback. Ok, still, how do I deal with 2. ?Beta Was this translation helpful? Give feedback.
All reactions