Threepenny-GUI

What's this?

for more information on what it does and can do for you as a library user.

Examples

The library comes with many examples, which can be found in the samples folder. Follow the link for more information on how to run them.

Desktop Apps

Threepenny is mainly intended for writing GUI applications that run on the local network, and it relies on a web browser being installed. You can drop the latter requirement and integrate it a bit more tightly with you desktop environment by using the Electron framework. There is no fully automated support for this yet, but the documentation includes a tutorial on how to use Electron with Threepenny.

Technical overview

JavaScript FFI

A program written with Threepenny is essentially a small web server that displays the user interface as a web page to any browser that connects to it.

The web server displays a HTML page, which in turn establishes WebSocket connection with the server. The server uses this connection to send JavaScript code that is executed in the client. In the library, this appears as a JavaScript Foreign Function Interface (FFI). The documentation includes more information on the design of the JavaScript FFI.

Latency

The frequent communication between browser and server
means that Threepenny is best used as a GUI server running on localhost. You can use it on your local network as well.

If you want to reduce latency, the best option is to generate larger blocks of JavaScript
code and run them on the client. Consider this approach similar to a
shading language.
You can import any JavaScript library and use it from the JavaScript FFI.

If you don't want to write JavaScript, then you could choose a Haskell-like language like PureScript, Fay. You can also directly compile JavaScript to Haskell with Haste or GHCJS.

Future ideas

HTML rendering mode

It might be nice in the case of search engines to merely generate a DOM and render it, so that search engines can read the pages.

UI libraries

qooxdoo — provides a feature-complete widget set. One could wrap this in a type-safe API from Threepenny and get a complete, stable UI framework for free. Most of the "immediate feedback" like dragging things here, switching tabs there, are taken care of by the framework. All that would be left would be to provide the domain configuration and business/presentation logic.

There are plenty more like this, but this is the first that springs to
mind that is good.

Contributors

Many thanks to everyone who contributed, provided feedback or simply wrote an application using Threepenny! In particular, many thanks to:

Implement batching / buffering for FFI calls. [#131][]. Several calls to the runFunction function may now buffer the JavaScript code and send it to the browser window in a single message at a later time. This improves performance considerably.

Add option jsWindowReloadOnDisconnect to reload the browser window [#130][] whenever the WebSocket connection is broken. This is useful for e.g. mobile devices, which tend to disconnect WebSocket connections very often.

Dependencies

Add dependency on exceptions

0.7.0.2 — Maintenance release

Bump dependencies to allow aeson 1.2

Bump dependencies to allow websockets 0.11

0.7.0.1 — Maintenance release

Bump dependencies to allow aeson 1.1

Bump dependencies to allow vector 0.12

Bump dependencies to allow websockets 0.10

0.7.0.0 — Maintenance and snapshot release

JavaScript FFI: Reduce communication from browser to server when creating Elements.
New function unsafeCreateJSObject to create JavaScript objects without
waiting for a client response. [#131][]

Elements that have become unreachable, for instance because they have been removed from the DOM and are no longer reachable in the Haskell code, will be garbage collected again. Fix [#109][], [#113][].

Adjust dependencies.

Add <meta> tag to indicate UTF8 encoding in html file. [#116][]

0.6.0.3 — Maintenance release.

Temporary fix for #109, which was causing event handlers to be discarded. Unfortunately, this means that elements are currently not garbage collected after they have been removed from the DOM tree.

The example source code in the samples folder has been reorganized and consolidated.

0.6.0.0 — Snapshot release.

The internals of the JavaScript FFI has been reimplemented completely. A new module Foreign.JavaScript exports a bare JavaScript FFI in case you want to write a custom GUI framework. However, the module Graphics.UI.Threepenny is not compatible with it, even though it builds on top of it.

The fields of Config type for server configuration are now prefixed with js instead of tp. Example: jsPort, jsStatic.

The functions loadFile and loadDirectory have been removed, as I felt that the jsStatic option is sufficient for most use cases.