-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Rework default Server.fs - move to a module #465
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,38 +6,32 @@ open Saturn | |
|
||
open Shared | ||
|
||
type Storage() = | ||
let todos = ResizeArray<_>() | ||
|
||
member __.GetTodos() = List.ofSeq todos | ||
|
||
member __.AddTodo(todo: Todo) = | ||
module Storage = | ||
let todos = ResizeArray () | ||
let addTodo (todo: Todo) = | ||
if Todo.isValid todo.Description then | ||
todos.Add todo | ||
Ok() | ||
else | ||
Error "Invalid todo" | ||
|
||
let storage = Storage() | ||
|
||
storage.AddTodo(Todo.create "Create new SAFE project") | ||
|> ignore | ||
|
||
storage.AddTodo(Todo.create "Write your app") | ||
|> ignore | ||
|
||
storage.AddTodo(Todo.create "Ship it !!!") | ||
|> ignore | ||
do | ||
addTodo (Todo.create "Create new SAFE project") |> ignore | ||
addTodo (Todo.create "Write your app") |> ignore | ||
addTodo (Todo.create "Ship it !!!") |> ignore | ||
|
||
let todosApi = | ||
{ getTodos = fun () -> async { return storage.GetTodos() } | ||
addTodo = | ||
fun todo -> | ||
async { | ||
match storage.AddTodo todo with | ||
| Ok () -> return todo | ||
| Error e -> return failwith e | ||
} } | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this fantomas formatting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not. |
||
getTodos = fun () -> async { | ||
return Storage.todos |> List.ofSeq | ||
} | ||
addTodo = fun todo -> async { | ||
return | ||
match Storage.addTodo todo with | ||
| Ok () -> todo | ||
| Error e -> failwith e | ||
} | ||
} | ||
|
||
let webApp = | ||
Remoting.createApi () | ||
|
@@ -54,4 +48,4 @@ let app = | |
use_gzip | ||
} | ||
|
||
run app | ||
run app |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks more succinct and maybe even more idiomatic. I'm not convinced though - prefer to use explicit class/object notation when dealing with internal state. Probably a matter of preference though - curious what other think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@theimowski in absence of any feedback (happy for you to loop in some people explicitly) - I would suggest we go with this one and add a recipe for the class-based (with DI) approach.