Skip to content

[WIP] Adding Elmish.Bridge as a communication option (counter version)#267

Merged
theimowski merged 7 commits intoSAFE-Stack:masterfrom
Nhowka:bridgelight
Jun 6, 2019
Merged

[WIP] Adding Elmish.Bridge as a communication option (counter version)#267
theimowski merged 7 commits intoSAFE-Stack:masterfrom
Nhowka:bridgelight

Conversation

@Nhowka
Copy link
Copy Markdown

@Nhowka Nhowka commented May 27, 2019

Alternative to #265. Makes the counter server-side with a fallback function so the client can work even when the server disconnects.

Changes made mainly to the elmish part of it.

@theimowski
Copy link
Copy Markdown
Member

Yeah I think I prefer this lighter option rather than #265
@Zaid-Ajaj wanna help reviewing?

"description": "add Fable.Remoting (https://zaid-ajaj.github.io/Fable.Remoting/) to server and client"
},
{
"choice": "bridge",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add it to Tests as in previous PR

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, sent it on a limited internet connection and has kinda of hurried.

Comment thread Content/src/Client/Client.fs Outdated
|> Remoting.buildProxy<ICounterApi>
#endif
let initialCounter = Server.api.initialCounter
#elseif (bridge)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is preventing the else branch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, let's change the else branch to elseif (!bridge) instead - those empty lines are misleading

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution! Will do

Comment thread Content/src/Client/Client.fs Outdated
let loadCountCmd =
#endif
#if (!reaction && remoting)
#if (!reaction && remoting && !bridge)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those 3 conditions got bit complex, can we refactor those to make it cleaner? Maybe use nested #if statements?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give it a try

Comment thread Content/src/Client/Client.fs Outdated
let nextModel = { Counter = Some initialCount }
nextModel, Cmd.none

#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to add your credits to safeComponents !

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops 😅

Comment thread Content/src/Server/ServerGiraffe.fs Outdated
|> Remoting.buildHttpHandler

#else
let getInitCounter () : Task<Counter> = task { return { Value = 42 } }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's inline getInitCounter both for remoting and the default option - we no longer need it to be a separate function

Comment thread Content/src/Server/ServerSaturn.fs Outdated
|> Remoting.buildHttpHandler

#else
let getInitCounter() : Task<Counter> = task { return { Value = 42 } }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above - inline

Comment thread build.fsx Outdated
type Communication =
| Remoting
| Bridge
| NoCommunication
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use option type and None for default

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, another example of how taking less time thinking creates overly complex things. That will even help on the other steps, good catch

@theimowski
Copy link
Copy Markdown
Member

Added couple comments

@Nhowka
Copy link
Copy Markdown
Author

Nhowka commented May 28, 2019

I was taken by surprise and got moved from workplaces where I don't have internet access yet. But I'll try to send commits using my phone as soon as possible.

@theimowski
Copy link
Copy Markdown
Member

Take your time, no need to hurry :)

Copy link
Copy Markdown
Contributor

@Zaid-Ajaj Zaid-Ajaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bridge.Send should use proper Cmds when using reaction && bridge

Comment thread Content/src/Client/Client.fs Outdated
match currentModel.Counter, msg with
| Some counter, Increment ->
#if (bridge)
Bridge.Send (ServerMsg.Increment)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combination of reaction && bridge are using the side-effects directly instead of proper commands using Cmd.bridgeSendOr

@Nhowka
Copy link
Copy Markdown
Author

Nhowka commented May 29, 2019

Feels ready... Any pointers on what can be better?

@theimowski
Copy link
Copy Markdown
Member

theimowski commented May 30, 2019

I'll get back to this next week

Comment thread Content/src/Client/Client.fs Outdated
#endif

#if (reaction)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those will result in many empty lines in generated project, let's try to minimise them

Comment thread Content/src/Server/ServerGiraffe.fs Outdated
/// Elmish init function with a channel for sending client messages
/// Returns a new state and commands
let init clientDispatch () =
let value = {Value = 42}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting: let's keep a single space at beginning and end of record construction { Value = 42 } - this comment applies to other places as well

Comment thread build.fsx

type CombinedPaketDependencies =
{ Azure : bool
Remoting : bool
Communication : Communication option
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried running UpdatePaketLockFiles after this change? We need to make sure it still works

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I did, I had to change some lines so the files that weren't created wouldn't fail the build target, then I reverted after creating everything and updated the files.

@theimowski
Copy link
Copy Markdown
Member

This is looking good now 👍 Added couple minor comments
Can you also add some docs to the other repository?

@Nhowka
Copy link
Copy Markdown
Author

Nhowka commented Jun 4, 2019

Sure! I'll fix the points raised. I hope I can write a full guide soon using the template as starting point.

@theimowski theimowski merged commit 23c6cbd into SAFE-Stack:master Jun 6, 2019
@theimowski
Copy link
Copy Markdown
Member

Thank you very much for this! Released in v1.8

On a side note, as per this issue from now on we will strive to simplify the template, so we'll need to discuss every new feature before adding it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants