Download Latest Version Api and internals improvement source code.tar.gz (3.1 MB)
Email in envelope

Get an email when there's a new version of asm-dom

Home / 0.6.0
Name Modified Size InfoDownloads / Week
Parent folder
Fragment and ref source code.tar.gz 2018-06-18 2.3 MB
Fragment and ref source code.zip 2018-06-18 2.4 MB
README.md 2018-06-18 2.3 kB
Totals: 3 Items   4.7 MB 0

Features

  • ref: a special callback that provides a way to access DOM nodes
  • Fragments: a way to group a list of children without adding extra nodes to the DOM or to improve performance (check out DocumentFragments)

Here you can find an example of both:

:::js
// ref
// C++
VNode* vnode = h("div",
  Data(
    Callbacks {
      {"red", refCallback}
    }
  )
);

// with gccx
VNode* vnode = <div ref={refCallback} />

// javascript
const vnode = h("div", {
  ref: node => {
        console.log(node)
    },
});


// Fragments
// C++
asmdom::VNode* vnode = (
    h("",
        Children {
            h("div", std::string("Child 1")),
            h("div", std::string("Child 2")),
            h("div", std::string("Child 3"))
        }
    )
);

// with gccx
VNode* vnode = (
    <Fragment>
        <div>Child 1</div>
        <div>Child 2</div>
        <div>Child 3</div>
    </Fragment>
);

// javascript
const vnode = h('', [
  h('div', 'Child 1'),
  h('div', 'Child 2'),
  h('div', 'Child 3')
]);

Breaking changes

If you want to delete an entire vnode tree from memory as you do before, you cannot use the keyword delete but you have to use the new api deleteVNode. Keyword delete now deletes a single vnode from memory:

:::c++
VNode* child1 = h("h1", string("Headline"));
VNode* child2 = h("p", string("A paragraph"));
VNode* vnode = h("div",
  Data(
    Attrs {
      {"id", "root"}
      {"style", "color: #000"}
    }
  ),
  Children {
    child1,
    child2,
  }
);

// delete vnode, child1 and child2 from memory
// asm-dom >= 0.6.0
deleteVNode(vnode);
// asm-dom < 0.6.0
// delete vnode;

// delete vnode but not child1 and child2 from memory
// asm-dom >= 0.6.0
// delete vnode;
// asm-dom < 0.6.0
// You cannot do that in asm-dom@0.5.0
Source: README.md, updated 2018-06-18