Skip to content

Commit

Permalink
Merge 748ac12 into 58d43f5
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasso committed Apr 15, 2018
2 parents 58d43f5 + 748ac12 commit 6c723bd
Show file tree
Hide file tree
Showing 65 changed files with 1,990 additions and 853 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ jobs:
branches:
only:
- master
if: tag =~ ^\d+\.\d+\.\d+
after_success: echo "Website online"
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ Also, here is the list of the online Demos:

## Roadmap

- [ ] create asm-dom boilerplate
- [ ] Thunks support
- [ ] asm-dom aims to be even more powerful with [GC/DOM Integration](http://webassembly.org/docs/future-features/). Unfortunately this is a future feature 🦄, so, we have to be patient and wait a bit.

Expand Down
Binary file modified benchmarks/compiled/app.bc
Binary file not shown.
Binary file modified benchmarks/compiled/app.o
Binary file not shown.
138 changes: 138 additions & 0 deletions benchmarks/compiled/asmjs/app.asm.js

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions benchmarks/compiled/wasm/app.js

Large diffs are not rendered by default.

Binary file modified benchmarks/compiled/wasm/app.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions benchmarks/src/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {
));
}
for (int i = 0; i < 10000; ++i) {
delete children[i];
deleteVNode(children[i]);
}

return 0;
Expand All @@ -61,7 +61,7 @@ void create() {
})
}
);
delete vnode;
deleteVNode(vnode);
}
};

Expand Down
Binary file modified compiled/asm-dom.a
Binary file not shown.
Binary file modified compiled/asm-dom.bc
Binary file not shown.
Binary file modified compiled/asm-dom.o
Binary file not shown.
23 changes: 11 additions & 12 deletions compiled/asmjs/asm-dom.asm.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions compiled/wasm/asm-dom.js

Large diffs are not rendered by default.

Binary file modified compiled/wasm/asm-dom.wasm
Binary file not shown.
63 changes: 40 additions & 23 deletions cpp/Diff/diff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ namespace asmdom {
const std::string emptyString;

void diffAttrs(VNode* __restrict__ const oldVnode, VNode* __restrict__ const vnode) {
if (oldVnode->data.attrs.empty() && vnode->data.attrs.empty()) return;
Attrs& oldAttrs = oldVnode->data.attrs;
Attrs& attrs = vnode->data.attrs;

for (auto& it : oldVnode->data.attrs) {
if (!vnode->data.attrs.count(it.first)) {
if (oldAttrs.empty() && attrs.empty()) return;

for (const auto& it : oldAttrs) {
if (!attrs.count(it.first)) {
EM_ASM_({
window['asmDomHelpers']['domApi']['removeAttribute'](
$0,
Expand All @@ -24,8 +27,8 @@ namespace asmdom {
}
}

for (auto& it : vnode->data.attrs) {
if (!oldVnode->data.attrs.count(it.first) || oldVnode->data.attrs[it.first] != it.second) {
for (const auto& it : attrs) {
if (!oldAttrs.count(it.first) || oldAttrs[it.first] != it.second) {
#ifndef ASMDOM_JS_SIDE
if (it.second == "false") {
EM_ASM_({
Expand Down Expand Up @@ -54,29 +57,32 @@ namespace asmdom {

#ifndef ASMDOM_JS_SIDE

void diffProps(VNode* __restrict__ const oldVnode, VNode* __restrict__ const vnode) {
if (oldVnode->data.props.empty() && vnode->data.props.empty()) return;
void diffProps(const VNode* __restrict__ const oldVnode, const VNode* __restrict__ const vnode) {
const Props& oldProps = oldVnode->data.props;
const Props& props = vnode->data.props;

if (oldProps.empty() && props.empty()) return;

emscripten::val elm = emscripten::val::global("window")["asmDomHelpers"]["nodes"][vnode->elm];

EM_ASM_({
window['asmDomHelpers']['nodes'][$0]['asmDomRaws'] = [];
}, vnode->elm);

for (auto& it : oldVnode->data.props) {
if (!vnode->data.props.count(it.first)) {
for (const auto& it : oldProps) {
if (!props.count(it.first)) {
elm.set(it.first.c_str(), emscripten::val::undefined());
}
}

for (auto& it : vnode->data.props) {
for (const auto& it : props) {
EM_ASM_({
window['asmDomHelpers']['nodes'][$0]['asmDomRaws'].push(Module['UTF8ToString']($1));
}, vnode->elm, it.first.c_str());

if (
!oldVnode->data.props.count(it.first) ||
!it.second.strictlyEquals(oldVnode->data.props.at(it.first)) ||
!oldProps.count(it.first) ||
!it.second.strictlyEquals(oldProps.at(it.first)) ||
(
(it.first == "value" || it.first == "checked") &&
!it.second.strictlyEquals(elm[it.first.c_str()])
Expand All @@ -87,11 +93,14 @@ namespace asmdom {
}
};

void diffCallbacks(VNode* __restrict__ const oldVnode, VNode* __restrict__ const vnode) {
if (oldVnode->data.callbacks.empty() && vnode->data.callbacks.empty()) return;
void diffCallbacks(const VNode* __restrict__ const oldVnode, const VNode* __restrict__ const vnode) {
const Callbacks& oldCallbacks = oldVnode->data.callbacks;
const Callbacks& callbacks = vnode->data.callbacks;

if (oldCallbacks.empty() && callbacks.empty()) return;

for (auto& it : oldVnode->data.callbacks) {
if (!vnode->data.callbacks.count(it.first)) {
for (const auto& it : oldCallbacks) {
if (!callbacks.count(it.first) && it.first != "ref") {
EM_ASM_({
var key = Module['UTF8ToString']($1).replace(/^on/, "");
var elm = window['asmDomHelpers']['nodes'][$0];
Expand All @@ -113,8 +122,8 @@ namespace asmdom {
}
}, vnode->elm, reinterpret_cast<std::uintptr_t>(vnode));

for (auto& it : vnode->data.callbacks) {
if (!oldVnode->data.callbacks.count(it.first)) {
for (const auto& it : callbacks) {
if (!oldCallbacks.count(it.first) && it.first != "ref") {
EM_ASM_({
var key = Module['UTF8ToString']($1).replace(/^on/, "");
var elm = window['asmDomHelpers']['nodes'][$0];
Expand All @@ -127,20 +136,28 @@ namespace asmdom {
}, vnode->elm, it.first.c_str());
}
}

if (callbacks.count("ref")) {
bool(*const* callback)(emscripten::val) = callbacks.at("ref").target<bool(*)(emscripten::val)>();
bool(*const* oldCallback)(emscripten::val) = oldCallbacks.count("ref") ? oldCallbacks.at("ref").target<bool(*)(emscripten::val)>() : NULL;
if (callback == NULL || oldCallback == NULL || *oldCallback != *callback) {
callbacks.at("ref")(
emscripten::val::global("window")["asmDomHelpers"]["nodes"][vnode->elm]
);
}
}
};

#endif

void diff(VNode* __restrict__ const oldVnode, VNode* __restrict__ const vnode) {
diffAttrs(oldVnode, vnode);

#ifdef ASMDOM_JS_SIDE
EM_ASM_({
window['asmDomHelpers']['diff']($0, $1, $2);
}, reinterpret_cast<std::uintptr_t>(oldVnode), reinterpret_cast<std::uintptr_t>(vnode), vnode->elm);
#endif

diffAttrs(oldVnode, vnode);

#ifndef ASMDOM_JS_SIDE
#else
diffProps(oldVnode, vnode);
diffCallbacks(oldVnode, vnode);
#endif
Expand Down
Loading

0 comments on commit 6c723bd

Please sign in to comment.