{"id":20050088,"url":"https://github.com/mithriljs/mithril-node-render","last_synced_at":"2025-04-09T05:09:24.142Z","repository":{"id":21922044,"uuid":"25246294","full_name":"MithrilJS/mithril-node-render","owner":"MithrilJS","description":"Use mithril views to render server side","archived":false,"fork":false,"pushed_at":"2024-09-02T15:06:33.000Z","size":225,"stargazers_count":212,"open_issues_count":0,"forks_count":44,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-02T04:02:48.413Z","etag":null,"topics":["javascript","mithril","server-rendering"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MithrilJS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"mithriljs"}},"created_at":"2014-10-15T08:45:03.000Z","updated_at":"2025-02-25T12:28:09.000Z","dependencies_parsed_at":"2024-01-23T21:17:41.066Z","dependency_job_id":"85a92662-4a88-488b-a647-52eae6eb479c","html_url":"https://github.com/MithrilJS/mithril-node-render","commit_stats":{"total_commits":173,"total_committers":31,"mean_commits":5.580645161290323,"dds":0.3988439306358381,"last_synced_commit":"a35f061dbae53dfa7c6a6273525b39ad255eae90"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MithrilJS%2Fmithril-node-render","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MithrilJS%2Fmithril-node-render/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MithrilJS%2Fmithril-node-render/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MithrilJS%2Fmithril-node-render/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MithrilJS","download_url":"https://codeload.github.com/MithrilJS/mithril-node-render/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980837,"owners_count":21027808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","mithril","server-rendering"],"created_at":"2024-11-13T11:54:02.848Z","updated_at":"2025-04-09T05:09:24.119Z","avatar_url":"https://github.com/MithrilJS.png","language":"JavaScript","readme":"mithril-node-render\n===================\n[![zulip, join chat](https://img.shields.io/badge/zulip-join_chat-brightgreen.svg)](https://mithril.zulipchat.com)\n[![Build Status](https://travis-ci.org/MithrilJS/mithril-node-render.svg?branch=master)](https://travis-ci.org/MithrilJS/mithril-node-render)\n[![rethink.js](https://img.shields.io/badge/rethink-js-yellow.svg)](https://github.com/rethinkjs/manifest)\n![no dependencies](https://img.shields.io/badge/dependencies-none-brightgreen)\n\nUse mithril views to render server side\n\nDemo\n----\n\n[Usage Example](https://github.com/StephanHoyer/mithril-isomorphic-example/)\n\nInstallation\n------------\n\n```\nnpm install mithril-node-render\n```\n\nUsage\n-----\n\n```javascript\n// Make Mithril happy\nif (!global.window) {\n  global.window = global.document = global.requestAnimationFrame = undefined\n}\n\nvar m = require('mithril')\nvar render = require('mithril-node-render')\n\nrender(m('span', 'huhu')).then(function (html) {\n  // html === '\u003cspan\u003ehuhu\u003c/span\u003e'\n})\n\nvar html = render.sync(m('span', 'huhu'))\n// html === '\u003cspan\u003ehuhu\u003c/span\u003e'\n```\n\nAsync components\n----------------\n\nAs you see the rendering is asynchronous. It lets you await certain data from within `oninit` hooks.\n\n```javascript\nvar myAsyncComponent = {\n  oninit: function (node, waitFor) {\n    waitFor(new Promise(function (resolve) {\n      node.state.foo = 'bar'\n      resolve()\n    }))\n  },\n  view: function (node) {\n    return m('div', node.state.foo)\n  }\n}\n\nrender(myAsyncComponent).then(function (html) {\n  // html === '\u003cdiv\u003ebar\u003c/div\u003e'\n})\n```\n\nSync rendering\n--------------\n\nYou can also render synchronously. You just don't get the `waitFor` callback.\n\n```js\nvar myAsyncComponent = {\n  oninit: function (node, waitFor) {\n    // waitFor === undefined\n    new Promise(function (resolve) {\n      node.state.foo = 'bar'\n      resolve()\n    })\n  },\n  view: function (node) {\n    return m('div', node.state.foo)\n  }\n}\n\nvar html = render.sync(myAsyncComponent)\n// html === '\u003cdiv\u003ebar\u003c/div\u003e'\n```\n\nOptions\n-------\n\nOptionally pass in options as an object: `render(component, options)`.\n\nThe following options are supported:\n\n**escapeAttribute(value)**\n`Default: render.escapeAttribute`\nA filter function for attribute values. Receives value, returns what is printed.\n\n**escapeText(value)**\n`Default: render.escapeText`\nA filter function for string nodes. Receives value, returns what is printed.\n\n**strict**\n`Default: false`\nSet this to true to close all empty tags automatically. Default is standard HTML mode where tags like `\u003cbr\u003e` and `\u003cmeta\u003e` are allowed to implicitly close themselves. This should be set to `true` if you're rendering XML-compatible HTML documents.\n\n**xml**\n`Default: false`\nSet this to true to render as generic XML instead of (possibly XML-compatible) HTML. Default is HTML mode, where children of void elements are ignored. This implies `strict: true`.\n\n\nSee also\n--------\n\n* [Blog post](https://gist.github.com/StephanHoyer/bddccd9e159828867d2a) about isomorphic mithril applications\n* [Usage Example](https://github.com/StephanHoyer/mithril-isomorphic-example/blob/master/README.md)\n","funding_links":["https://opencollective.com/mithriljs"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmithriljs%2Fmithril-node-render","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmithriljs%2Fmithril-node-render","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmithriljs%2Fmithril-node-render/lists"}