Opened 3 years ago

Closed 3 years ago

#18883 closed defect (fixed)

StatefulArray.watchElements provide inconsistent argiments values (adds and removals)

Reported by: Rozaev Viktor Owned by: Ed Chatelain
Priority: undecided Milestone: tbd
Component: DojoX MVC Version: 1.11.2
Keywords: Cc:
Blocked By: Blocking:

Description

The problem description: StatefulArray? has watchElements method, that method call callback with arguments index, removals and adds.

When you add element or remove element from StatefulArray?, then removals and adds will be arrays.

But if you sort StatefulArray?, then removals and adds has value undefined.

It's looks like inconsistent API, we get Exception in our project because of that.

Maybe removals and adds should contains empty arrays?

Change History (6)

comment:1 Changed 3 years ago by Akira Sudoh

StatefulArray does not provide removals/adds for sort(), etc. operations as it tends to affect many (often all) array elements and therefore comparison with the original array would be costful.

comment:2 in reply to:  1 Changed 3 years ago by Rozaev Viktor

You are right, but we not need provide any elements.

My point is: when you get undefined in removals/adds it really unexpected behavior.

Docs (https://dojotoolkit.org/reference-guide/1.10/dojox/mvc/StatefulArray.html) says:

dojox/mvc/StatefulArray also has watchElements() function, that allows to watch for removals/adds of array elements.

It looks like removals and adds always must be array. sort() and etc. operations not adds or removals elements, so we can just provide empty array is looks consistent.

Replying to asudoh:

StatefulArray does not provide removals/adds for sort(), etc. operations as it tends to affect many (often all) array elements and therefore comparison with the original array would be costful.

Version 0, edited 3 years ago by Rozaev Viktor (next)

comment:3 Changed 3 years ago by Rozaev Viktor

comment:4 Changed 3 years ago by Michael J Van Sickle

The PR looks good, doesn't affect the test results for dojox/mvc and does seem to align the API since the docs imply a very symmetrical interface that this now provides.

comment:5 Changed 3 years ago by dylan

Ok, I suggest we land it then!

comment:6 Changed 3 years ago by Michael Van Sickle <mvansickle@…>

Resolution: fixed
Status: newclosed

In 8d4249b/dojox:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 
Note: See TracTickets for help on using tickets.