Property observer in @noView class

I want to use the BindingEngine property observer within a regular JavaScript class, not a View Model as in

My class is decorated with @noView ( and it seems that when I try to get hold of a BindingEngine via a static inject() as in that example, or using the @inject decorator as in, any additional parameters I add to the constructor ( are giving me undefined.

I could set up the property observation in a view model, such as regions-list.js above, but it seems that it this should be the responsibility of the underlying model object.

Many thanks,

1 Like

Hi @will-moore.

Have you tried this:

It seems to me that you want some observable properties. If that’s all what you need, then you can simply use the @observable decorator on your property. That should work, irrespective of whether your class is a view model, or not. And you don’t have to bother about the BindingEngine. That is useful where you don’t have access to source code of the class where you want to observe property, or don’t want to put Aurelia dependency for whatever reason.

1 Like

Thanks for your help.
So, the @observable is just for observing changing properties of a class?
My class has a property called data which is a Map where the values are regular JS objects (created when I dynamically load some JSON data). I want to observe the ‘show’ property of every object in this Map. The UI is a bit like a hierarchy browser - loading ‘folders’ then listening for each one to be expanded -> then loading child objects.

Currently I’m setting this up using the bindingEngine like this in the model view:

    // for each object in the Map, observe the 'show' property., roi_id) => {
        this.observers.push(this.bindingEngine.propertyObserver(roi, 'show').subscribe(
            (newValue, oldValue) => {
                this.handleRoiShow(newValue, oldValue, roi_id);

Using the subscribe() closure allows me to pass an additional roi_id parameter to the handler.
This is working but I would prefer it if the regions_info class itself was able to setup these observers.

Many thanks,

1 Like

Now I think that I have understood the issue. I think instead of using a raw object literal when setting the value of a region id in the map, it might be easier to use a class like this.

class Region {
  @observable public show: boolean = false;
  public deleted: number = 0,

  public constructor(
    public name: string,
    public shapes: Shapes, // assuming the Shapes type exists

  private showChanged(){
    // handle the change event here;
    // or publish the `{name}:show:changed` event from here to notify the actual handler(s).

Then you can use the following to set values in the map., new Region(name, shapes));

I have used TS syntax, but I think you can transfer that to JS as well. Does this approach help you?


Thanks for that. I implemented it in