Results 1 to 4 of 4

Thread: Mutliple stores for the same api call BUT different parameters

  1. #1

    Default Answered: Mutliple stores for the same api call BUT different parameters

    I have 3 list views that display the same templates, I also have 3 stores, 1 for each of the list views, I then have a single model shared between the three stores.

    Code:
    Ext.regStore('NewyorkSchoolsStore', {
    	model: 'SchoolModel',
    	autoLoad: true,
    	clearOnPageLoad: true,
    	sorters: 'name',
    	proxy: {
            type: 'scripttag',
            url: 'http://example.com/api/getschoollist.json',
    		extraParams: {
    			state_id: 1
    		}
            reader: {
    			type: 'json',
                root: 'schools'
            }
        }
    });
    Code:
    Ext.regStore('GeorgiaSchoolsStore', {
    	model: 'SchoolModel',
    	autoLoad: true,
    	clearOnPageLoad: true,
    	sorters: 'name',
    	proxy: {
            type: 'scripttag',
            url: 'http://example.com/api/getschoollist.json',
    		extraParams: {
    			state_id: 2
    		}
            reader: {
    			type: 'json',
                root: 'schools'
            }
        }
    });
    As you can see, both stores are near identical, except for the state_id parameter I am passing in. It doesn't seem correct to have multiple stores for the same data, It seems like I am repeating my code a lot and I'm wondering if I need the 3 different stores.

    Would it be better to move the proxy to the model?

    Is it possible to pass parameters to the store an have it refresh the content before the panel is displayed?

    Or am I thinking about this incorrectly and I really should have separate stores for different sets of data?


    Any help appreciated.

  2. Quote Originally Posted by rossmurphy View Post
    So can you confirm it is best practice to use a different store for each of these data instances?
    If you need a different data set then of course it is. Even if it's the same data but you need one to be filtered and not reflect on the 3 different views. For instance, if you had 3 grids showing with the same store and you sort one of the grids, it will reflect on all 3. If you have 3 different stores then you won't have this problem.

  3. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,448
    Answers
    3997

    Default

    If the proxy is going to be the same then it is a good candidate to move the proxy to the model.

    If you want the store to load with certain parameters before it is displayed then you can use different things... you can apply some things to the extraParams on the proxy on the store (the proxy will be on the model but the store will use it) or you can use store.load({params : {}});
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  4. #3

    Default

    So can you confirm it is best practice to use a different store for each of these data instances?

  5. #4
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,448
    Answers
    3997

    Default

    Quote Originally Posted by rossmurphy View Post
    So can you confirm it is best practice to use a different store for each of these data instances?
    If you need a different data set then of course it is. Even if it's the same data but you need one to be filtered and not reflect on the 3 different views. For instance, if you had 3 grids showing with the same store and you sort one of the grids, it will reflect on all 3. If you have 3 different stores then you won't have this problem.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •