Code Monkey home page Code Monkey logo

v's Introduction

V

v is a domain specific language for creating virtual-dom nodes. It features a clean interface for dealing with control flow like if/else, and looping, and integrates with Bacon to automatically handle patching the DOM.

Examples

Creating a static list:

var e = v
  .open('div')
    .open('h1').text('A list of cool things').close()
    .open('ul')
      .open('li').text('Bacon').close()
      .open('li').text('virtual-dom').close()
      .open('li').text('v').close()
    .close()
  .run();

document.body.appendChild(e);

Creating a dynamic clock:

let time    = Bacon.fromPoll(1000, () => new Date());
let hours   = time.map(d => d.getHours());
let minutes = time.map(d => d.getMinutes());
let seconds = time.map(d => d.getSeconds());

let e = v
  .open('div', {'class': 'clock'})
    .open('span', {'class': 'clock_hours'})
      .text(hours)
    .close()

    .text(':')

    .open('span', {'class': 'clock_minutes'})
      .text(minutes)
    .close()

    .text(':')

    .open('span', {'class': 'clock_seconds'})
      .text(seconds)
    .close()
  .run();

document.body.appendChild(e);

Learning v

Get it

TODO: register on npm (find a name that isn't taken)

There are three ways you can use v:

As a commonjs module

var v = require('v');

As an amd module:

define(['v'], function(v){
  //...
});

From window. If you are not using a module loader, v is exported to window, so it is still available using a <script> tag. Make sure you load Bacon and virtualDom before v.

var v = window.v;

Comparing v to h

Control flow

If you've used virtual-dom Compared to h, v has a much cleaner interface for handling control flow logic.

[TODO: example using 'h', and using 'v']

Functional Reactive Programming

v ๐Ÿ’– Bacon!

v is built to take advantage of functional reactive programming. You can use properties directly in your templates, without having to handle subscription yourself. v will take care of subscribing as necessary to keep your template up to date. Rather than defining your templates as snapshots in time, v encourages you view your templates as elements that evolve over time. (i.e. think Property<data> -> Property<VTree>, instead of data -> VTree).

You can also use v to automatically patch your elements as their inputs update, using run. This way, you avoid the imperative "create -> diff -> patch" dance that you usually have to do when using virtual-dom.

v's People

Contributors

mkaemmerer avatar

Stargazers

Daniel K avatar

Watchers

James Cloos 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.