Code Monkey home page Code Monkey logo

hplayground's Introduction

HPlayground

latest additions:

Create applications in the browser as fast as easy as console applications and have reactive, window-oriented and spreadsheet-like behaviours for free.

So you translate your inputs and outputs from console calls to playground widgets and with no more modifications you have reactive and spreadsheet behaviours.

Hplayground uses the same MFlow combinators running in the browser with the Haste compiler

This program creates two input boxes and present the sum below them:

    import Haste.HPlay.View
    import Control.Applicative


    main= runBody action

    action :: Widget ()
    action = do
         r  <- (+) <$> inputInt Nothing `wake` OnKeyPress <++ br
                   <*> inputInt Nothing `wake` OnKeyPress <++ br
         p  (show r) ++> noWidget

Each widget creates his own rendering and manage his own events, that can be propagated or not down trough the monadic computation and trigger modifications in the DOM.

IDE with EXAMPLES, EXAMPLES and more EXAMPLES

There is an IDE for Haste and hplayground it is running At:

http://tryplayg.herokuapp.com

With many examples.

You can install this IDE locally or in an Heroku instance. Follow the instructions at:

https://github.com/agocorona/tryhplay

Additionally you can see a more complex example: the hplay-todo, the todoMVC project for hplayground.

The todo application running

How it works

Under the hood there is the good old formlet concept. It uses monadic and applicative combinators The same ones used by MFlow in the server side. While the server side widgets of MFlow produce blaze-html output converted to bytestrings, playground construct a builder function that creates a tree in the HTML DOM when executed. This builder (perch) is monoidal so the formlet can aggregate subtrees. When some event happens in the widget subtree, the widget executes his code and reconstruct itself. If it return a valid result and it is in a monadic computation the tree continues recreating itself downstream by executing further widgets in the monadic sequence. If the event is raised within a widget that does not generate a valid result (return empty) the remaining widgets continue unchanged and unevaluated.

Status

Non-local modifications of the DOM works with the new "at" primitive. Option buttons, checkboxes and drop-down buttons works with the same syntax than MFlow.

The Cell module has Lens-like primitives for updates of form elements and experimental math operations with form elements as spreadsheet cells. Currently it is at the beginning.

How to run

Docker file

https://registry.hub.docker.com/u/agocorona/tryhplay/

Contains everything necessary to use hplayground

Install from scratch

install the ghc compiler

install Haste:

>cabal install haste-compiler
>haste-boot

install perch

>haste-inst install haste-perch

clone hplayground

>git clone http://github.com/agocorona/hplayground

install hplayground:

>haste-inst install

or install it from Hackage using cabal:

>haste-inst install hplayground

compile

>cd src
>hastec Main.hs --output-html

hastec uses ghc internally so you can expect ordinary ghc error messages in your development.

Browse the Main.html file. In windows simply execute it in the command line:

>Main.html

you can also see it executing at

 http://mflowdemo.herokuapp.com/noscript/wiki/browserwidgets

Main.html and Main.js is included in the repo so you can execute it in your PC

Execute it in the same directory where Main.js is, since it references it assuming that it is in the current folder

hplayground's People

Contributors

agocorona avatar juhp avatar mietek avatar tusj avatar

Watchers

 avatar  avatar  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.