Binding to 'data' (.ofObject())

I have a node template that looks like this:

   $(go.Node,
        ...,
        $(go.Picture,
            { name : "PIC" },
            new go.Binding("element", "data", data => { return this.createCanvasForData(data); }).ofObject()));

It uses a bit of a kludge to get ahold of the entire node data object for the node under construction: a binding on ‘data’ together w/ ofObject. The createCanvasForData() call needs several properties from data; it’s for this reason that binding to a single property w/in data doesn’t suffice.

So, this works, but it results in createCanvasForData() being called twice for every node that is created using the template, when a model is loaded. It’s not hard to imagine ‘data’ being set at the end of the bottom-up copy / construction of a new node, or something of that kind.

So, a few questions:

Is it possible to refer to ‘data’ during construction of a node via a template, other than through a binding on ‘data’ itself? I don’t really need or want a binding here, in the sense of monitoring changes to ‘data’; this is exclusively for creation of the element in the first place.

Is it possible to get the effect of a binding that refers to several properties in tandem? I’m not at liberty, I think, to aggregate the properties of interest into a single property, because the most important one is the category of the node.

Any other suggestions for how I might get this effect?

Thanks,

-Luddy

The order in which Bindings are evaluated is not defined, so you cannot depend on them being evaluated in any particular order or any number of times.

Try using this instead:

$(go.Picture, { name: "PIC" },
    new go.Binding("element", "", data => this.createCanvasForData(data)))

Perfect! Thanks.

-Luddy