Giter VIP home page Giter VIP logo

duet-example-app's Introduction

duet example app

A simple counter app, built using duet.

screenshot

Getting started

  1. Install dependencies and start development server:
$ npm install
$ npm run dev
  1. Visit http://localhost:8000

  2. Open your browser's developer console and watch the messages fly.

    • Messages sent from the worker (app) thread to the main thread are:
      • VIRTUAL_DOM::CREATE: Creates a root node in the DOM, resulting from the creation of a new virtual DOM.
      • VIRTUAL_DOM::PATCH: A patch for the DOM, which is sent every time the worker's virtual DOM is updated (due the app state updates).
      • CSJS::STYLES: A block of styles, resulting from the import of a CSJS module inside a component. These blocks will be written as separate stylesheets in the document.head.
      • LOCALFORAGE::REQUEST: A call to localForage (either getItem or setItem) to load/save state, if IndexedDB is not available inside the worker.
    • Messages sent from the main thread to the worker thread are:
      • VIRTUAL_DOM::EVENT: A DOM event which corresponds to an event handler created while rendering your app's virtual DOM. If the element is a control, its value will also be passed through.
      • LOCALFORAGE::RESPONSE: A response from localForage, along with a reference to a response handler inside the worker so that it can be resolved.

These messages are enabled by channels supplied to duet when it was initialised, and sent when you use their respective modules in the app.

const duet = require('duet');
const csjs = require('duet-csjs/channel');
const lf   = require('duet-localforage/channel');
const vdom = require('duet-virtual-dom/channel');
const app  = require('./app');

duet([csjs, lf, vdom], app);

This app was built with: duet-virtual-dom, duet-csjs and duet-localforage, which all provide channels built with duet-channel.

Suggestions

  • In src/index.js, comment out the logger option to disable debug messages.
  • In src/index.js, un-comment the forceShim option to force the app to run entirely the main thread, simulating how browsers without web worker support will perform.
  • Create a production build of the app commenting out both options in src/index.js, then running:
$ npm run build

This will remove source maps and minify your entry script (with duet-build), showing how small the app's footprint actually is (especially when gzipped).

duet-example-app's People

Contributors

colingourlay avatar rtsao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

rtsao

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.