Giter VIP home page Giter VIP logo

fable.elmish.nile's Introduction

Fable.Elmish.Nile

Nuget

Extension to Fable.Elmish that enables transforming the stream of dispatched messages from the view to messages that are dispatched to the update function.

It's an alternative approach to Fable.Elmish.Streams. However Fable.Elmish.Streams has some nice helpers that you might want to use with Fable.Elmish.Nile.

Sample usage:

open Fable.Elmish.Nile

let stream states msgs =
    [
        // Let `Increment` messages flow through.
        // Note that messages are swallowed by default, you have to explicitely let them flow through.
        msgs
        |> AsyncRx.choose (function | Increment as x -> Some x | _ -> None)

        // Debounce `Search` messages for 500 ms
        msgs
        |> AsyncRx.choose (function | Search as x -> Some x | _ -> None)
        |> AsyncRx.debounce 500
    ]
    |> AsyncRx.mergeSeq // Merge all streams together (this is where "Nile" comes from)

Program.mkSimple init update view
|> Program.withStream stream
|> Program.run

Sub streams are also possible:

open Fable.Elmish.Nile

let stream states msgs =
    [
        // Top-level message
        msgs
        |> AsyncRx.choose (function | ActivateTab _ as x -> Some x | _ -> None)

        // Forward model and message stream to sub component and map the resulting messages back to top-level messages
        (
            states |> AsyncRx.map (snd >> fun m -> m.SubComponent1Model),
            msgs |> AsyncRx.choose (function SubComponent1Msg msg -> Some msg | _ -> None)
        )
        ||> SubComponent1.stream
        |> AsyncRx.map SubComponent1Msg

        // The pattern for sub components is always the same
        (
            states |> AsyncRx.map (snd >> fun m -> m.SubComponent2Model),
            msgs |> AsyncRx.choose (function SubComponent2Msg msg -> Some msg | _ -> None)
        )
        ||> SubComponent2.stream
        |> AsyncRx.map SubComponent2Msg
    ]
    |> AsyncRx.mergeSeq // Merge all streams together (this is where "Nile" comes from)

Program.mkSimple init update view
|> Program.withStream stream
|> Program.run

fable.elmish.nile's People

Contributors

johannesegger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.