Page 1 of 1

Stock item add/remove timing

Posted: 10 June 2020, 17:11
by RavingWanderer
I have a Stock displaying a hand full of cards. Sometimes, when cards are added to the hand, I would like to highlight them.

I have code that looks roughly like this:

Code: Select all

dojo.connect( this.playerHand, 'onChangeSelection', this, 'onHandSelectionChanged' );
this.playerHand.addToStockWithId(...,mycardid,...);
dojo.ready(dojo.hitch(this, 'makeSelection', mycardid));

makeSelection: function (mycardid)
{
  console.log(mycardid);
   this.playerHand.selectItem(mycardid);
}

onHandSelectionChanged: function(ctrl, item_id)
{
  console.log('onHandSelectionChanged');
  console.log(item_id);
}
The dojo.ready surrounding the makeSelection is my attempt to delay processing of the selection, but it seems to make no difference whether I call makeSelection directly there or delay it. When makeSelection is called in this setting, the onHandSelectionChanged callback says the item_id is undefined. When called in a different setting, not associated with a recent addition of the relevant cards to the hand, the callback reports the correct item_id.

It seems to me there may be a timing issue related to this. How do I best deal with it?