Register to event listener for object in a form

2
Hi everyone, I have an observation like this: I have a mendix form with datasource is an object. In the form, i have 2 dataview for the same object. So it seems that for that setting, mendix registers an event, "rollback" for example, 3 times. That's reasonable so far. Now, my widget calls the form. My widget subscribes for changes of the object in the form. As a result, when I cancel the form, the function which will be triggered when the object changed, will be call 3 times. I would like to know if any is wrong in my observation (may be other factors influcence)? And if it is correct, do you think it is reasonable? Since my widget will do many things for a change, I want to minimize the number of callback as much as possible. Regards.
asked
4 answers
0

Do you need to know if the object changes or just a particular attribute? If it is the attribute you are interested in you can limit the amount of callbacks by subscribing to changes on the attribute level.

answered
0

I like how you specifically ask if the behaviour is reasonable, as this leaves a lot of room for discussion and interpretation of what you think is reasonable.

Is this behaviour to be expected given how Mendix works? Yes.

Is there a lot of room for improvement? Definitely.

If you would want to work around the issue in your widget you would run into the problem that your widget doesn't know that both changes have been triggered by the same user action. An improvement that I think might be relatively simple to implement is if all events would exist in the context of a specific user action. In this case you could easily detect that both events were triggered by the same user action (clicking the cancel button) and ignoring all but the first change event.

answered
0

I can only comment about the case of "rollback" action as I am quite sure about it. With the above setting, my widget will trigger the callback of rollback three times as the rollback is registered three times in the form. The situation could be improved if the platform knows that those three rollbacks will cause the same effects to everything else, so It will send rollback signal only one time.

answered
0

its kind of late but you should have added a subscription like this:

var objectHandle = this.subscribe({ guid: this.contextObj.getGuid(), callback: dojoLang.hitch(this, function (guid) { this.updateRendering(); }) });

answered