Skip to content
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

Update remoting to latest, docs for client #118

Merged
merged 7 commits into from
Jul 20, 2018
Merged

Update remoting to latest, docs for client #118

merged 7 commits into from
Jul 20, 2018

Conversation

Zaid-Ajaj
Copy link
Contributor

This PR updates remoting to latest version and api, I also took the liberty and updated a couple of things along the way, PLEASE REVIEW (I haven't tested every possible combination):

Client

Added docs to model, msg, init and update

type Model = Counter option became type Model = { Counter: Counter option }

The messages now became:

type Msg =
| Increment
| Decrement
| LoadInitialCount 
| InitialCountLoaded of Result<Counter, exn>

where LoadInitialCount is a message the initiates the request and InitialCountLoaded is the one that results from the (http) request, and init() becomes:

// defines the initial state and initial command (= side-effect) of the application
let init () : Model * Cmd<Msg> =
    let initialModel = { Counter = None }
    let initialCmd = Cmd.ofMsg LoadInitialCount
    initialModel, initialCmd

Saturn

use_router instead of router as per the depreciation message
disable_diagnostics doesn't seem necessary anymore with remoting enabled (probably because the routing with remoting doesn't rely on existing combinators any more)

Suave

opening Suave.Filters and Suave.Successful instead of fully qualifying them with the OK and path web parts (it is common that they are fully qualified?)

build.fsx

DotNet.Release_2_1_300 => DotNet.Versions.Release_2_1_300 as per the depreciation message
Run target is Clean-ed before running

@Zaid-Ajaj
Copy link
Contributor Author

Tested working combinations:

  • dotnet new SAFE
  • dotnet new SAFE --remoting
  • dotnet new SAFE --server suave --remoting
  • dotnet new SAFE --server suave

Testing thse combinations is very cumbersome and time-consuming: found a bug? then

  • Update template
  • Rebuild
  • Uninstall => install from built nuget package
  • Delete old project
  • scaffold a new project
  • build created project (& resolve deps from scratch, etc.)
  • try again 😓

Any effort to automate this would be highly appreciated

@isaacabraham
Copy link
Member

@Zaid-Ajaj indeed, I had the same thoughts. I'm not sure how easy it would be to automate, but yes. Could you create an issue for it?

@isaacabraham
Copy link
Member

@Zaid-Ajaj there are a few shortcuts around this, however. For example, you can install a template "over the top" of an existing folder, and it usually works fine. This removes the need to do the yarn download etc. etc. Also, did you test out giraffe?

@Zaid-Ajaj
Copy link
Contributor Author

Could you create an issue for it?

Yeah, sure

there are a few shortcuts around this, however. For example, you can install a template "over the top" of an existing folder, and it usually works fine

I will try it out

Also, did you test out giraffe?

No, not yet, will do sometime today :)

@Krzysztof-Cieslak
Copy link
Member

Krzysztof-Cieslak commented Jul 16, 2018

disable_diagnostics doesn't seem necessary anymore with remoting enabled

I've fixed that in latest - site.map generation doesn't crash anymore if it hasn't detected any routes.

@theimowski
Copy link
Member

theimowski commented Jul 16, 2018

@Zaid-Ajaj see ad8bcbe - I've added a FAKE target to help with the test workflow.
Not very much, but now you can fake build -t install and have the updated template already available in dotnet

Also, I agree that testing the template is kinda cumbersome.
I'm open to any suggestions to improve the experience.
Automated tests would be very welcome

@Zaid-Ajaj
Copy link
Contributor Author

Zaid-Ajaj commented Jul 16, 2018

@theimowski Thank you! I will test it out next time 😄

I have now tested giraffe with and without remoting and it seems to work (On My Machine™), I am working on windows 10 with dotnet 2.1.300

I came across another issue: I am noticing global.json is magically coming into existence and disappearing on it's own after I execute the Run for the second time in a different directory, having the effect of the Run target not running the server and I get:

(The process cannot access the file 'C:\projects\safe-giraffe\no-remoting\global.json' because it is being used by another process.)

only after I exit the process. This seems due to this block:

let install = lazy DotNet.install DotNet.Versions.Release_2_1_300

let inline withWorkDir wd =
    DotNet.Options.lift install.Value
    >> DotNet.Options.withWorkingDirectory wd

my workaround is to replace runDotNet with runTool "dotnet" cmd workingDir

@theimowski
Copy link
Member

I'm considering removing the DotNet.install alltogether - we have .NET SDK 2.1 in the prerequisites anyway

Relates to #79

@Zaid-Ajaj
Copy link
Contributor Author

This can be merged, if I missed something, just let know :)

@theimowski
Copy link
Member

Actually there are 2 things (posted comments in code diff):

  1. How about float pinning the Fable.Remoting dependencies?
    e.g. nuget Fable.Remoting.Suave ~> 3 to prevent future breaking changes?
  2. I'm not convinced with adding one more Msg case - IMO it makes the update function more complex than it needs to be

I'm fine with rest of changes

@Zaid-Ajaj
Copy link
Contributor Author

How about float pinning the Fable.Remoting dependencies?

That shouldn't be needed anymore when pulling lastest packages (also, I will try to publish one library with it's dependencies in one package)

I'm not convinced with adding one more Msg case - IMO it makes the update function more complex than it needs to be

In the context of this simple counter app, I agree with you.

The reasoning behind this is for larger apps: usually a component doesn't ask for it's data when initialized at application startup, but when loaded or navigated to from other components where you will explicitly need to dispatch a message to initiate the request (hence the LoadInitialCounter)

I can remove the message for now, but since we are on the subject, I was actually thinking of using a more representative app in the template like a to-do list instead of a counter: it showcases the used frameworks much better with a CRUD scenario while still being very simple to follow and understand

What do you think? @isaacabraham @Krzysztof-Cieslak

@theimowski
Copy link
Member

I'm happy to discuss the idea or more representative app, but let's make it a separate issue

@isaacabraham
Copy link
Member

isaacabraham commented Jul 18, 2018

I'm definitely of the view that the template should be as simple as possible in terms of code. I really don't want to see it include CRUD stuff that is opinionated in any way or might not be applicable - we want the template to be useful for any SAFE app really.

I'd say there's a good case to be made for creating such an example app to include in the SAFE github area like the bookstore etc

@Zaid-Ajaj
Copy link
Contributor Author

I see, then we will keep it simple 😄

@@ -15,11 +15,9 @@ group Server
//#if (!remoting && server != "suave")
nuget Fable.JsonConverter
//#elseif (remoting && server == "suave")
nuget Fable.Remoting.Server ~> 3.6
nuget Fable.Remoting.Suave ~> 2.7
nuget Fable.Remoting.Suave
Copy link
Member

Choose a reason for hiding this comment

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

Shall we float pin to a major version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but it is not necessary afaik

type Msg =
| Increment
| Decrement
| Init of Result<Counter, exn>
| LoadInitialCount
Copy link
Member

Choose a reason for hiding this comment

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

Not sure about this change, it's just additional step and IMO makes things more complex

// The update function computes the next state of the application based on the current state and the incoming events/messages
// It can also run side-effects (encoded as commands) like calling the server via Http.
// these commands in turn, can dispatch messages to which the update function will react.
let update (msg : Msg) (currentModel : Model) : Model * Cmd<Msg> =
Copy link
Member

Choose a reason for hiding this comment

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

I think I prefer the shorter 6-line version
I'll merge it but revert this change afterrwards

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, it was just my personal preference to do it this way 👌

@theimowski theimowski merged commit 82f4d98 into SAFE-Stack:master Jul 20, 2018
@theimowski
Copy link
Member

Also for future, please install https://editorconfig.org/ - we use it in SAFE template to handle white spaces in a consistent shape

@Zaid-Ajaj
Copy link
Contributor Author

Also for future, please install https://editorconfig.org/ - we use it in SAFE template to handle white spaces in a consistent shape

Good idea, that's why I always seemed to get the space diffs on my commits

@Zaid-Ajaj Zaid-Ajaj deleted the upgrade-remoting branch July 20, 2018 11:23
theimowski added a commit that referenced this pull request Jul 20, 2018
This reverts commit 82f4d98, reversing
changes made to 21cf12b.
@theimowski
Copy link
Member

Unfortunately I had to revert this PR - sorry, should have tested it before merging.
The default template dotnet new SAFE nor azure dotnet new SAFE --deploy azure don't work - keep in mind for those two we keep the paket.lock files (paket-default.lock and paket-azure.lock)

@Zaid-Ajaj
Copy link
Contributor Author

Hmm before the last change (removing the client msg) the template was working fine...

@theimowski
Copy link
Member

It failed on:

  • build script with change DotNet.Versions (locked Fake.DotNet.Cli didn't have that module
  • saturn application CE - I got compiler error on url with Saturn pinned to 0.5

@theimowski
Copy link
Member

I've rebased the commits now on new master, the changes are released in 0.26 - thanks again for contribution!

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.

4 participants