Skip to content

Commit

Permalink
added event "afterWampWrite" to signal when the store processed a WAM…
Browse files Browse the repository at this point in the history
…P event he was listening to.

This is useful to trigger further action on store updates.
  • Loading branch information
markope committed Apr 21, 2013
1 parent e39d367 commit 4afc6e1
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions autobahnextjs/autobahnextjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,16 @@ Ext.define('Ext.data.WampStore', {
constructor: function () {
var me = this;

me.addEvents(
/**
* @event afterWampWrite
* Fires when remotely triggered write operation (insert, update, delete) on the store was completed.
* Fires on update WAMP event only when the record to be updated is in the store.
* @param {Ext.data.WampStore} this
* @param {Object} obj The payload of the wamp event.
*/
'afterWampWrite');

//me.callParent(arguments);
Ext.data.WampStore.superclass.constructor.apply(me, arguments);

Expand All @@ -484,6 +494,7 @@ Ext.define('Ext.data.WampStore', {
}
// apply configured sort of the store
me.sort();
me.fireEvent('afterWampWrite', me, obj);
});

me.model.proxy.on('onupdate', function (proxy, obj) {
Expand All @@ -496,13 +507,17 @@ Ext.define('Ext.data.WampStore', {
}
}
record.dirty = false;
// apply configured sort of the store
me.sort();
me.fireEvent('afterWampWrite', me, obj);
}
});

me.model.proxy.on('ondestroy', function (proxy, obj) {
var record = me.getById(obj[me.model.prototype.idProperty]);
// record.phantom = true;
me.remove(record);
me.fireEvent('afterWampWrite', me, obj);
});
}
});
Expand All @@ -519,6 +534,16 @@ Ext.define('Ext.data.WampTreeStore', {
constructor: function () {
var me = this;

me.addEvents(
/**
* @event afterWampWrite
* Fires when remotely triggered write operation (insert, update, delete) on the store was completed.
* Fires on update WAMP event only when the record to be updated is in the store.
* @param {Ext.data.WampTreeStore} this
* @param {Object} obj The payload of the wamp event.
*/
'afterWampWrite');

// me.callParent(arguments);
Ext.data.WampTreeStore.superclass.constructor.apply(me, arguments);

Expand All @@ -541,13 +566,9 @@ Ext.define('Ext.data.WampTreeStore', {
}
}

// apply sort
me.sort([
{
property : 'leaf',
direction: 'ASC'
}
]);
// apply sort
me.sort();
me.fireEvent('afterWampWrite', me, obj);
});

me.model.proxy.on('onupdate', function (proxy, obj) {
Expand All @@ -566,19 +587,16 @@ Ext.define('Ext.data.WampTreeStore', {
me.getRootNode().findChild(me.model.prototype.nodeParam, obj[me.model.prototype.nodeParam]).insertChild(0, obj);
}

// apply sort
me.sort([
{
property : 'leaf',
direction: 'ASC'
}
]);
// apply sort
me.sort();
me.fireEvent('afterWampWrite', me, obj);
});

me.model.proxy.on('ondestroy', function (proxy, obj) {
// deep search for node
var node = me.getRootNode().findChild(me.model.prototype.idProperty, obj[me.model.prototype.idProperty], true);
node.remove();
me.fireEvent('afterWampWrite', me, obj);
});
}
});

0 comments on commit 4afc6e1

Please sign in to comment.