• This repository has been archived on 16/Jun/2020
  • Stars
    star
    2,818
  • Rank 16,155 (Top 0.4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 4 years ago

Reviews

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

Repository Details

A truly modular frontend framework

mercury

Deprecated: Not actively being worked on.

Instead tonic and https://tonic.technology/ are actively being worked on.

mercury has some interesting ideas but they are not very practical at scale. tonic is a lightweigth component system on top of web components that leverages the browsers HTML parser for the heavy lifting instead of virtual-dom.

It comes with a set of components which help with building apps more quickly by having some re-usable components out of the box.

Description

A truly modular frontend framework

To understand what I mean by truly modular just read the source

Examples

Hello world

'use strict';

var document = require('global/document');
var hg = require('mercury');
var h = require('mercury').h;

function App() {
    return hg.state({
        value: hg.value(0),
        channels: {
            clicks: incrementCounter
        }
    });
}

function incrementCounter(state) {
    state.value.set(state.value() + 1);
}

App.render = function render(state) {
    return h('div.counter', [
        'The state ', h('code', 'clickCount'),
        ' has value: ' + state.value + '.', h('input.button', {
            type: 'button',
            value: 'Click me!',
            'ev-click': hg.send(state.channels.clicks)
        })
    ]);
};

hg.app(document.body, App(), App.render);

Basic Examples

Intermediate Examples

Unidirectional examples

The following examples demonstrate how you can mix & match mercury with other frameworks. This is possible because mercury is fundamentally modular.

Disclaimer: The following are neither "good" nor "bad" ideas. Your milage may vary on using these ideas

Motivation

Mercury vs React

mercury is similar to react, however it's larger in scope, it is better compared against om or quiescent

  • mercury leverages virtual-dom which uses an immutable vdom structure
  • mercury comes with observ-struct which uses immutable data for your state atom
  • mercury is truly modular, you can trivially swap out subsets of it for other modules
  • mercury source code itself is maintainable, the modules it uses are all small, well tested and well documented. You should not be afraid to use mercury in production as it's easy to maintain & fix.
  • mercury encourages zero dom manipulation in your application code. As far as your application is concerned elements do not exist. This means you don't need to reference DOM elements when rendering or when handling events
  • mercury is compact, it's 11kb min.gzip.js, that's smaller than backbone.
  • mercury strongly encourages FRP techniques and discourages local mutable state.
  • mercury is highly performant, it's faster than React / Om / ember+htmlbars in multiple benchmarks TodoMVC benchmark
    animation benchmark TodoMVC benchmark source
  • mercury comes with FP features like time-travel / easy undo out of the box.
  • mercury is lean, it's an weekend's read at 2.5kloc. (virtual-dom is 1.1kloc, an evening's read.) compared to react which is almost 20kloc (a month's read)

Modules

mercury is a small glue layer that composes a set of modules that solves a subset of the frontend problem.

If mercury is not ideal for your needs, you should check out the individual modules and see if you can re-use something.

Alternatively if the default set of modules in mercury doesn't work for you, you can just require other modules. It's possible to for example, swap out vtree with react or swap out observ-struct with backbone

See the modules README for more information.

Documentation

See the documentation folder

FAQ

See the FAQ document

API

WIP. In lieu of documentation please see examples :(

Installation

npm install mercury

Development

If you want to develop on mercury you can clone the code

git clone [email protected]:Raynos/mercury
cd mercury
npm install
npm test

npm run tasks

  • npm test runs the tests
  • npm run jshint will run jshint on the code
  • npm run disc will open discify (if globally installed)
  • npm run build will build the html assets for gh-pages
  • npm run examples will start a HTTP server that shows examples
  • npm run dist will create a distributed version of mercury
  • npm run modules-docs will (re)generate docs of mercury modules

Inspirations

A lot of the philosophy and design of mercury is inspired by the following:

  • react for documenting and explaining the concept of a virtual DOM and its diffing algorithm
  • om for explaining the concept and benefits of immutable state and time travel.
  • elm for explaining the concept of FRP and having a reference implementation of FRP in JavaScript. I wrote a pre-cursor to mercury that was literally a re-implementation of elm in javascript (graphics)
  • reflex for demonstrating the techniques used to implement dynamic inputs.

Contributors

  • Raynos
  • Matt-Esch
  • neonstalwart
  • parshap
  • nrw
  • kumavis

MIT Licenced

More Repositories

1

http-framework

A web framework based purely on require('http')
JavaScript
523
star
2

xtend

extend like a boss
JavaScript
305
star
3

global

Require global variables
JavaScript
252
star
4

main-loop

A rendering loop for diffable UIs
JavaScript
172
star
5

leaked-handles

Detect any handles leaked in node
JavaScript
166
star
6

DOM-shim

Shims out the entire DOM4 API
JavaScript
155
star
7

function-bind

JavaScript
136
star
8

error

Error handling utilities for node
JavaScript
122
star
9

body

Body parsing
JavaScript
120
star
10

after

All the flow control you'll ever need
JavaScript
116
star
11

min-document

A minimal DOM implementation
JavaScript
109
star
12

jsig

From scratch type-checker
JavaScript
104
star
13

duplexer

Creates a duplex stream
JavaScript
95
star
14

observ

A observable value representation
JavaScript
74
star
15

observ-struct

An object with observable key value pairs
JavaScript
72
star
16

virtual-hyperscript

A DSL for creating virtual trees
JavaScript
59
star
17

topology

Different network topologies
JavaScript
57
star
18

dom-delegator

Decorate elements with delegated events
JavaScript
57
star
19

continuable

Idea for callbacks as values
JavaScript
54
star
20

live-reload

A live reload server & client
JavaScript
51
star
21

pd

Property Descriptors made easy
JavaScript
44
star
22

engine.io-stream

Wrap engine.io in a real stream interface
JavaScript
44
star
23

vdom-thunk

A thunk optimization for virtual-dom
JavaScript
42
star
24

stream-chat

Alpha chat app using streams for communication
JavaScript
40
star
25

resultify

Handle errors with async/await without try/catch.
JavaScript
38
star
26

graphics

Efficient data structures that represent renderable scenes
JavaScript
38
star
27

safe-json-parse

Parse JSON safely without throwing
JavaScript
36
star
28

webrtc-stream

WebRTC demo
JavaScript
34
star
29

level-livefeed

Live query a range in leveldb
JavaScript
34
star
30

http-works

A workshopper for http framework
JavaScript
32
star
31

tsdocstandard

Standard but also use TypeScript on JS files with jsdoc.
JavaScript
31
star
32

discovery-network

A peer to peer discovery network
JavaScript
31
star
33

geval

JavaScript
30
star
34

corsify

CORS up a route handler
JavaScript
29
star
35

itape

An interactive tape runner.
JavaScript
27
star
36

ncore

Core infrastructure for node.
JavaScript
26
star
37

send-data

send data through response
JavaScript
26
star
38

observ-array

An array containing observable values
JavaScript
26
star
39

append-only

Append only scuttlebutt structure
JavaScript
25
star
40

jsonml-stringify

Convert jsonml arrays to html strings
JavaScript
22
star
41

eslint-plugin-perf-standard

A set of custom plugins to enforce high performance JS
JavaScript
21
star
42

routes-router

Simplest request handler possible
JavaScript
21
star
43

for-each

A better forEach
JavaScript
21
star
44

auth-stream

Authorize access before exposing a stream
JavaScript
21
star
45

value-event

Create DOM event handlers that write to listeners
JavaScript
21
star
46

boot

Shoe & mux demux with reconnect!
JavaScript
20
star
47

stream-router

Easily route mdm streams
JavaScript
19
star
48

raynos-blog

My blog
JavaScript
19
star
49

jsconf2014-talk

Modular frontend with NPM & pals
JavaScript
19
star
50

whatwg-streams

JavaScript
17
star
51

deep-merge

Deep merge objects with custom merging logic
JavaScript
17
star
52

map-async

Asynchronously map over a list
JavaScript
17
star
53

data-channel

Turn a data channel into a stream
JavaScript
17
star
54

gens

Experimental usage of generators
JavaScript
17
star
55

level-cache

An in memory cache on top of leveldb
JavaScript
17
star
56

npm-bin-deps

NPR allows you to run your CLI dependencies without having a copy in node_modules.
JavaScript
16
star
57

serve-browserify

HTTP handler for serving browserify bundles
JavaScript
16
star
58

delta-stream

A stream that emits deltas in change
JavaScript
15
star
59

examplifier

Turn bland source code into interactive demos
JavaScript
15
star
60

distributed-map

A distributed key value store in the browser
JavaScript
14
star
61

clientmongo

Use the mongo API in the browser
JavaScript
14
star
62

multi-channel-mdm

Create persisted channels to broadcast data!
JavaScript
14
star
63

buffer-stream

A duplex stream that buffers writes
JavaScript
14
star
64

chain-stream

Chain stream operations together
JavaScript
14
star
65

fake-s3

a fake s3 server for testing purposes.
JavaScript
13
star
66

signal-channel

A signal channel that empowers webrtc
JavaScript
13
star
67

levelidb

A levelup interface on top of indexeddb
JavaScript
12
star
68

reduce

A better [].reduce
JavaScript
12
star
69

level-write-stream

A writeStream implementation for leveldb
JavaScript
12
star
70

frontend-framework

Building frontend apps with small modules
JavaScript
12
star
71

browserify-server

spin up browserify demos real easy
JavaScript
12
star
72

format-stack

Formats a stack with colors
JavaScript
12
star
73

feature

Feature detection for host objects
JavaScript
12
star
74

hash-router

A frontend router for the hash change event
JavaScript
11
star
75

promise-stream

A Promises/A implementation based on streams
JavaScript
11
star
76

html-delegator

Decorate elements with delegated events
JavaScript
11
star
77

ready-signal

A ready signal. Wait for ready and signal it's ready
JavaScript
11
star
78

ev-store

Stores event listeners and event handles on a DOM object
JavaScript
11
star
79

weakmap-shim

JavaScript
10
star
80

to-array

Turn an array like into an array
JavaScript
10
star
81

term-color

A lighter weight alternative to chalk
JavaScript
9
star
82

static-config

JavaScript
9
star
83

npm-less

JavaScript
9
star
84

eventemitter-light

It's a light event emitter
JavaScript
9
star
85

expiry-model

A scuttlebutt model that expires keys
JavaScript
9
star
86

http-methods

Handle multiple methods elegantly
JavaScript
9
star
87

mux-demux-shoe

Shoe and mux-demux come together!
JavaScript
9
star
88

validate-form

JavaScript
9
star
89

iterators

iterate over collections asynchronously
JavaScript
8
star
90

fake-sqs

Runs a fake SQS server on a HTTP port.
JavaScript
8
star
91

redirecter

JavaScript
8
star
92

seaport-proxy

Proxy all the seaports!
JavaScript
8
star
93

request-proxy

A version of request that's local to a fixed base uri
JavaScript
8
star
94

pre-bundled

A tool that pre bundles and re publishes npm dependencies
JavaScript
8
star
95

mongo-col

mongodb collection wrapper
JavaScript
8
star
96

tape-harness

A helper to run integration tests against an application
JavaScript
8
star
97

sockjs-stream

A streaming API for sockjs
JavaScript
7
star
98

add

Add two numbers
JavaScript
7
star
99

so642

JavaScript
7
star
100

composite

Compose functions together
JavaScript
7
star