• This repository has been archived on 02/Feb/2021
  • Stars
    star
    161
  • Rank 233,470 (Top 5 %)
  • Language PureScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An experiment in replacing the virtual DOM and avoiding diffing

purescript-sdom

An experiment in replacing the virtual DOM and avoiding diffing.

Motivation

The virtual DOM (VDOM) has become a very popular approach to developing applications in the browser, popularized by libraries like React. A simplified VDOM approach can be summarized briefly as follows:

  • Choose a type state of application states.
  • Write a function state -> VDOM from application states to a virtual DOM representation of the UI.
  • Each time we reach a new state, use a function diff :: VDOM -> VDOM -> Patch to compute the changes to the rendered virtual DOM.
  • Use a function Patch -> Eff (dom :: DOM) Unit to apply those changes to the real DOM.

The VDOM approach has many benefits. However, many web apps which use a VDOM don't actually require one.

Consider something like a web form which might contain text inputs and validation messages. If you didn't have a virtual DOM, you would just lay out the form statically, set the initial attributes and text values, and add event handlers to update them. The elements themselves would never change.

A VDOM approach in this case might be considered overkill - why should I have to diff two trees of components in order to update a simple label, when I can always easily figure out which label to update.

A key benefit of the VDOM is that it hides the complexity of the DOM API behind a simpler API with a clean denotation: an application is a function from states to a conceptual representation of the UI. However, operationally it is very heavy. The potential problem is that the diff function above might be quite expensive to compute. With well-chosen keys on every node, it might be possible to tune this computation, but there are other options available.

This library introduces the SDOM, or "static DOM". The idea is that by restricting components so that the "shape" of the UI becomes static, we can keep the clean denotation of the VDOM approach, but simplify the operational side dramatically. The SDOM consists of a static tree of components, with only the leaves (text nodes and attributes) changing over time. The SDOM approach also allows for limited forms of dynamic behavior, such as a component which renders a (uniform) array of subcomponents.

In practice, this is not so much of a restriction, and the limited form of dynamic behavior is enough to emulate most common UI patterns. Indeed, working with the SDOM is quite reminiscent of template-based approaches to UI development, but keeping the "one way binding" approach which is commonly associated with the VDOM.

More

For a more extensive motivation of the SDOM approach, an explanation of the underlying approach and how it was developed, you may want to check out this blog post.

More Repositories

1

purescript-book

Sources for the PureScript book
PureScript
454
star
2

purescript-thermite

A simple PureScript wrapper for React
PureScript
350
star
3

24-days-of-purescript-2016

24 Days of PureScript, 2016
287
star
4

initialround

Web app for interviewing technical candidates in the browser
C#
163
star
5

purescript-behaviors

A simple push-pull FRP implementation
PureScript
134
star
6

dovetail

A PureScript interpreter in Haskell
Haskell
118
star
7

purescript-purview

A UI library based on the incremental lambda calculus
PureScript
111
star
8

purescript-react-explore

Experiments with comonads for modelling React UIs
PureScript
90
star
9

purescript-incremental-functions

Incremental lambda calculus
PureScript
80
star
10

purescript-foreign-generic

Generic deriving for purescript-foreign
PureScript
63
star
11

purescript-quickserve

Quick HTTP servers
PureScript
60
star
12

haskell-slides

Haskell
50
star
13

purescript-drawing

A data structure for drawings
PureScript
47
star
14

purescript-derive-lenses

A little utility to derive lenses and prisms for data types in PureScript
PureScript
41
star
15

purescript-smash

An "extensible coeffect" system built out of comonads and Day convolution.
PureScript
36
star
16

the-future-is-comonadic

My (rejected) OBT-2018 submission
TeX
35
star
17

purescript-rest

A toolkit for creating REST services with Node and PureScript
PureScript
32
star
18

purescript-jquery

Type declarations for jQuery
PureScript
30
star
19

mu-kanren

A step-by-step MicroKanren evaluator
JavaScript
29
star
20

star-dodge-clone

A partial clone of 2D Star Dodge
PureScript
26
star
21

purescript-safely

A combinator for making any monadic control operator stack-safe
PureScript
26
star
22

24-days-of-purescript-2014

25
star
23

purescript-event

The Event type, extracted from purescript-behaviors
PureScript
23
star
24

purescript-debugger

A simple console debugger for PureScript functions
PureScript
22
star
25

purescript-graphics-vis

A library for interactively creating graphics visualizations
PureScript
22
star
26

typescript-docs

A documentation tool for TypeScript Definition files
Haskell
21
star
27

purescript-behaviors-demo

purescript-behaviors in PSCi
PureScript
19
star
28

language-typescript

Haskell library for working with TypeScript Definition files
Haskell
18
star
29

purescript-leibniz

Leibniz Equality
PureScript
18
star
30

purescript-memoize

Type classes for creating memoized functions
PureScript
18
star
31

lambdaconf-2015

Materials for my LambdaConf 2015 Workshop
PureScript
17
star
32

purescript-yargs

PureScript bindings for the yargs command-line parsing library
PureScript
17
star
33

partial

A nullary type class for partial functions
Haskell
15
star
34

purescript-signal-loop

An abstraction on top of purescript-signal, for avoiding Channels
PureScript
15
star
35

purescript-folds

Applicative Folds, in the style of Gabriel Gonzalez' foldl library
PureScript
14
star
36

purescript-free-canvas

A free monad interface to the canvas
PureScript
13
star
37

purescript-lists-fast

Fast replacements for some common functions on linked lists
PureScript
13
star
38

purescript-hooks

PureScript
12
star
39

Purity

CLR-Hosted Total Functional Programming Language
C#
11
star
40

dicom-haskell-library

A library for reading and writing DICOM files in the Explicit VR Little Endian transfer syntax.
Haskell
10
star
41

purescript-day

Day Convolution
PureScript
10
star
42

runpurs

PureScript corefn interpreter experiment for processing JSON
JavaScript
10
star
43

purescript-hoist

Optics between functors
PureScript
10
star
44

purescript-foreign-lens

A lens-compatible set of getters for purescript-foreign
PureScript
10
star
45

purescript-node-coroutines

Coroutines for working with Node streams
PureScript
9
star
46

lambdaconf

LambdaConf Notes
JavaScript
9
star
47

Embedding-a-Full-Linear-Lambda-Calculus-in-Haskell

Embedding a Full Linear Lambda Calculus in Haskell
8
star
48

Adventure

For the LA Haskell Meetup
Haskell
8
star
49

purescript-scoped-labels

A little implementation of records with duplicate labels
PureScript
8
star
50

purescript-pprint

A simple pretty printing library
PureScript
8
star
51

purescript-bsp-experiment

An isometric canvas renderer which supports transparency
JavaScript
8
star
52

purescript-lens-simple

Very basic lenses
PureScript
7
star
53

purescript-reflection

Reflecting values at the type level
PureScript
7
star
54

stack-safety-for-free

A note on the approach to stack-safety in PureScript's core libraries
PureScript
7
star
55

purescript-tropical

Tropical Semirings
PureScript
6
star
56

purescript-pairing

Pairings of functors
PureScript
6
star
57

codemesh2016

Code Mesh 2016 slides
PureScript
5
star
58

tablestorage

Azure Table Storage REST API Wrapper
Haskell
4
star
59

hasuracon-2022

Haskell
4
star
60

blog-source

Markdown files and static site generator script for my blog.
Haskell
4
star
61

purescript-distributions

A monad which generalizes the probability monad to an arbitrary Semiring of probabilities
PureScript
4
star
62

purescript-isomorphisms

A category of isomorphisms, and some standard isomorphisms
PureScript
4
star
63

HsDiff

Haskell Diff Tool
Haskell
4
star
64

tinytemplate

A tiny text templating library for Haskell
Haskell
3
star
65

purescript-webidl

A wrapper for the webidl2 library
PureScript
3
star
66

Automata-hs

A monad for finite deterministic automata
Haskell
3
star
67

purescript-with-index

A tiny library for composing indexed traversals
PureScript
3
star
68

old-blog

Very old blog posts
2
star
69

supervisor

A simple ptrace-based supervisor
C
2
star
70

BF

BF .NET Compiler
C#
2
star
71

purescript-croco

Croco Magneto remake in PureScript - work in progress
JavaScript
2
star
72

acme-all-monad

A monad which is powerful enough to interpret any action
Haskell
2
star
73

codejam

Google CodeJam Solutions
Haskell
1
star
74

purescript-sammy

PureScript bindings for Sammy.js, a Javascript, browser-based Sinatra-clone.
PureScript
1
star
75

parsel

A just-in-time compiler for recursive descent parsers
C#
1
star
76

paf31.github.io

functorial
HTML
1
star
77

with-index

A tiny library for composing indexed traversals
Haskell
1
star
78

purescript-taylor

Taylor series
PureScript
1
star
79

purescript-drumloops

Experimenting with purescript-howler
PureScript
1
star
80

Automata

A monad for finite deterministic automata
C#
1
star
81

pattern-arrows

Arrows for Pretty Printing
Haskell
1
star
82

monad-unify

A library for type-safe first-order unification
Haskell
1
star
83

purescript-handlebars

Simple bindings to the handlebars text templating library
PureScript
1
star