-
-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it ok to store sink inside the model? #750
Comments
This isn't a bad idea per se. There really isn't a good way (that I see yet) to expose the global sink to users outside of the One alternative (so you can keep the model pure) is to do the globalSinkRef :: IORef (Sink Action)
{-# NOINLINE globalSinkRef #-}
globalSinkRef = unsafePerformIO $ newIORef (\_ -> pure ())
update InitGlobalSink m =
effectSub m $ \sink ->
m <# liftIO (writeIORef globalSinkRef sink) Then you can just do Lastly, TBH, we could add this to the library and users could make use of it exactly for circumstances like this. |
Thanks @dmjio ! |
Yea let me know how it works out for you |
I need to emit action on some async events like loading files from input component:
https://github.com/functora/functora.github.io/blob/4ca33c655deea34117e27b5feb2a03f13c432c96/ghcjs/miso-functora/src/Functora/Miso/Widgets/Field.hs#L344-L350
Because my input component is basically just a view, I need to make two things - create main application miso action, and emit async event which should land on update function of the main miso application. I'm using two corresponding arguments of my input component to do so:
https://github.com/functora/functora.github.io/blob/4ca33c655deea34117e27b5feb2a03f13c432c96/ghcjs/miso-functora/src/Functora/Miso/Widgets/Field.hs#L35-L36
Providing action argument is easy - basically it's just a mapping to main miso application action type. Providing emitter argument is a bit less straightforward, because my input component is basically a view, so all argument I'm providing I should get somehow from the model, because I don't have direct access to main miso app update function, effectSub and sink.
The workaround I'm using at the moment is to save MVar with the sink to the model on the initial main miso app update, so I can have access to it from my input component:
https://github.com/functora/functora.github.io/blob/4ca33c655deea34117e27b5feb2a03f13c432c96/ghcjs/delivery-calculator/src/Main.hs#L124-L125
Is it ok to do so, or there are better ways to emit async actions from components similar to my input component? Best regards!
The text was updated successfully, but these errors were encountered: