如何连接虚拟超脚本、超脚本助手和主循环

How to wire up virtual-hyperscript, hyperscript-helpers, and main-loop

我正在查看 example by substack 使用超脚本、主循环和 hyperx。

我想使用 hyperscript-helpers 重新创建此示例以获得类似于 Elm 的代码。该模块说它支持 hyperscriptvirtual-hyperscript,所以我正在尝试 virtual-hyperscript

我的代码如下所示:

var vdom = require('virtual-dom')
var vh = require('virtual-hyperscript');
var hh = require('hyperscript-helpers')(vh);
var main = require('main-loop')

var div  = hh.div;
var span = hh.span;
var h1   = hh.h1;

var loop = main({ times: 0 }, render, vdom)
document.querySelector('#content').appendChild(loop.target)

function render(state) {
  return h1('title');
}

它给我一个错误:

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

怎么了?我假设有些地方没有正确连接,因为

console.log(loop.target) //null

如果有帮助,我可以 post 我的 html 和我正在使用的 browserify 构建命令

virtual-hyperscript 移动到 https://github.com/Matt-Esch/virtual-dom/tree/master/virtual-hyperscript

请参阅 https://github.com/Raynos/virtual-hyperscript

中的自述文件

virtual-dom/h只是virtual-hyperscript的新版本。