I have defined the following Sencha Store, which uses SessionStorage:
Ext.define('TestApp.store.SessionStore', {
extend: 'Ext.data.Store',
config: {
model: 'TestApp.model.SessionStoreModel',
autoLoad: true,
autoSync: true,
proxy: {
type: 'sessionstorage',
id: 'SessionStore'
}
}
});
This store has the following model:
Ext.define('TestApp.model.SessionStoreModel', {
extend: 'Ext.data.Model',
config:{
identifier: {
type: 'uuid'
},
fields: [
{ name:'token', type:'string'},
{ name:'auth', type:'boolean', defaultValue: false }
]
}
});
The ideas is,
I will always have just one model inside, not more.
It seems an overkill to have a store for just one model (i have to clear it, count it's index when using it).
In my humble opinion, there should be a way to make the model save data directly to SessionStorage and reference it, not evolving a store.
Can this be done in Sencha Touch 2?
UPDATE
Here is what I did with no avail:
Ext.define('TestApp.model.TestModel', {
extend: 'Ext.data.Model',
config: {
identifier: {
type: 'uuid'
},
fields: [
{ name:'auth', type:'boolean', defaultValue: false }
],
proxy: {
type: 'sessionstorage'
}
}
});
Save model data:
// Test.
var testModel = Ext.create('TestApp.model.TestModel', {
auth: 'La Playa'
});
testModel.save({
scope: this,
success: function() {
console.log('TestModel success');
},
failure: function() {
console.log('TestModel failure');
},
callback: function() {
console.log('TestModel callback');
}
});
Reade model data:
// Test.
TestApp.model.TestModel.load(1, {
scope: this,
success: function(record, operation) {
console.log('TestModel read success');
console.log(record.get('auth'));
},
failure: function(record, operation) {
console.log('TestModel read failure');
},
callback: function(record, operation) {
console.log('TestModel read callback');
}
});
But it does not work, cannot read from SessionStorage