-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Component: Ideas to Try Out #5262
Comments
Closed
Dumping some personal notes here, towards (potentially-distributed) MVU apps module Darklang =
// TODO: I'm not sure where this would best belong
module ModelViewUpdate =
module Cli =
type App<'Model, 'Msg> =
{ init: 'Model
update: ('Model, 'Msg) -> 'Model
view: 'Model -> String
clearBeforeView: Bool
readAndParseNextMsg: Unit -> Result<'Msg, String> }
let loop (app: App<'Model, 'Msg>) (model: 'Model): Unit =
if app.clearBeforeView then Console.Clear()
printfn "%s" (app.view model)
match app.readAndParseNextMsg () with
| Ok msg ->
let updatedModel = app.update model msg
loop app updatedModel
| Error errMsg ->
printfn "Error reading or parsing message: %s" errMsg
loop app model
let runApp (app: App<'Model, 'Msg>): Unit =
loop app app.init
type Model = { counter: Int }
type Msg =
| Increment
| Decrement
let update (state: Model) (msg: Msg) : Model =
match msg with
| Increment -> Model { counter = state.counter + 1 }
| Decrement -> Model { counter = state.counter - 1 }
let view (state: Model) : String =
$"Count: {state.counter}\ntype 'i' or 'd' to continue"
let readAndParseNextMsg () : Result<Msg, String> =
// reads from console or something
let line = Builtin.Stdin.readLine ()
match line with
| "i" -> PACKAGE.Darklang.Stdlib.Result.Result.Ok Msg.Increment
| "d" -> PACKAGE.Darklang.Stdlib.Result.Result.Ok Ok Msg.Decrement
| other -> PACKAGE.Darklang.Stdlib.Result.Result.Error other
let app =
PACKAGE.Darklang.ModelViewUpdate.Cli.App
{ init = Model { counter = 0 }
update = (fun (state, msg) -> update state msg)
view = view
clearBeforeView = false
readAndParseNextMsg = readAndParseNextMsg }
runApp app
dark run x
runs Cli app named x
type CliAppHandler =
type SimpleCliApp =
{ name: String
init: 'State
handleInput: 'State -> String -> 'State
render: 'State -> String }
type CliApp =
/// REPL-y - no fancy UI
| Simple<'State> of SimpleCliApp<'State>
//| Elmish<'State, 'Msg>
// of name: String
// * init: 'State
// * handleInput: 'State
// * render: 'State -> String
// package/user constant?
let darkRepl =
CliApp.Simple<Int>
{ name = "simpleCounter"
init = 0
handleInput =
fun acc input ->
match input with
| "increase" -> acc + 1
| "decrease" -> acc - 1
| _ -> acc
render = fun acc -> Int.toString acc }
upon `dark run x`, we try to look up any CliApp constant named `x` |
(Some day) would it be possible to bring back structured editing? Some relevant personal notes:
|
StachuDotNet
added
the
needs-review
I plan on going through each of the issues and clarifying them -- this is to mark remaining issues
label
Feb 14, 2024
This was referenced Feb 16, 2024
StachuDotNet
removed
the
needs-review
I plan on going through each of the issues and clarifying them -- this is to mark remaining issues
label
Feb 19, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Issue is a grab-bag dumping ground for a bunch of Dark ideas that we'd like to not forget about, but aren't high enough priority to seriously consider yet. If users submit Issues that seem really interesting but would fill up GitHub Issues, we might link them here, close the issue, and reopen it once we're able to tackle it.
jq
, in darktype Error = CouldNotNavigate of pathSoFar: List<JsonPath> * failureAt: JsonPath.Part
let navigate (json: Json) (path: JsonPath): Result<Json, Error> = ...
json |> Json.Nav.accessField "fieldName" |> Json.Nav.accessIndex 4
The text was updated successfully, but these errors were encountered: