3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
17 * @class Ext.data.proxy.Memory
18 * @extends Ext.data.proxy.Client
20 * <p>In-memory proxy. This proxy simply uses a local variable for data storage/retrieval, so its contents are lost on
21 * every page refresh.</p>
23 * <p>Usually this Proxy isn't used directly, serving instead as a helper to a {@link Ext.data.Store Store} where a
24 * reader is required to load data. For example, say we have a Store for a User model and have some inline data we want
25 * to load, but this data isn't in quite the right format: we can use a MemoryProxy with a JsonReader to read it into
29 //this is the model we will be using in the store
31 extend: 'Ext.data.Model',
33 {name: 'id', type: 'int'},
34 {name: 'name', type: 'string'},
35 {name: 'phone', type: 'string', mapping: 'phoneNumber'}
39 //this data does not line up to our model fields - the phone field is called phoneNumber
45 phoneNumber: '555 1234'
50 phoneNumber: '666 1234'
55 //note how we set the 'root' in the reader to match the data structure above
56 var store = new Ext.data.Store({
70 Ext.define('Ext.data.proxy.Memory', {
71 extend: 'Ext.data.proxy.Client',
72 alias: 'proxy.memory',
73 alternateClassName: 'Ext.data.MemoryProxy',
76 * @cfg {Array} data Optional array of Records to load into the Proxy
79 constructor: function(config) {
80 this.callParent([config]);
82 //ensures that the reader has been instantiated properly
83 this.setReader(this.reader);
87 * Reads data from the configured {@link #data} object. Uses the Proxy's {@link #reader}, if present
88 * @param {Ext.data.Operation} operation The read Operation
89 * @param {Function} callback The callback to call when reading has completed
90 * @param {Object} scope The scope to call the callback function in
92 read: function(operation, callback, scope) {
94 reader = me.getReader(),
95 result = reader.read(me.data);
97 Ext.apply(operation, {
101 operation.setCompleted();
102 operation.setSuccessful();
103 Ext.callback(callback, scope || me, [operation]);