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.
18 * In-memory proxy. This proxy simply uses a local variable for data storage/retrieval, so its contents are lost on
21 * Usually this Proxy isn't used directly, serving instead as a helper to a {@link Ext.data.Store Store} where a reader
22 * is required to load data. For example, say we have a Store for a User model and have some inline data we want to
23 * load, but this data isn't in quite the right format: we can use a MemoryProxy with a JsonReader to read it into our
26 * //this is the model we will be using in the store
27 * Ext.define('User', {
28 * extend: 'Ext.data.Model',
30 * {name: 'id', type: 'int'},
31 * {name: 'name', type: 'string'},
32 * {name: 'phone', type: 'string', mapping: 'phoneNumber'}
36 * //this data does not line up to our model fields - the phone field is called phoneNumber
42 * phoneNumber: '555 1234'
47 * phoneNumber: '666 1234'
52 * //note how we set the 'root' in the reader to match the data structure above
53 * var store = Ext.create('Ext.data.Store', {
66 Ext.define('Ext.data.proxy.Memory', {
67 extend: 'Ext.data.proxy.Client',
68 alias: 'proxy.memory',
69 alternateClassName: 'Ext.data.MemoryProxy',
72 * @cfg {Ext.data.Model[]} data
73 * Optional array of Records to load into the Proxy
76 constructor: function(config) {
77 this.callParent([config]);
79 //ensures that the reader has been instantiated properly
80 this.setReader(this.reader);
84 * Reads data from the configured {@link #data} object. Uses the Proxy's {@link #reader}, if present.
85 * @param {Ext.data.Operation} operation The read Operation
86 * @param {Function} callback The callback to call when reading has completed
87 * @param {Object} scope The scope to call the callback function in
89 read: function(operation, callback, scope) {
91 reader = me.getReader(),
92 result = reader.read(me.data);
94 Ext.apply(operation, {
98 operation.setCompleted();
99 operation.setSuccessful();
100 Ext.callback(callback, scope || me, [operation]);