GithubHelp home page GithubHelp logo

rlugojr / mercury Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raynos/mercury

0.0 2.0 0.0 1.5 MB

A truly modular frontend framework

Home Page: http://raynos.github.io/mercury/

License: MIT License

JavaScript 100.00%

mercury's Introduction

mercury

build status NPM version Coverage Status David Dependency status Gitter Size

Sauce Test Status

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 then 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

mercury's People

Contributors

raynos avatar kuraga avatar neonstalwart avatar aknuds1 avatar kumavis avatar ashnur avatar crabmusket avatar nrw avatar joshgillies avatar jonnyscholes avatar martintietz avatar matt-esch avatar lucianlature avatar omphalos avatar gcallaghan avatar jimt avatar joaostein avatar klemola avatar mattferrin avatar parshap avatar danielnaab avatar fiatjaf avatar jbplayground avatar ljharb avatar ntharim avatar ngryman avatar rtsao avatar

Watchers

Ray Lugo, Jr. 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.