How do you implement a Store to be a singleton?
In Architect my store has a property checkbox that adds the property
singleton: true,
If I add that then reload the application it fails to load (I can give more details if required about error)
Uncaught TypeError: object is not a function VM5238:3
(anonymous function) VM5238:3
Ext.ClassManager.instantiate ext-all-debug.js:5485
(anonymous function) ext-all-debug.js:2109
Ext.define.getStore
If I then remove that property it loads fine, but where I use Ext.getStore("MyStore") then the stores that are returned contain different data depending on where I'm using the store. I have a single controller where I use the class name inside the getStore method and this is used in a couple of functions inside that one controller.
Also there does not appear to be any documentation about the singleton property in the docs. If I look at Ext.data.Store there is no singleton.
I recommend you to do it the ExtJS way for handling stores and store instances...
Use the
storeIdalong with theExt.StoreManager. Note that eachstoreIdneed to be unique and as soon as you create a instance of a store it will register itself into theExt.StoreManagerwith itsstoreId. You can get a store by calling thelookup('storeId')on theExt.StoreManager. And yes you can do that from anywhere in your code.For example all
Ext.Componentsthat mixinExt.util.Binable(which are most (all) native components that bind a store) will be fine with thestoreIdstring assigned to thestorecfg property. The Binable mixin will internally lookup it from the StoreManager. If you need to do it yourself