• Stars
    star
    1,444
  • Rank 31,354 (Top 0.7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 5 years ago

Reviews

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

Repository Details

A functional frontend framework.

functional-frontend-architecture

This repository is meant to document and explore the implementation of what is known as "the Elm architecture". A simple functional architecture for building frontend applications.

High level overview

The entire state is contained in a single data structure. Things can happen and the state should change accordingly. The number of things that can happen is described as a set of actions. Actions flow unidirectionally down the application. Actions are handled by pure update functions. Such a function takes an action and a state and returns a new state. The state is handed to a view function that returns a virtual DOM representation. A module is an encapsulated set of actions, an update function and a view function. Modules can be nested inside other modules and modules can contain other modules. This makes the architecture nestable and modular.

Features/goals/ideas

  • As few mutations in application code as possible. The vast majority of your application can be completely pure.
  • Time changing values and interactions with the world is introduced in a controlled manner through FRP.
  • Testing should be easy! And nothing is easier to test than pure side-effect free functions.
  • State should be easily inspectable for debugging and serialization. Also, time travel.
  • Minimalism and simplicity are center pieces in every used library.
  • Actions should be expressed as union types.
  • Everything should be modular and nestable.
  • Simple live code editing thanks to hot module replacement.

Documentation

Examples

  • Counters example without FRP – This is several versions of a counters application. It starts out very simple and then gradualy increases in complexity. This is implemented with Snabbdom, union-type and Ramda.
  • Counters example with FRP – This is similair to the above example but the architecture is bootstraped with Flyd as and FRP library.
  • Who to follow – A small who to follow box using GitHubs API. It can be compared with a plain FRP version using Flyd and one using Rx.
  • Zip codes – This is a translation of Elm's zip-codes example, designed to show how to use asyncronous tasks, specifically http requests. ES6 Promises are used here as stand-ins for Elm's Tasks.
  • TodoMVC – A TodoMVC implementation built with Snabbdom, union-type, Ramda and Flyd.
  • File Uploader – Implements a file-upload component, i.e. it renders a list of chosen files, shows their upload progress, and allows users to cancel uploads. It demonstrates asynchronous side effects and a realistic stand-alone reuseable component or 'widget'.
  • Hot module reloading – Demonstrates how simple it is to use webpack's hot module replacement to achieve live code editing without browser refreshes.
  • Modal – Demonstrates a technique for implementing modals.
  • Nesting – A simple application that demonstrates three level nesting of components. This is intended to show how the action-routing scales.

Libraries

The architecture is implementation independent. It can be implemented with varied combinations of libraries. It only requires a virtual DOM library and a way to update JavaScript data structures without mutations. Having a nice representation of actions is also useful.

Virtual DOM libraries

The view layer in the architecture consists of pure functions that takes part of the applications state and returns a description of it's view. Such a description will typically be a virtual DOM representation that will later be rendered with a virtual DOM library. A number of options exists.

  • Snabbdom – A small modular and extensible virtual DOM library with splendid performance.
  • virtual-dom – A popular virtual DOM library.
  • React – Mature and widely used. It supports JSX which many people like. It is however a bulky library. It supports stateful components which should not be used together with the architecture.

Updating data structures

When handling actions inside update functions it is necessary to update ones state without mutating it. Libraries can provide a help with regards to this.

  • Ramda – Ramda provides a huge amount of functions for working with native JavaScript data structures in a purely functional way.

Representing actions

More Repositories

1

flyd

The minimalistic but powerful, modular, functional reactive programming library in JavaScript.
JavaScript
1,566
star
2

union-type

A small JavaScript library for defining and using union types.
JavaScript
475
star
3

synceddb

Makes it easy to write offline-first applications with realtime syncing and server side persistence.
JavaScript
397
star
4

dffptch

A micro library for diffing and patching JSON objects using a compact diff format
JavaScript
170
star
5

composable.el

Composable text editing for Emacs.
Emacs Lisp
115
star
6

functionize

A library which aids in making any JavaScript library more functional.
JavaScript
49
star
7

projectdo

Context-aware single-letter project commands to speed up your terminal workflow.
Shell
47
star
8

Kran

An entity system written in JavaScript.
JavaScript
42
star
9

Gtk98Icons

An icon theme for GTK that looks like Windows 98
PHP
40
star
10

smart-comment

Smarter commenting for Emacs
Emacs Lisp
40
star
11

sync-promise

Compact synchronized promise implementation. Promises/A+ incompliant. Works inside IdexedDB transactions.
JavaScript
32
star
12

dot-compose

Function composition with dot as a composition operator.
JavaScript
23
star
13

seamless-fantasy

Make fantasy land seamlessly compatible with plain JavaScript data structures.
JavaScript
10
star
14

list-difference

Fast algorithm for finding edits between lists.
JavaScript
10
star
15

duck

πŸ¦† Turns a TypeScript file into JSON describing the files exports.
TypeScript
8
star
16

find-the-function

A tiny tool for finding functions from libraries
TypeScript
7
star
17

ryter

A tiny JavaScript router
JavaScript
7
star
18

web-swipe-view

Horizontal swipe views for mobile web applications
JavaScript
7
star
19

finger-tree

Highly optimized implementation of finger trees in JavaScript
TypeScript
6
star
20

flyview

Efficient views powered by streams/ovservables/functional reactive properties.
JavaScript
6
star
21

fake-raf

A fake requestAnimationFrame perfect for unit testing.
JavaScript
5
star
22

flyd-forwardto

Create a new stream that passes all values through a function and forwards them to a target stream.
JavaScript
4
star
23

maxima-calculus2

Maxima funktioner til lΓΈsning af eksamensopgaver i kurset Calculus 2 pΓ₯ Aarhus Universitet
4
star
24

turing-patterns

Multi-Scale Turing Patterns
JavaScript
4
star
25

reflex-examples

A collection of examples using Reflex.
Haskell
3
star
26

flyd-scanmerge

Flyd module for conveniently merging and reducing several streams into one.
JavaScript
3
star
27

flyd-obj

Functions for working with stream in objects.
JavaScript
3
star
28

category-theory-notes

TeX
3
star
29

matmod

Handy functions for matMod written in R for Jupyter
Jupyter Notebook
3
star
30

dnd-scroll

Proper edge scroll when dragging with HTML 5 drag and drop!
JavaScript
3
star
31

dffptch-haskell

A small library for diffing and patching JSON objects using a compact diff format
Haskell
2
star
32

keyano-vscode

Next-generation keyboard-driven editing language. Edit code at the speed of light.
TypeScript
2
star
33

flyd-filter

Filter function for Flyd.
JavaScript
2
star
34

planetsimulator

A physical simulation of planetary motion written in JavaScript
JavaScript
2
star
35

flyd-every

Takes a time interval t and creates a stream of the current time updated every t.
JavaScript
1
star
36

paldepind.github.io

CSS
1
star
37

hareactive-old

Experimental WIP.
JavaScript
1
star
38

vdom-benchmark-snabbdom

Virtual DOM Benchmark implementation for Snabbdom library.
JavaScript
1
star
39

simple-frp

An attempt at creating a very simple FRP library for educational purposes.
TypeScript
1
star
40

flyd-sampleon

sampleOn for Flyd.
JavaScript
1
star
41

software-foundations

My solutions to exercises in Benjamin C. Pierce's Software Foundations
HTML
1
star
42

flyd-keepwhen

keepWhen function for Flyd.
JavaScript
1
star
43

flyd-lift

Lift function for Flyd.
JavaScript
1
star
44

dotfiles

Repository containing my dotfiles.
Emacs Lisp
1
star
45

react-native-chainable-stylesheet

TypeScript
1
star
46

flyd-aftersilence

Flyd module that buffers values from a stream and emits them after a specified duration of silience.
JavaScript
1
star
47

domain-theory

CSS
1
star