Giter VIP home page Giter VIP logo

mithril-node-render's Introduction

mithril-node-render

Gitter Build Status rethink.js Dependency Status devDependency Status

Use mithril views to render server side

Demo

Usage Example

Installation

npm install mithril-node-render

Usage

// use a mock DOM so we can run mithril on the server
require('mithril/test-utils/browserMock')(global)

var m = require('mithril')
var render = require('mithril-node-render')

render(m('span', 'huhu')).then(function (html) {
  // html === '<span>huhu</span>'
})

Async components

As you see the rendering is asynchron. It waits for resolve of all promises that might get returned from oninit callbacks.

var myAsyncComponent = {
  oninit: function (node) {
    return new Promise(function (resolve) {
      node.state.foo = 'bar'
      resolve()
    })
  },
  view: function (node) {
    return m('div', node.state.foo)
  }
}

render(myAsyncComponent).then(function (html) {
  // html === '<div>bar</div>'
})

Options

Optionally pass in options as an object: m.render(component, options).

The following options are supported:

escapeAttributeValue(value) Default: render.escapeHtml A filter function for attribute values. Receives value, returns what is printed.

escapeString(value) Default: render.escapeHtml A filter function for string nodes. Receives value, returns what is printed.

strict Default: false Set this to true to close all empty tags automatically. Default is HTML mode where tags like <br> and <meta> are allowed without closing tags. This is required if you're rendering XML or XHTML documents.

See also

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.