addArrayItem duplicating values?


Within my main model object I have an array that must be unique and this array is, of course linked to a panel that will show the contents of this array.

Since the array must be unique, I decided to implement some sort of “set” (extending array and overriding its push method) that will check if the added item already exists before adding it, if it already exists, it will not do anything and return.

At some point a duplicate value is added to this collection, the collection works as expected, it does not add anything to the array, however the value appears duplicated.

Internally, addArrayItem ends up calling Array.splice, not Array.push.

That said, it would be better if you checked for the existence of something in the array before adding it, since calling addArrayItem will raise changed events that you don’t really want.

Is there anyway to raise these events manually, as in “if my adding succeeds raise these events”? The idea is to make this addition undoable AND of course refreshing the binding and showing the updated model.

EDIT: Would manually raising a ChangedEvent suffice?

There is Model.raisedChangedEvent.

But I still think it would be better to check if something is in the array before adding it. Then you can just skip adding it rather than fiddling with events.