首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我可以将HyperX与Snabbdom一起使用吗

我可以将HyperX与Snabbdom一起使用吗
EN

Stack Overflow用户
提问于 2016-10-12 13:34:17
回答 1查看 233关注 0票数 1

HyperX是一个模块,它将标记的模板文字转换为hyperscript函数,就像virtual-dom中包含的函数一样。

Snabbdom使用一个类似hyperscript的函数来构建它的vdom,但是它的第二个参数是不同的。它的属性被各种“模块”使用,而不是属性;

代码语言:javascript
复制
h('div', {
  props: {title: someString}, // snabbdom/modules/props
  classes: {selected: isSelected}, // snabbdom/modules/class
  on: {click: doSomething}, // snabbdom/modules/eventlisteners
  style: {color: someColor} // snabbdom/modules/style
}, ['children']);

是否可以将hyperxsnabbdom的超脚本函数一起使用:

代码语言:javascript
复制
const h = require('snabbdom/h');
const hyperx = require('hyperx');
const hx = hyperx(h);

let vdom = hx`
  <div 
    title=${someString} 
    class-selected={isSelected} 
    on-click={doSomething} 
    style={({color: someColor})}
  >
   children
  </div>
`;
EN

回答 1

Stack Overflow用户

发布于 2016-10-18 23:54:07

是的,你可以的!

代码语言:javascript
复制
var snabbdom = require('snabbdom')
var patch = snabbdom.init([ // Init patch function with chosen modules
  require('snabbdom/modules/class'), // makes it easy to toggle classes
  require('snabbdom/modules/props'), // for setting properties on DOM elements
  require('snabbdom/modules/style') // handles styling on elements with support for animations  
])
var h = require('snabbdom/h')
var hyperx = require('hyperx')
var hx = hyperx(h)

var title = 'world'
var wow = [1,2,3]
var tree = hx`<div>
  <h1 y="ab${1+2}cd">hello ${title}!</h1>
  ${hx`<i>cool</i>`}
  wow
  ${wow.map(function (w, i) {
    return hx`<b>${w}</b>\n`
  })}
</div>` 
patch(document.body, tree)

检查 的工作代码

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39991162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档