Where can I find `BindingEngine` in Aurelia 2?

Hi All.

I am trying to upgrade a plugin from Aurelia 1 to Aurelia 2. In my Aurelia 1 plugin I am using
the BindingEngine to observe a specific property on a bound object (via bindable). Like this:

import { bindable, BindingEngine, Disposable } from 'aurelia-framework';

@customElement('pagination')
@inject(BindingEngine)
export class PaginationComponent {

    @bindable({
        defaultBindingMode: bindingMode.twoWay,
        changeHandler: 'dataChange'
    }) public request: MyRequest;

    constructor(
        private bindingEngine: BindingEngine
    ) { }

    public attached(): void {
         this.bindingEngine
            .propertyObserver(this.request, 'currentPage')
            .subscribe(() => this.dataChange());
    }

    private dataChange(): void {
        // Logic
    }
}

I can’t find anything on that in Aurelia 2 though. Can anyone point me in the right direction?

1 Like

It looks like you’ll just use ObserverLocator

There is even an easier way to observe property with the @watch decorator. Here is the docmentation for that: Watching data - The Aurelia 2 Docs

3 Likes

That looks nice, but from a porting standpoint, observerLocator will be the least amount of change. I’ll probably change to using @watch over time

Thanks guys! I’ll look into both suggestions!

That’s an elegant solution :slightly_smiling_face: Really loving Au2’s simplicity

1 Like