Last active
August 8, 2018 18:08
-
-
Save grishace/a29bbfe82bb9395d082cb0233a9d93ad to your computer and use it in GitHub Desktop.
Moving to Fable 2
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
// Client project | |
// This piece of code follows the pattern from SAFE-Dojo for loading data from API endpoints | |
open Thoth.Json | |
type Dto = int list | |
let dtoDecoder = Decode.Auto.generateDecoder<Dto> () | |
let init () = | |
let initialModel = Model.Empty | |
let withException = function | |
| Ok x -> (match x with Ok res -> Ok res | Error str -> Error(exn str)) | |
| Error ex -> Error ex | |
let loadDto = | |
Cmd.ofPromise | |
(tryFetchAs "/api/dto" dtoDecoder) | |
[] | |
(Ok >> withException >> DtoLoaded) | |
(Error >> DtoLoaded) | |
initialModel, loadDto |
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
// my folders' structure is not just simple Client/Server/Shared, but with another projects at the upper level, | |
// so when the build is started in the topmost folder it was failing to run `dotnet fable webpack` command because | |
// the webpack configuration could not be found, and then `webpack-dev-server` could not find the content folder... | |
let fableWebpack' fwp opt clientPath = | |
let webpackProd = | |
match opt with | |
| Some "Release" -> "production" | |
| _ -> "development" | |
sprintf "fable %s -- --config \"%s/webpack.config.js\" --mode %s --context \"%s\"" | |
fwp clientPath webpackProd clientPath | |
let fableWebpack = fableWebpack' "webpack" | |
let fableWebpackServer = fableWebpack' "webpack-dev-server" |
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
// Server project | |
// Fable 2 serialization choice | |
open Thoth.Json.Giraffe | |
/// application { service_config config } | |
let config (s: IServiceCollection) = s.AddSingleton<IJsonSerializer>(ThothSerializer()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment