All Projects → jcbrand → Backbone.vdomview

jcbrand / Backbone.vdomview

Licence: mit
VirtualDOM-aware Backbone View

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Backbone.vdomview

Tyto
manage and organise things
Stars: ✭ 662 (+2778.26%)
Mutual labels:  backbone, backbonejs
vdom
Simple JavaScript Virtual DOM
Stars: ✭ 17 (-26.09%)
Mutual labels:  virtual-dom, vdom
Mithril.js
A JavaScript Framework for Building Brilliant Applications
Stars: ✭ 13,062 (+56691.3%)
Mutual labels:  virtual-dom, vdom
Neo
Create blazing fast multithreaded Web Apps
Stars: ✭ 1,219 (+5200%)
Mutual labels:  virtual-dom, vdom
Vhtml
Render JSX/Hyperscript to HTML strings, without VDOM 🌈
Stars: ✭ 556 (+2317.39%)
Mutual labels:  virtual-dom, vdom
Omi
Front End Cross-Frameworks Framework - 前端跨框架跨平台框架
Stars: ✭ 12,153 (+52739.13%)
Mutual labels:  virtual-dom, vdom
Ng Vdom
(Developer Preview) A virtual-DOM extension for Angular, also work as React bridge.
Stars: ✭ 249 (+982.61%)
Mutual labels:  virtual-dom, vdom
Preact
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Stars: ✭ 30,527 (+132626.09%)
Mutual labels:  virtual-dom, vdom
Domvm
DOM ViewModel - A thin, fast, dependency-free vdom view layer
Stars: ✭ 581 (+2426.09%)
Mutual labels:  virtual-dom, vdom
Refractor
Lightweight, robust, elegant virtual syntax highlighting using Prism
Stars: ✭ 291 (+1165.22%)
Mutual labels:  virtual-dom, vdom
Asm Dom Boilerplate
A simple boilerplate to start using asm-dom without configuration.
Stars: ✭ 49 (+113.04%)
Mutual labels:  virtual-dom, vdom
Autoedit 2
Fast text based video editing, node Electron Os X desktop app, with Backbone front end.
Stars: ✭ 343 (+1391.3%)
Mutual labels:  backbone, backbonejs
Remark Vdom
plugin to compile Markdown to Virtual DOM
Stars: ✭ 44 (+91.3%)
Mutual labels:  virtual-dom, vdom
Val
VirtualDOM abstraction layer - give yourself better integration and full control over the DOM with any virtual DOM library that uses a Hyperscript-like API such as React and Preact.
Stars: ✭ 181 (+686.96%)
Mutual labels:  virtual-dom, vdom
Wonders
🌈 Declarative JavaScript framework to build command-line applications.
Stars: ✭ 34 (+47.83%)
Mutual labels:  virtual-dom, vdom
Asm Dom
A minimal WebAssembly virtual DOM to build C++ SPA (Single page applications)
Stars: ✭ 2,604 (+11221.74%)
Mutual labels:  virtual-dom, vdom
Puddles
Tiny vdom app framework. Pure Redux. No boilerplate.
Stars: ✭ 24 (+4.35%)
Mutual labels:  virtual-dom, vdom
Muve
Muve is a micro library for building interactive javascript applications.
Stars: ✭ 11 (-52.17%)
Mutual labels:  virtual-dom, vdom
backbone-tutorial-series
Source code generated in the Backbone.js tutorial series
Stars: ✭ 71 (+208.7%)
Mutual labels:  backbone, backbonejs
Lowlight
Virtual syntax highlighting for virtual DOMs and non-HTML things
Stars: ✭ 310 (+1247.83%)
Mutual labels:  virtual-dom, vdom

backbone.vdomview

This library provides a VirtualDOM-aware Backbone View, called Backbone.VDOMView.

It depends on snabbdom for the virtual-DOM implementation.

How to use

To use it, extend Backbone.VDOMView. Then, instead of implementing a render method in your view, add a toHTML method which returns the View's HTML as a string (or alternatively, add a toDOM method which returns a single DOM element).

The HTML of the toHTML must be structured so that there's a root element containing everything else. This root element is the view's top-level element, in other words, it's the DOM node represented by the this.el or this.$el attribute of the View.

React has a similar requirement that JSX returned by a component's render method should have a root node which contains everything else.

The rest will then be handled by VDOMView, which will automatically generate a diff between the view's current DOM element and new virtual-DOM node and then patch the actual DOM with this diff.

For example:

const MyView = Backbone.VDOMView.extend({

    tagName: 'span',
    className: 'vdom-span',

    toHTML () {
        return this.template(_.assign(this.model.toJSON()));
    }
});

The toHTML method

One important difference between Backbone.VDOMView and Backbone.View that should be noted is that the HTML being rendered (in the case of Backbone.VDOMView this is done in the toHTML method) should include the root element of the view.

So in the example above toHTML should return <span class="vdom-span"> ... </span> as the outer part of the HTML string.

This is different from normal Backbone.View classes, where your template will only return the inner part of the view element.

Event registration on virtual nodes

Snabbdom implements non-core functionality in separate modules.

Backbone.VDOMView makes use of all Snabbdom's modules except for the eventlisteners module.

The eventlisteners module allows you to add event listeners when creating a virtual node via the h method.

However Backbone.VDOMView doesn't use the h method of Snabbdom at all (it doesn't even include the code for it). Instead, it expects you to render the HTML for the view in the toHTML method, for example by using an underscore or lodash template.

There's therefore no way to attach these event listeners.

This way of registering event listeners is also in contrast to Backbone's declarative way of registering events, which is more the "Backbone way".

Backbone.VDOMView will make sure that these declaratively registered event listeners will remain active whenever the View's DOM representation changes.

The beforeRender and afterRender lifecycle methods

Backbone.VDOMView will call two lifecycle methods (if they exist). These are beforeRender and afterRender and are respectively called before and after toHTML is called.

Using Backbone.VDOMView without jQuery

Backbone can be used without jQuery by using Backbone.NativeView instead of Backbone.View.

If Backbone.NativeView is available, then the VDOMView will use that instead of Backbone.View.


Backbone.VDOMView is used in converse.js.

If you have any questions, feel free to create an issue or contact me directly.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].