Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 20 additions & 25 deletions WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ Ext.define('Ext.ux.data.proxy.WebSocket', {
* The use of this method is discouraged: it's invoked by the store with sync/load operations.
* Use api config instead
*/
create: function (operation, callback, scope) {
this.runTask(this.getApi().create, operation, callback, scope);
create: function (operation) {
this.runTask(this.getApi().create, operation);
},

/**
Expand All @@ -253,8 +253,8 @@ Ext.define('Ext.ux.data.proxy.WebSocket', {
* The use of this method is discouraged: it's invoked by the store with sync/load operations.
* Use api config instead
*/
read: function (operation, callback, scope) {
this.runTask(this.getApi().read, operation, callback, scope);
read: function (operation) {
this.runTask(this.getApi().read, operation);
},

/**
Expand All @@ -263,38 +263,34 @@ Ext.define('Ext.ux.data.proxy.WebSocket', {
* The use of this method is discouraged: it's invoked by the store with sync/load operations.
* Use api config instead
*/
update: function (operation, callback, scope) {
this.runTask(this.getApi().update, operation, callback, scope);
update: function (operation) {
this.runTask(this.getApi().update, operation);
},

/**
* @method destroy
* @method erase
* Starts a new DESTROY operation (pull)
* The use of this method is discouraged: it's invoked by the store with sync/load operations.
* Use api config instead
*/
destroy: function (operation, callback, scope) {
this.runTask(this.getApi().destroy, operation, callback, scope);
erase: function (operation) {
this.runTask(this.getApi().destroy, operation);
},

/**
* @method runTask
* Starts a new operation (pull)
* @private
*/
runTask: function (action, operation, callback, scope) {
runTask: function (action, operation) {
var me = this ,
data = {} ,
ws = me.getWebsocket() ,
i = 0;

scope = scope || me;

// Callbacks store
me.callbacks[action] = {
operation: operation,
callback: callback,
scope: scope
operation: operation
};

// Treats 'read' as a string event, with no data inside
Expand Down Expand Up @@ -356,7 +352,7 @@ Ext.define('Ext.ux.data.proxy.WebSocket', {
resultSet = me.getReader().read(data);

// Server push case: the store is get up-to-date with the incoming data
if (Ext.isEmpty(me.callbacks[event])) {
if (!me.callbacks[event]) {
var store = Ext.StoreManager.lookup(me.getStoreId());

if (typeof store === 'undefined') {
Expand All @@ -366,7 +362,7 @@ Ext.define('Ext.ux.data.proxy.WebSocket', {

if (action === 'update') {
for (var i = 0; i < resultSet.records.length; i++) {
var record = store.getById(resultSet.records[i].internalId);
var record = store.getById(resultSet.records[i].getId());

if (record) {
record.set(resultSet.records[i].data);
Expand All @@ -376,7 +372,11 @@ Ext.define('Ext.ux.data.proxy.WebSocket', {
store.commitChanges();
}
else if (action === 'destroy') {
store.remove(resultSet.records);
Ext.each(resultSet.records, function(record) {
store.remove(record);
});

store.commitChanges();
}
else {
store.loadData(resultSet.records, true);
Expand All @@ -385,20 +385,15 @@ Ext.define('Ext.ux.data.proxy.WebSocket', {
}
// Client request case: a callback function (operation) has to be called
else {
var fun = me.callbacks[event] ,
opt = fun.operation ,
var opt = me.callbacks[event].operation ,
records = opt.records || data;

delete me.callbacks[event];

if (typeof opt.setResultSet === 'function') opt.setResultSet(resultSet);
else opt.resultSet = resultSet;
opt.scope = fun.scope;

opt.setCompleted();
opt.setSuccessful();

fun.callback.apply(fun.scope, [opt]);
opt.setSuccessful(true);
}
}
});
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"Gruntfile.js"
],
"dependencies": {
"ext.ux.websocket": "~0.0.4"
"ext.ux.websocket": "~1.0.0"
}
}
19 changes: 14 additions & 5 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ Ext.onReady(function () {
url: 'ws://localhost:9001',
reader: {
type: 'json',
root: 'user'
rootProperty: 'data'
},
writer: {
type: 'json',
writeAllFields: true
}
}
});
Expand All @@ -41,9 +45,14 @@ Ext.onReady(function () {
clicksToEdit: 1
})],

columns: [{
columns: [
/*{
// rownumberer doesn't work in 5.0.0:
// EXTJS-13759 Rownumberer/Action Column causes error when updating row.
// Fixed in Ext JS 5.0.1.
xtype: 'rownumberer'
} , {
} , */
{
text: 'ID',
dataIndex: 'id',
hidden: true
Expand Down Expand Up @@ -137,7 +146,7 @@ Ext.onReady(function () {

var treeStore = Ext.create('Ext.data.TreeStore', {
storeId: 'myTreeStore',
autoLoad: true,
autoLoad: false,
model: 'TreeModel',
proxy: {
type: 'websocket',
Expand All @@ -151,7 +160,7 @@ Ext.onReady(function () {
},
reader: {
type: 'json',
root: 'children'
rootProperty: 'data'
}
},
root: {
Expand Down
7 changes: 5 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Ext.ux.data.proxy.WebSocket</title>
<link rel="stylesheet" type="text/css" href="http://cdn.sencha.com/ext-4.2.0-gpl/resources/css/ext-all.css"/>
<script src="http://cdn.sencha.com/ext-4.2.0-gpl/ext-all.js"></script>
<script src="http://cdn.sencha.com/ext/gpl/5.0.0/build/ext-all-debug.js"></script>
<script src="http://cdn.sencha.com/ext/gpl/5.0.0/packages/ext-charts/build/ext-charts-debug.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdn.sencha.com/ext/gpl/5.0.0/packages/ext-theme-crisp/build/resources/ext-theme-crisp-all-debug.css"/>
<link rel="stylesheet" type="text/css" href="http://cdn.sencha.com/ext/gpl/5.0.0/packages/ext-theme-crisp/build/ext-theme-crisp-debug.js">

<script src="demo.js"></script>
</head>
</html>
56 changes: 50 additions & 6 deletions demo/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ wss.on('connection', function (ws) {

ws.send(JSON.stringify({
event: 'read' ,
data: users
data: {
data: users,
success: true
}
}));

ws.send(JSON.stringify({
event: 'user/read' ,
data: {
children: users
data: users,
success: true
}
}));

Expand All @@ -65,13 +69,33 @@ wss.on('connection', function (ws) {

wss.broadcast(JSON.stringify({
event: 'create' ,
data: message.data
data: {
data: message.data,
success: true
}
}));
wss.broadcast(JSON.stringify({
event: 'user/create' ,
data: {
data: message.data,
success: true
}
}));
}
else if (event === 'read') {
ws.send(JSON.stringify({
event: 'read' ,
data: users
data: {
data: users,
success: true
}
}));
ws.send(JSON.stringify({
event: 'user/read' ,
data: {
data: users,
success: true
}
}));
}
else if (event === 'update') {
Expand All @@ -89,7 +113,17 @@ wss.on('connection', function (ws) {

wss.broadcast(JSON.stringify({
event: 'update' ,
data: message.data
data: {
data: message.data,
success: true
}
}));
wss.broadcast(JSON.stringify({
event: 'user/update' ,
data: {
data: message.data,
success: true
}
}));
}
else if (event === 'destroy') {
Expand All @@ -107,7 +141,17 @@ wss.on('connection', function (ws) {

wss.broadcast(JSON.stringify({
event: 'destroy' ,
data: message.data
data: {
data: message.data,
success: true
}
}));
wss.broadcast(JSON.stringify({
event: 'user/destroy' ,
data: {
data: message.data,
success: true
}
}));
}
});
Expand Down