Created
March 15, 2017 14:39
-
-
Save kaheglar/10afd535e4970ad9ec6accd62b6ceb03 to your computer and use it in GitHub Desktop.
Knockout server-side rendering.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const domino = require('domino'); | |
const html = ` | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<ul data-bind="foreach: list"> | |
<li data-bind="text: $data"></> | |
</ul> | |
</body> | |
</html> | |
`; | |
const window = domino.createWindow(html); | |
const document = window.document; | |
global.document = document; | |
global.window = window; | |
const ko = require('knockout'); | |
const viewModel = { | |
list: [ | |
'John', | |
'Paul', | |
'George', | |
'Ringo' | |
] | |
}; | |
const rootElement = document.documentElement; | |
ko.applyBindings(viewModel, rootElement); | |
console.log(rootElement.outerHTML); |
$ npm install domino knockout
$ node render-ko
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses https://github.com/fgnass/domino a Server-side DOM implementation based on Mozilla's dom.js