-
15 Nov 2011 10:37 AM #11
A minor update. I had to block in the constructor in order to make sure the store loads. Otherwise the first query is against an empty store.
PHP Code:/*
* File: RemoteStorageProvider.js
* Date: 20-Jul-2011
* By : Kevin L. Esteb
*
* This module provides a state provider that uses remote storage as
* the backing store.
*
* RemoteStorageProvider.js is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RemoteStorageProvider.js is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RemoteStorageProvider.js. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
Ext.define('Ext.ux.state.RemoteStorageProvider', {
extend: 'Ext.state.Provider',
mixins: {
observable: 'Ext.util.Observable'
},
uses: [
'Ext.data.Model',
'Ext.data.Store',
'Ext.state.Provider',
'Ext.util.Observable'
],
store: {},
constructor: function(config) {
config = config || {};
this.initialConfig = config;
Ext.apply(this, config);
this.store = this.storeage();
// Have to block to load the store before leaving the constructor
// otherwise, the first query will be against an empty store.
// There must be a better way...
Ext.data.Connection.prototype.async = false;
this.store.load();
Ext.data.Connection.prototype.async = true;
this.mixins.observable.constructor.call(this, config);
},
set: function(name, value) {
var pos, row;
if ((pos = this.store.find('name', name)) > -1) {
row = this.store.getAt(pos);
row.set('value', this.encodeValue(value));
} else {
this.store.add({
name: name,
value: this.encodeValue(value)
});
}
this.store.sync();
this.fireEvent('statechange', this, name, value);
},
get: function(name, defaultValue) {
var pos, row, value;
if ((pos = this.store.find('name', name)) > -1) {
row = this.store.getAt(pos);
value = this.decodeValue(row.get('value'));
} else {
value = defaultValue;
}
return value;
},
clear: function(name) {
var pos;
if ((pos = this.store.find('name', name)) > -1) {
this.store.removeAt(pos);
this.store.sync();
this.fireEvent('statechange', this, name, null);
}
},
storeage: Ext.emptyFn
});
-
2 Dec 2011 8:32 AM #12
Another minor update. This one introduces the concept of throttling. It is turned off by default. Throttling will buffer state changes until a certain number have occurred, when that happens the changes are then batched to the store. You do lose some granularity in the state of the state. So you need to balance that out with performance needs.
PHP Code:/*
* File: RemoteStorageProvider.js
* Date: 20-Jul-2011
* By : Kevin L. Esteb
*
* This module provides a state provider that uses remote storage as
* the backing store.
*
* RemoteStorageProvider.js is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RemoteStorageProvider.js is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RemoteStorageProvider.js. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
Ext.define('Ext.ux.state.RemoteStorageProvider', {
extend: 'Ext.state.Provider',
mixins: {
observable: 'Ext.util.Observable'
},
uses: [
'Ext.data.Model',
'Ext.data.Store',
'Ext.state.Provider',
'Ext.util.Observable'
],
store: {},
throttled: false,
queue: 10,
count: 0,
constructor: function(config) {
config = config || {};
this.initialConfig = config;
Ext.apply(this, config);
this.store = this.storeage();
// Have to block in order to load the store before leaving the
// constructor, otherwise, the first query may be against an
// empty store. There must be a better way...
Ext.data.Connection.prototype.async = false;
this.store.load();
Ext.data.Connection.prototype.async = true;
this.mixins.observable.constructor.call(this, config);
},
set: function(name, value) {
var pos, row;
if ((pos = this.store.find('name', name)) > -1) {
row = this.store.getAt(pos);
row.set('value', this.encodeValue(value));
} else {
this.store.add({
name: name,
value: this.encodeValue(value)
});
}
this.sync();
this.fireEvent('statechange', this, name, value);
},
get: function(name, defaultValue) {
var pos, row, value;
if ((pos = this.store.find('name', name)) > -1) {
row = this.store.getAt(pos);
value = this.decodeValue(row.get('value'));
} else {
value = defaultValue;
}
return value;
},
clear: function(name) {
var pos;
if ((pos = this.store.find('name', name)) > -1) {
this.store.removeAt(pos);
this.sync();
this.fireEvent('statechange', this, name, null);
}
},
sync: function() {
if (this.throttled) {
if (this.count >= this.queue) {
this.count = 0;
this.store.sync();
} else {
this.count++;
}
} else {
this.store.sync();
}
},
storeage: Ext.emptyFn
});
-
12 Jan 2012 1:22 PM #13
One glitch...
One glitch...
The function 'storeage' should be spelled 'storage'.
-
2 May 2012 8:44 AM #14
-
2 May 2012 9:55 AM #15
-
7 May 2012 1:46 PM #16
I have been using it with a internal 4.1 application.
-
11 Aug 2012 8:01 AM #17
-
21 Aug 2012 2:07 AM #18
Hey, could you release this with a dual license (GPL/Sencha) for a commercial support?
Additionally, I would prefer something like a github repo incl. the required store/model configuration. I would do this, but it's actually "your" code...
-
13 Sep 2012 7:50 AM #19
Updates? Sure, why not. This fixes the above noted spelling error:
I use the following model:PHP Code:/*
* File: RemoteStorageProvider.js
* Date: 20-Jul-2011
* By : Kevin L. Esteb
*
* This module provides a state provider that uses remote storage as
* the backing store.
*
* RemoteStorageProvider.js is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RemoteStorageProvider.js is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RemoteStorageProvider.js. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
Ext.define('Ext.ux.state.RemoteStorageProvider', {
extend: 'Ext.state.Provider',
mixins: {
observable: 'Ext.util.Observable'
},
uses: [
'Ext.data.Model',
'Ext.data.Store',
'Ext.state.Provider',
'Ext.util.Observable'
],
store: {},
throttled: false,
queue: 10,
count: 0,
constructor: function(config) {
config = config || {};
this.initialConfig = config;
Ext.apply(this, config);
this.store = this.storage();
// Have to block in order to load the store before leaving the
// constructor, otherwise, the first query may be against an
// empty store. There must be a better way...
Ext.data.Connection.prototype.async = false;
this.store.load();
Ext.data.Connection.prototype.async = true;
this.mixins.observable.constructor.call(this, config);
},
set: function(name, value) {
var pos, row;
if ((pos = this.store.find('name', name)) > -1) {
row = this.store.getAt(pos);
row.set('value', this.encodeValue(value));
} else {
this.store.add({
name: name,
value: this.encodeValue(value)
});
}
this.sync();
this.fireEvent('statechange', this, name, value);
},
get: function(name, defaultValue) {
var pos, row, value;
if ((pos = this.store.find('name', name)) > -1) {
row = this.store.getAt(pos);
value = this.decodeValue(row.get('value'));
} else {
value = defaultValue;
}
return value;
},
clear: function(name) {
var pos;
if ((pos = this.store.find('name', name)) > -1) {
this.store.removeAt(pos);
this.sync();
this.fireEvent('statechange', this, name, null);
}
},
sync: function() {
if (this.throttled) {
if (this.count >= this.queue) {
this.count = 0;
this.store.sync();
} else {
this.count++;
}
} else {
this.store.sync();
}
},
storage: Ext.emptyFn
});
Along with this store:PHP Code:/*
* File: WAM.desktop.model.State.js
* Date: 19-Jul-2011
* By : Kevin L. Esteb
*
* This module provides a state provider for the desktop using remote storage.
*
*/
Ext.define('WAM.desktop.model.State', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'string' },
{ name: 'value', type: 'string' },
{ name: 'revision', type: 'int' }
]
});
Which is specific to my application. I really don't see a need for a git repository and I don't see a need to change the license.PHP Code:/*
* File: State.js
* Date: 12-Dec-2011
* By : Kevin Esteb
*
* This is the various stores for usage within WAM.
*
*/
Ext.define('WAM.desktop.store.State', {
extend: 'Ext.data.Store',
uses: [
'Ext.data.Store',
'WAM.desktop.model.State',
'WAM.lib.mixins.MessageHandler'
],
mixins: {
messageHandler: 'WAM.lib.mixins.MessageHandler'
},
constructor: function(opts) {
var config = {
model: 'WAM.desktop.model.State',
proxy: {
timeout: 100000,
type: 'ajax',
reader: {
type: 'json',
root: 'data',
idProperty: 'id',
totalProperty: 'count',
successProperty: 'success'
},
writer: {
type: 'json',
root: 'data',
encode: true
},
listeners: {
exception: {
fn: this.onException,
scope: this
}
},
api: {
create: opts.app_rootp + 'desktop/state/create',
read: opts.app_rootp + 'desktop/state/read',
update: opts.app_rootp + 'desktop/state/update',
destroy: opts.app_rootp + 'desktop/state/delete'
}
}
};
Ext.merge(this, config);
this.callParent();
}
});
-
14 Sep 2012 1:41 AM #20
Sad to here so.
Because the time goes, I'd prepared the stuff already. I had to find something for a commercial Ext JS application propose. Anywhere, I will provide a solution which works more reliable (my opinion). At GitHub and with the Sencha License being more compatible. In the next few weeks, expecting October.


Reply With Quote