Replies: 1 comment 3 replies
-
Note that it is correct these things are side effects, but you don't have to necessary run side effects as autorun/ observe, you might also run them as part of the action that triggers them directly, e.g. when the user changes the pitch, you could both update the state and trigger the effect. Also not that both autorun and observe return a function that can be used to stop them. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a React app that utilizes WebGL and AudioContext very heavily, and as such, my React app has lots of sideffects.
I understand sideeffects are discouraged but Web GL and AudioContext are not stateless environments like React App; they're much more traditional stateful OOP environments (BabylonJS and Tone)
Accepting this requirement; its common that I need mutations in my Mobx state to be reflected in my 3d/audio state.
A simplified example might be a
Song
with manyTrack
's with manyNotes
:When I add a new track, I want to start binding to the notes array of the track and bridge any new notes to the
AudioEngine
(not react). And when I modify an existing note's velocity, I want to immediately update the audio playback.In the above, I end up having tons of lifecycle changes to keep track of (add/remove/update) and also lots of cleanup to do.
Alternatives I've considered are
.forEach
calls but this creates tons of extra refreshesonAdded, onRemoved
onUpdated
styles of callbacks and cleanupactions
. Challenges: injecting all the required state may become burdensome and break weak coupling.Thoughts? Familiar pattern?
Beta Was this translation helpful? Give feedback.
All reactions