asm-dom 介绍
用于构建C ++ SPA的最小WebAssembly虚拟DOM(单 页面 应用程序) ?,您可以使用Emscripten在C ++中编写整个SPA并将其编译为WebAssembly(或asmjs作为后备),asm-dom将为您 调用 DOM API。
asm-dom是 一个 低级虚拟DOM库。 最初,asm-dom诞生于在 一个 不是游戏,VR,AR或图像/视频编辑的常见用例中测试WebAssembly强大 功能 的想法。asm-dom并非在ism中完全发展。与DOM的所有交互都是用JavaScript编写的。这是 一个 很大的缺点,因为js和WASM之 间的 绑定开销,在未来asm-dom将更加强大,无论如何结果是令人满意的。?
例子
#include "asm-dom.hpp"
using namespace asmdom;
int main() {
Con fig con fig = Con fig ();
init(con fig );
// asm-dom can be used with a jsX like Syntax thanks to gccx
VNode* vnode = (
<div
onclick={[](emscripten::val e) -> bool {
emscripten::val::global("console").call<void>("log",emscripten::val("clicked"));
return true;
}}
>
<span font-weight: bold">This is bold</span>
and this is just nor mal text
<a href="/foo">I'll take you places!</a>
</div>
);
// Patch into empty DOM element – this modifies the DOM as a side effect
patch(
emscripten::val::global("document").call<emscripten::val>(
"getElementById",
std::string("root")
),
vnode
);
// without gccx
VNode* newVnode = h("div",
Data(
Callbacks {
{"onclick",[](emscripten::val e) -> bool {
emscripten::val::global("console").call<void>("log",emscripten::val("another click"));
return true;
}}
}
),
Children {
h("span",
Data(
Attrs {
{"style","font-weight: nor mal; font-style: italic"}
}
),
std::string("This is Now italic type")
),
h(" and this is just nor mal text",true),
h("a",
Data(
Attrs {
{"href","/bar"}
}
),
std::string("I'll take you places!")
)
}
);
// Second `patch` invocation
patch(vnode,newVnode); // asm-dom efficiently updates the old view to the new state
return 0;
};
网站地址 : https://mbasso.github.io/asm-dom
GitHub: https://github.com/mbasso/asm-dom
网站描述: 一个 极小的WebAssembly虚拟DOM专注于 性能
asm-dom官方网站
官方网站: https://mbasso.github.io/asm-dom
如果觉得 网站内容还不错,欢迎将 网站 推荐给程序员好友。