Hey folks,

I've hit a dead-end trying to integrate Elm 0.17 with Firebase. (This isn't 
actually a Firebase-specific problem, but it's my concrete example.)

Firebase has a feature where you can subscribe to changes at a particular 
database path. So I can subscribe to "/votes", and any new votes made by 
other people will be pushed to my client. You can also unsubscribe at any 
time.

I started doing this with a port. Subscribing to a path works as neatly as 
you might hope. It's unsubscribing that gets hairy. I have this code:

port listenForVotes : (List Vote -> msg) -> Sub msg

subscriptions : Model -> Sub Msg
subscriptions model =
    if model.authenticated then
        listenForVotes NewVotes
    else
        Sub.none

Once we're authenticated, it triggers code on the other side of the port to 
start listening to that path. But if we log out, we just ignore them. No 
new message is sent to the Firebase API to say, "Stop listening." That's 
the problem I want to solve.


This seems to me like something effect managers were built for - tracking 
which subscriptions are live and dealing with their appearance & 
disappearance. So I started writing one of those.

And technically it seems like the right solution. It's shaping up well. But 
practically I can see it's going to fail. If I write an effect manager, the 
native part of the code will be tied to the name of the project that uses 
it. I can't reuse my effect manager across projects, even privately. As far 
as I can tell, the only way to make an effect manager reusable is to get it 
published to packages.elm-lang.org. And I'm deeply pessimistic about that 
ever being approved.

Can anyone see a way forward?

Cheers,
Kris

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to