Opened 6 years ago

Closed 6 years ago

#16682 closed enhancement (fixed)

arrays cannot be synced, because equals fails

Reported by: Stefan Meyer Owned by: Ed Chatelain
Priority: undecided Milestone: 1.9
Component: DojoX MVC Version: 1.8.3
Keywords: Cc:
Blocked By: Blocking:

Description

I triede to bind an array to the dojox.form.CheckedMultiSelect?. It turns out that any update will provoke an infinite loop because array equality checks fail and therefore both ends fire value changed events.

The problem is sync.equals which does not work for arrays and objects. Maybe dojox.mv.equals should be used here.

Change History (7)

comment:1 Changed 6 years ago by Akira Sudoh

Support for collection (array) requires special code in widget implementation, therefore limited number of widgets support it. (An example supporting array is dojox/mvc/WidgetList)

dojox/form/CheckedMultiSelect seems to mangle the value attribute's value, which does not work well with the code checking value going back and forth. Not sure it's the issue this ticket reports, but if it's the case - There is an extension point in dojox/mvc/sync library so that such check can be changed, by doing something like below:

var sync = require("dojox/mvc/sync"),
    origEquals = sync.equals;
sync.equals = function(src, dst){
    var orig = origEquals(src, dst);
    if(orig){ return true; }
    if(!(src || {}).splice || !(dst || {}).splice || src.length != dst.length){ return false; }
    for(var i = 0, l = src.length; i < l; ++i){
        if(src[i] != dst[i]){ return false; }
    }
    return true;
};

It avoids infinite loop by setting value attribute with data binding, though it does not make the widget respond to change in array like push() call.

comment:2 Changed 6 years ago by Stefan Meyer

Is the option to define the equals operation also available for dojo.mvc.at? Like this:

 at(stateful,property).equals(myEqualsImplementation)

comment:3 Changed 6 years ago by Akira Sudoh

Yes that can be done.

comment:4 Changed 6 years ago by Stefan Meyer

Could you be more specific about how that can be done. I did not find it in the documentation.

comment:6 Changed 6 years ago by Ed Chatelain

In [30885]:

refs #16682 Support for setting equals callback per sync/at . !strict Thanks Akira Sudoh (IBM, CCLA).

comment:7 Changed 6 years ago by Ed Chatelain

Milestone: tbd1.9
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.