PDA

View Full Version : One Store to Rule Them All



bwags
20 Apr 2012, 8:23 AM
Hello,

I have 3 stores:
Urls : manage the urls that the dynamic store can get it's data from.
MyDataItems : a store which loads data from multiple locations into a single model.
MySuperDataItems : which is associated with a MyDataItem model which I populate manually when the MyDataItems store loads via a customLoad method.

Urls contains the list of Url models that a user can select or deselect and MyDataItems is the store associated to the MyDataItem model.

Then I am able to iterate Urls.each and dynamically apply the url stored there to the MyDataItmes store and load the data.

I am then able to define a list with a store property of MySuperDataItems and call the customLoad and all is well.

I have run into a couple issues with this approach.

Gatchas : (There are likely quite a few more I won't remember as I've worked on this for a while.)

1) Sorting...
I ran into some trouble getting the store to sort for me. Finally got it to work by sorting inside MySuperDataItems iteration/loading of MyDataItems. I optimized this a little by only sorting on the last item in the list.

2) PullToRefresh...
If I try to apply the PullRefreshPlugin the load method is never called because the load is dynamic based on another store and called manually by MySuperDataItems.customLoad();
I added a refreshFn to the plugin that calls the customLoad on MySuperDataItems.

3) Adding the items to MySuperStoreDataItems...
I went through a few hours of looking at the different methods available for adding items manually to a store and finally went with MySuperDataItems.add(MyDataItems.each())...or something similar, this is all obviously psudo-code.

Let me know if this helps anyone or post questions if you have them....or especially if you have suggestions for improvement!

Thanks,

bwags

mitchellsimoens
23 Apr 2012, 6:51 AM
Why are you having trouble sorting?
Seems like you would need to extend the plugin and handle things to suit your needs
You can iterate through a store and add to another store using record.getData()

bwags
23 Apr 2012, 7:13 AM
I ended up getting everything to work...I was mostly just posting this in case anyone else wanted to do something similar. I was able to resolve all of the 'gatchas' with the solutions I posted beneath them, again in case anyone else was having similar issues.