View Full Version : One instance of Model belong to multiple Stores
29 Nov 2011, 12:50 AM
I need to share a model instance between two stores (a TreeStore and a Store).
A model instance can only have a reference to one store. I can listen the update event and propagate it to the other store but it need configuration, coding, ...
I search into the forum but I didn't find anything. In a old Ed Spencer post http://edspencer.net/2011/02/proxies-extjs-4.html. He said that I will be possible to do it in 4.0 (in february 2011). But I think that it's not yet available...
Anyone know if it's possible to share instance between multiple stores ?
29 Nov 2011, 1:56 AM
multiple stores can use the same model class.
i do not think it makes sense to share an instance -> if one store gets a filter, is cleared, loaded etc. you get problems.
you can share one store instance with multiple views.
29 Nov 2011, 3:48 AM
I'm agree with you that, in some case, you didn't need to share instance. Filter is a good example.
But in some case, it's important (or easier) to share instance.
Example : a file browser. A tree to show the directory and a grid to show files and subfolders. If you change a subfolder name, it's nice if the node corresponding to this subfolders is automatically updated without listening store update event.
29 Nov 2011, 9:39 AM
using the same store (instance) would be not easy to implement, since you have a treeStore for the tree and a plain store for the grid.
you can put all the data into the treeStore and fill the grid store on a node selection with the relevant subData. imho the easiest way to go. if the data is huge, i would only load the parent nodes for the tree and fetch the needed grid data via ajax on demand.
30 Nov 2011, 11:05 PM
I take a look into the model class and it's possible to extend it to use an collection of store. But I don't know the side effects...
Currently, we use the solution you describe in your post. So we got the same idea ;-)
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.