-
Notifications
You must be signed in to change notification settings - Fork 12
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
Suggestions for Reader integration on top of the effects api #15
Comments
Many people prefer to inject the dependencies explicitly, so another option is using some kind of MTL style. See this PR |
@gcanti thanks for the feedback will try it out |
@gcanti am I right that it doesn't make sense to apply the full mtl-style from fp-ts to elm-ts? So making it to the more generic interface |
Theoretically you need a natural transformation, from toTask: <A>(fa: HKT<M, A>) => Task<A> That's what const saveToNamespace = (M: MonadLocalStorage) => (value: string): Task<void> => fromIO(M.setItem(NAMESPACE, value)) So a generalization would be something along the lines of interface MonadLocalStorage<M> {
URI: M
setItem: (key: string, value: string) => HKT<M, void>
getItem: (key: string) => HKT<M, Option<string>>
}
interface MonadTask<M> {
URI: M
toTask: <A>(fa: HKT<M, A>) => Task<A>
} however in this case it's not worth it as I can't come up with another sensible instance other than interface MonadLocalStorage {
setItem: (key: string, value: string) => IO<void>
getItem: (key: string) => IO<Option<string>>
} |
@gcanti thanks again for your help. |
I would like to make all dependencies that are involed in side effects to be exchangable. It seems that the most common solution for this problem is the usage of a
Reader
(my first time using it).What would be the best way to integrate it in
elm-ts
? I already experiment a little bit with it and this is what I came up with. I needed to write some code around theelm-ts
functions to get it working.I limited the access to the Reader to the commands to prevent the leaking of effectfull dependencies to the rest of the application (view, init and update functions).
I used this code in your
elm-ts-todomvc
example to makelocalStorage
to be exchangable in unit tests or to make the app server side renderable (where no localStorage is avaibale).Would this be something reasonable to integrate in
elm-ts
itself?The text was updated successfully, but these errors were encountered: