Nhowka / Elmish.Bridge

Create client-server Fable-Elmish apps keeping a single mindset
MIT License
139 stars 17 forks source link

Integration with Elmish.Streams on the server side #18

Closed sheganinans closed 1 year ago

sheganinans commented 5 years ago

I have a scenario where I am using the Elmish.Bridge architecture on the frontend with Elmish.Streams. However this breaks the isomorphism, since Elmish.Bridge on the server side uses Cmds by default, while Elmish.Streams does not use Cmds.

You may know, Elmish.Streams modifies the update function, where instead of generating and returning Cmds there. There is a new function stream that is subscribed to Program.mkSimple and what would be done by update with Cmds, is instead done in stream, decoupled from update.

What would be a simple way to use Elmish.Bridge, modified to use Elmish.Streams on the server side?

Nhowka commented 5 years ago

As it is now, Elmish.Streams hook into the view so it can access both the current model and the dispatch function. The server has no view, so I didn't do a similar concept to support the same features.

The bad news is that changes will need to be made. The good news is that they aren't breaking changes.

I'll see what can be done. Can Elmish.Streams work on the server without changes?

sheganinans commented 5 years ago

I'm just gonna link in my other issue, since this is fundamentally related: https://github.com/dbrattli/Elmish.Streams/issues/26

How it's done right now in Elmish.Streams is that uses websockets explicitly, serialization with Thoth.Json hooks into AspNetCore's middlewares: https://github.com/dbrattli/Elmish.Streams/blob/master/AspNetCore.Middleware/StreamsMiddleware.fs

The relevant example is Magic example, which is essentially the Time Files Like An Arrow example, but with toggles for things like local and remote: https://github.com/dbrattli/Elmish.Streams/blob/master/examples/Magic/src/Client/Utils.fs https://github.com/dbrattli/Elmish.Streams/blob/master/examples/Magic/src/Shared/Shared.fs https://github.com/dbrattli/Elmish.Streams/blob/master/examples/Magic/src/Server/Server.fs

I think the simplest way forward would actually be an update of Elmish.Streams.AspNetCore.Middleware, maybe a Elmish.Bridge-aware version.

sheganinans commented 5 years ago

Also, if you don't have the time to do this currently. I'm very motivated right now to get this working. So if you can just get me pointed in the right direction, I'll try to get this working ASAP.

Nhowka commented 5 years ago

Probably just reimplement the setState will give a way to attach the stream with little change.

sheganinans commented 5 years ago

@Nhowka I'm not sure what you mean

Nhowka commented 5 years ago

Sorry, there is that feature on Elmish that gets called after every update and then is used for rendering the view in the case of Elmish.React. As it overrides the setState completely, Elmish.Streams used the view for attaching it to it, but it should be ok with a setState based attachment on the BridgeServer implementation.

sheganinans commented 1 year ago

Closing, since it seems Elmish.Streams is seemingly not actively developed.