aurelia.js - custom binding engine?

847 views Asked by At

found next phrase:

The system is pluggable and will let developers teach it new ways of observing properties so you can easily plug in custom model/view-model libraries such as Knockout, Breeze, Backbone, etc. which may have their own mechanism for storing properties and raising change events.

but not found examples - how it can be used (just because can't imagine how to "bind" some data to template in terms of aurelia, that not attached to document yet... and update this data later)

P.S. I need to write custom element using clusterize.js for aurelia.js and have no luck at this moment.

2

There are 2 answers

2
JotaBe On

Thanks to the comment by Crisim II Numeroano for saying that now there is another available github project: aurelia-knockout. (A previous one in https://github.com/jdanyow was deleted on dec 18th 2015).

The documentation that shows how to use ko with Aurelia: Aurelia's Adaptive Binding includes information on how to implement custom bindings for Aurelia. Perhaps you can get some inspiration from the Breeze plugin in this page to implement a new one for ko. Or contact the author of the deleted plugin.

2
Fabio On

Suppose you want to write a custom-element using a library called SomeLibrary:

import {inject, DOM} from 'aurelia-framework';
import SomeLibrary from './someLibrary';

@inject(DOM.Element)
export class MyElement {
    constructor(element) {
        this.element = element;
    }

    //this method will be called by convetions
    bind() {
       //Do your magic here, using SomeLibrary and this.element
    }
}

EDIT

There is no need to import DOM.Element anymore. A simple inject(Element) without any import statement should be enough.