Giter Site home page Giter Site logo

bs-hyperapp's Introduction

bs-hyperapp

This library is an opinionated overlay of the Elm Architecture on top of Hyperapp, the tiny UI library. It's driven by the realisation that because of strong static typing in languages like OCaml, it's possible to simplify Hyperapp's actions into just a single update function (a single reducer), and also to simplify a few other things.

Usage

The main entry points are the BsHyperapp.Hyperapp.{app,asyncApp} functions, which take an initial model, view, and update functions, and the (string) HTML ID of a root element to mount the app on.

The model can be any valid OCaml type, and the update function takes a model and a message (of any one type) and returns a new model (for app) or a JavaScript promise of a new model (for asyncApp).

The view function takes a model and a 'message sender' function which is hooked up to route update messages properly into Hyperapp, and returns a rendering of the view which is composed of Hyperapp tags, which are created with BsHyperapp.Hyperapp.h (for tags with children) and BsHyperapp.Hyperapp.h_ (for tags with a single text node as the body).

For an illustrative example, see src/index.ml.

Difference between app and asyncApp

There are two different app runners (for now) because Elm does something similar. The app runner is a simple synchronous runner like Elm's http://package.elm-lang.org/packages/elm-lang/html/2.0.0/Html#beginnerProgram , in that it doesn't manage effects like HTTP requests. The asyncApp runner on the other hand does manage effects asynchronously, like Elm's http://package.elm-lang.org/packages/elm-lang/html/2.0.0/Html#program . In the future I may decide to unify the two using a parameterised OCaml module.

Unlike Elm's program, asyncApp has a (I believe) simpler way of managing effects: its update function returns a JavaScript promise of a new model instead of Elm's pair of (new model, effectful action to carry out).

bs-hyperapp's People

Contributors

yawaramin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bs-hyperapp's Issues

Any plans to update to latest Hyperapp version?

Hi, I see that this is tied to a very old version of hyperapp (v0.12.0). I tried to use this with hyperapp v1.25 but nothing shows on screen. Do you plan to update or is this project dead?

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.