Socket
Socket
Sign inDemoInstall

mithril-node-render

Package Overview
Dependencies
2
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mithril-node-render

Node rending of mithril views


Version published
Weekly downloads
98
decreased by-64.23%
Maintainers
1
Install size
43.4 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 02 Nov 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc