Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Latest commit

 

History

History
61 lines (48 loc) · 1.88 KB

view.md

File metadata and controls

61 lines (48 loc) · 1.88 KB

View

Introduction

A view is the entry-point for creating reactive d3 based web applications.

var vm = d3.view({
    model: {...},
    components: {...},
    directives: {...}
});

Mount

When a new view is created with the statement above, no binding with the DOM has occurred and the view is in an unmounted state

vm.isMounted    //  undefined
vm.el           //  undefined
vm.sel          //  undefined

To bind a view object into an HTML element one uses the view.mount method. The view only affect element and its children. This method should be called once only for a given view object:

vm.mount('#app').then(() => {
    vm.logWarn('View mounted');
    vm.isMounted    //  true
});

The element can be a W3c selector string, an HTML element or a d3 selection. The mount method always return a Promise resolved once the view is fully mounted.

Plugins

Views are extendible via plugins. To add plugins into a view

vm.use(myPlugin);

This method can be called several times with as many plugins as one needs, however it can be called only before the view is mounted into an element.

View API

With the exception of the mount and use methods, the view API is available once the view has been mounted to an HTML element, i.e. once the mount method has been called. The API is exactly the same as the component API.