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

Latest commit

 

History

History
67 lines (52 loc) · 1.81 KB

plugins.md

File metadata and controls

67 lines (52 loc) · 1.81 KB

Plugins

Overview

Plugins, usually, add functionality to a view-model. There is no strictly defined scope for a plugin but there are typically several types of plugins you can write:

  • Add a group of components
  • Add a group of directives
  • Add some components methods by attaching them to components prototype.
  • Add providers to the view.providers object
  • Whatever you think it is useful

A plugin can be an object with the install method or a simple function (same signature as the install method).

var myPlugin = {
    install: function (vm) {
        // add a component
        vm.addComponent('alert', {
            model: {
                style: "alert-info",
                text: "Hi! this is a test!"
            },
            render: function () {
                return view.htmlElement('<div class="alert" :class="style" d3-html="text"></div>');
            }
        });
        // add another component
        vm.addComponent('foo', ...);

        // add a custom directive
        vm.addDirective('mydir', {
            refresh: function (model, value) {
                ...
            }
        });

        // inject a property to the root view
        vm.myCustomProperty = [];
    }
}

Install Plugins

Plugins are installed in a view via the chainable use method:

var vm = d3.view();
vm.use(myPlugin).use(anotherPlugin);

The use method can only be used before the view vm is mounted into the dom.