GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — knowledge/virtual-dom.md at master · AndCollectiom/knowledge

Expand file tree

/

virtual-dom.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
74 lines (61 loc) · 1.99 KB
/

virtual-dom.md

Copy path

File metadata and controls

74 lines (61 loc) · 1.99 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

virtual-dom

   DOM
Raw Input  ->  Input
                 ▾
               State
                 ▾
Raw Output <-  Render

source

Input

dom-delegator
value-event/*
  • mercury/issues/renaming-handles-and-events

State

state-atom
state-channel
  • mercury/index.js/state

Render

virtual-dom/h
vdom-thunk
virtual-raf

Wrapping vanilla DOM nodes

Sometimes you want to wrap an external piece of DOM machinery inside your virtual-dom application. This is done using widgets. It allows you to create a custom.

module.exports = GoogleMapWidget

function GoogleMapWidget(initialPosition) {
  if (!(this instanceof GoogleMapWidget)) {
    return new GoogleMapWidget(initialPosition)
  }
  this.type = 'Widget' // setting the type prevents errors
  this.position = initialPosition
}

GoogleMapWidget.prototype.init = function () {
  var elem = document.createElement('div')
  this.map = GoogleMap(elem)
  this.map.setPosition(this.position)
  return elem
}

GoogleMapWidget.prototype.update = function (prev, elem) {
  this.map = this.map || prev.map
  this.map.setPosition(this.position)
}

The first time init() is called it should return a DOM element. The DOM element can be mutated freely as virtual-dom will never touch it.

update() is called if the widget was available in the previous tree, and gives a chance to update state through this. In practice this means that an immutable state object or data store can be queried for the latest data and the new render can take place based on that. So unlike in React, virtual-dom doesn't rely on new properties to flow through to update widgets.

  • virtual-dom/docs/widgets
  • mercury/docs/how-to-do-custom-rendering
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.