• Stars
    star
    2,794
  • Rank 16,298 (Top 0.4 %)
  • Language
    C++
  • License
    Other
  • Created almost 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A minimal WebAssembly virtual DOM to build C++ SPA (Single page applications)

:rage4: asm-dom :rage4:

experimental Build Status npm version npm downloads Join the chat at https://gitter.im/mbasso/asm-dom

A minimal WebAssembly virtual DOM to build C++ SPA (Single page applications)

Table of Contents

Motivation

asm-dom is a minimal WebAssembly virtual DOM to build C++ SPA (Single page applications). You can write an entire SPA in C++ and compile it to WebAssembly (or asmjs as fallback) using Emscripten, asm-dom will call DOM APIs for you. This will produce an app that aims to execute at native speed by taking advantage of common hardware capabilities, also, you can use your C/C++ code without any change, you haven't to create a binding layer to use it (as we have to do if we want to use a C++ lib from JS). Basically we are creating an app in C++ that call javascript if needed instead of the opposite. You can write only once in C++ and share as much code as possible with desktop/mobile apps and web site. If you want to learn more about performance, please see this.

How can I structure my application with asm-dom?

asm-dom is a low-level virtual DOM library. It is unopinionated with regards to how you should structure your application.

How did you come up with the concept of asm-dom?

At the beginning asm-dom is born from the idea to test the powerful of WebAssembly in a common use case that is not gaming, VR, AR or Image / video editing. Unfortunately, at the moment, GC/DOM Integration is a future feature πŸ¦„, so, asm-dom isn't totally developed in wasm. All interactions with the DOM are written in Javascript. This is a big disadvantage because of the overhead of the binding between JS and WASM, in the future asm-dom will be even more powerful, anyway results are satisfying.

Inline Example

#include "asm-dom.hpp"

using namespace asmdom;

int main() {
  Config config = Config();
  init(config);

  // 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 style="font-weight: bold">This is bold</span>
      and this is just normal 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: normal; font-style: italic"}
          }
        ),
        std::string("This is now italic type")
      ),
      h(" and this is just normal 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;
};

Getting started

asm-dom aims to be used from C++, however it can be used also from javascript, here you can find the doc of both:

Ecosystem

Here you can find a list of related projects:

  • gccx - CPX (JSX like syntax) support.
  • asm-dom-boilerplate - A simple boilerplate to start using asm-dom without configuration.

Examples

Examples are available in the examples folder.

Also, here is the list of third-party examples:

and online Demos:

Roadmap

  • Thunks support
  • asm-dom aims to be even more powerful with GC/DOM Integration. Unfortunately this is a future feature πŸ¦„, so, we have to be patient and wait a bit.

Change Log

This project adheres to Semantic Versioning.
Every release, along with the migration instructions, is documented on the Github Releases page.

Authors

Matteo Basso

Copyright and License

Copyright for portions of project asm-dom are held by:

  • Simon Friis Vindum, 2015 as part of project snabbdom
  • project snabbdom-to-html

All other copyright for project asm-dom are held by Matteo Basso.

Copyright (c) 2016, Matteo Basso.

asm-dom source code is licensed under the MIT License.

More Repositories

1

awesome-wasm

😎 Curated list of awesome things regarding WebAssembly (wasm) ecosystem.
8,801
star
2

react-decoration

A collection of decorators for React Components
JavaScript
630
star
3

react-wasm

Declarative WebAssembly instantiation for React
JavaScript
447
star
4

gccx

Transforms CPX (JSX like syntax) into asm-dom Virtual DOM
JavaScript
261
star
5

wasm-worker

Move a WebAssembly module into its own thread
JavaScript
257
star
6

natural-regex

Create regex from natural language
JavaScript
152
star
7

refraction

A guard that represents a central point of control in your application
JavaScript
151
star
8

ienumerable

Deep immutable, Lightweight Enumerable with superpowers
JavaScript
66
star
9

react-browser-detection

React component to detect browser
JavaScript
57
star
10

react-cssom

Css selector for React Components
JavaScript
57
star
11

asm-dom-boilerplate

A simple boilerplate to start using asm-dom without configuration.
Makefile
52
star
12

styled-components-test-utils

Test utils for styled-components compatible with jest, expect, chai and jasmine
JavaScript
46
star
13

react-https-redirect

Force a redirect to HTTPS when not on a local web server
JavaScript
34
star
14

react-http-request

React component exposes network request functionality
JavaScript
19
star
15

script-wasm

Require WebAssembly modules using script tag
JavaScript
14
star
16

watpl

Create WebAssembly modules using template strings
JavaScript
13
star
17

mandrake

Facility, Prosperity and Maintainability.
Elixir
9
star
18

refraction-react

React bindings for refraction
JavaScript
6
star
19

make-watch

Continuously run Make in watch mode
JavaScript
4
star
20

awesome-refraction

A collection of awesome things regarding Refraction ecosystem
4
star
21

spaceSurvival

A simple, free, open source game designed with Phaser.io
JavaScript
3
star
22

refraction-player

An events player for refraction
JavaScript
2
star
23

natural-regex-cli

Command line tool for natural-regex
JavaScript
2
star
24

npm-react-boilerplate

Minimal dev environment to build React modules
JavaScript
1
star
25

emscripten-issue-6442

Makefile
1
star
26

cleanChat

A simple free chat
JavaScript
1
star
27

se-assignment-8

Software Engineering course @ USI - Assignment 8
Java
1
star