PDA

View Full Version : [NOREPRO] Stop Store Event Bug



roycyang
11 Apr 2012, 12:28 PM
I have a store that I've been using for two different views. Sometimes when I go from one view to the other, I want to reset the store. I can remove the items but pending AJAX calls then load items intended for view 1 while I am looking at view 2. Here's what I've been using and it's been very inconsistent.



var store = Ext.data.StoreManager.lookup('Items');
store.removeAll(true) // clear the store
store.suspendEvents(); // shouldn't this stop all pending events, wiping them out?
store.resumeEvents(); // I want to then resume looking at events but sometimes it resumes the old events too. I know that it shouldn't based on the API docs


Thanks for your help

mitchellsimoens
11 Apr 2012, 12:35 PM
The name of the method is suspendEvents... is suspends the events.

roycyang
11 Apr 2012, 12:52 PM
Right, I hear you but in the API docs, it says:


suspendEvents (http://docs.sencha.com/touch/2-0/#!/api/Ext.mixin.Observable-method-suspendEvents)( Boolean (http://docs.sencha.com/touch/2-0/#!/api/Boolean) queueSuspended )Suspends the firing of all events. (see resumeEvents (http://docs.sencha.com/touch/2-0/#!/api/Ext.mixin.Observable-method-resumeEvents))
Parameters


queueSuspended : Boolean (http://docs.sencha.com/touch/2-0/#!/api/Boolean)Pass as true to queue up suspended events to be fired after the resumeEvents (http://docs.sencha.com/touch/2-0/#!/api/Ext.mixin.Observable-method-resumeEvents) call instead of discarding all suspended events.



It leads me to believe that if I do suspendEvents(false), then the events get discarded. My events are NOT getting discarded.

If that is not the intent, how do I "destroy" the store? I want to reuse the store but don't want any of the old data or events. Thanks.

Jamie Avins
11 Apr 2012, 2:38 PM
Seems like we need to clarify this quite a bit.

roycyang
11 Apr 2012, 3:04 PM
Okay good to know. Any suggestions on any alternatives in the meantime?

Jamie Avins
11 Apr 2012, 3:09 PM
This looks more like an async issue. Do you know if there are outstanding calls pending when you suspend the events?

roycyang
11 Apr 2012, 3:14 PM
So here's what's happening.

I open a search panel and load a keyword search into the store. The search somes takes 3-4 seconds to complete. If I leave the search panel and destroy it, then do another search using the same store, I will end up getting the results of the first store and then those get cleared when I get the results of the second store. I need to stop the stores refresh event based on th store count I show/hide other panels.

Is it possible to instantiate different instances of the same store each time I load the panel? I've never really seen that in action...

Jamie Avins
11 Apr 2012, 3:24 PM
You could do a new store per panel, but first I'd try to abort any pending requests. Can you try to slip in a Ext.Ajax.abortAll() before your resumeEvents? You really only want to about the one specific request, but thats a bit more work to get to and this should at least tell us if aborting the pending request fixes the problem.

roycyang
11 Apr 2012, 3:33 PM
Hi Jamie,

The Ext.Ajax.abortAll() worked great. This works better for my needs. This makes it so that the first request is always ended before I start the second request.

Interesting note about Ext.Ajax.abortAll() that I didn't expect is that the 'refresh' event and all events still fire, they just fire immediately after the abort call.

Thanks!
Roy