Git Product home page Git Product logo

idom2string's Introduction

idom2string

Early experiments with IncrementalDOM server-side rendering. As of now this is just a proof of concept, all comments and ideas are welcome.

Usage

Import it as you would import the real thing, your app will start rendering to string:

var IncrementalDOM = require('idom2string')

A target output can be set before your app calls IncrementalDOM.patch:

IncrementalDOM.setOutput(prettyPrint, output, doneCallback, keepOpen)
  • prettyPrint: nothing or a string to be used for indentation.
  • output:
    • an object: will get a .rendered property containing the output. it defaults to a new Object.
    • a stream: will be directly filled using it's .write method, it's reference is then passed to the callback, it can be an http response, a file stream, std.process...
  • doneCallback: a function being called when patch is done, it receives the output reference.
  • keepOpen: prevents flushing the internal state when patch is done.

IncrementalDOM.patch "node" argument can be empty or one of the following:

  • a function: get passed the patch description function as a partial, this can be used to wrap the patch into an outer description function to generate an approot, note that executing the partial is responsability of the node function. Check document.js in the demos for examples
  • an object: when a .innerHTML property is present it will be assigned the patch rendered result, this can enable some other kind of composition or fill an Element.innerHTML when testing in a browser. When .setOuput is not called the node reference, if any, can be an alternative way to read the output.

The methods expected to return an element will return a mock object, you can assign or merge to this object whatever suits your code:

IncrementalDOM.setElementDummy(obj, merge)

To forcefully clean up the internal state (mostly when using keepOpen on a strem output):

IncrementalDOM.forceReset()

Examples

All examples are based on localvoid's incremental dom port of dbmonster. App code is untouched, document reference is mocked via incremental-dom calls.

dbmonster-server
$ cd demo/dbmonster-server
$ node server.js

Serves a server side rendered version of dbmonster, look at server.js to check some possible usages of .setOutput for serving. Once the prerendered document is loaded the normal js app will kick in (throttle your network to notice it)

dbmonster-streaming
$ cd demo/dbmonster-streaming
$ node server.js

Streams a live dbmonster output, be advised that when streming to http it will likely flood your browser tab process in a few seconds.

dbmonster-browser

start a static server in the root of the project

localhost:8080/demo/dbmonster-browser/index.html is a client side dbmonster only using the string interpreter, this is just usefull for test and development.

idom2string's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

anilanar

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.