Skip to content

An easy-to-use implementation of the ExtJS/Sencha Touch proxy, using HTML5 WebSocket.

Notifications You must be signed in to change notification settings

AndreVirtimo/Ext.ux.data.proxy.WebSocket

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ext.ux.data.proxy.WebSocket

Ext.ux.data.proxy.WebSocket is an easy-to-use implementation of the ExtJS/Sencha Touch proxy, using Ext.ux.WebSocket (a HTML5 WebSocket wrapper built for ExtJS and Sencha Touch).

Dependencies

ExtJS 5

The new version of ExtJS 5 has requested to make a new major version of Ext.ux.data.proxy.WebSocket. Now, this new major version v1.0.0 is located on the master branch.

ExtJS 4 & Sencha Touch 2

It's possible to work either with ExtJS 4 and Sencha Touch 2 with previous version v0.0.7

Install via Bower

First of all, install Bower.

Then install the Ext.ux.data.proxy.WebSocket dependency (version v1.x.x for ExtJS 5):

$ bower install ext.ux.data.proxy.websocket

Or install the Ext.ux.data.proxy.WebSocket dependency (version v0.0.7 for ExtJS 4 & Sencha Touch 2):

$ bower install ext.ux.data.proxy.websocket#0.0.7

Now, you got the extension at the following path: YOUR_PROJECT_PATH/bower_components/ext.ux.data.proxy.websocket/

It contains WebSocket.js.

Let's setup the Ext.Loader to require the right file:

Ext.Loader.setConfig ({
	enabled: true ,
	paths: {
		'Ext.ux.data.proxy.WebSocket': 'bower_components/ext.ux.data.proxy.websocket/WebSocket.js' ,
		// Require the Ext.ux.WebSocket dependency
		'Ext.ux.WebSocket': 'bower_components/ext.ux.websocket/WebSocket.js'
	}
});

Ext.require (['Ext.ux.data.proxy.WebSocket']);

Usage

Load Ext.ux.data.proxy.WebSocket via Ext.require:

Ext.Loader.setConfig ({
	enabled: true
});

Ext.require (['Ext.ux.data.proxy.WebSocket']);

Now, you are ready to use it in your code!

First define a new Ext.data.Model:

Ext.define ('myModel', {
	extend: 'Ext.data.Model' ,
	fields: ['id', 'name', 'age'] ,
	// Ext.ux.data.proxy.WebSocket can be put here in the model or in the store
	proxy: {
		type: 'websocket' ,
		storeId: 'myStore',
		url: 'ws://localhost:8888' ,
		reader: {
			type: 'json' ,
			root: 'user'
		}
	}
});

Second create a Ext.data.Store:

var store = Ext.create ('Ext.data.Store', {
	model: 'myModel',
	storeId: 'myStore'
});

Third attach the store to a grid or a chart:

var myGrid = Ext.create ('Ext.grid.Panel', {
	title: 'My Grid' ,
	store: store ,
	...
});

var myGrid = Ext.create ('Ext.chart.Chart', {
	title: 'My Chart' ,
	store: store ,
	...
});

In the above example, a WebSocket proxy is defined into the model (the same thing can be done into stores): when a CRUD operation is made by its store (through sync/load methods), a 'create'/'read'/'update'/'destroy' event is sent to the server. At this point, the server intercepts the event, parses the request, and then replies back with the same event. If you want/need to specify your communication protocol (you wanna CRUD operations like 'createUsers','readUsers','updateUsers','destroyUsers'), just use the api configuration:

proxy: {
	type: 'websocket' ,
	storeId: 'myStore',
	url: 'ws://localhost:8888' ,
	api: {
		create:  'createUsers' ,
		read:    'readUsers' ,
		update:  'updateUsers' ,
		destroy: 'destroyUsers'
	} ,
	reader: {
		type: 'json' ,
		root: 'user'
	}
}

With this configuration, each sync/load operation made by the store will fire the right CRUD-overridden action.

Now, you're ready to watch the magic in action!

Run the demo

The demo has a back-end written in NodeJS so you have to install it first. Now, clone the repo locally:

$ git clone https://github.com/wilk/Ext.ux.data.proxy.WebSocket
$ cd Ext.ux.data.proxy.WebSocket

Then use NPM and Bower to satisfy every dependencies:

$ npm install && bower install

Last step, launch the server:

$ node demo/server

Now, you have a websocket listening at port 9001 on the server side! Then, type in the address bar of your browser: http://localhost/Ext.ux.data.proxy.WebSocket/demo and play the demo ;)

Documentation

You can build the documentation (like ExtJS/Sencha Touch Docs) with jsduck:

$ jsduck ux --output /var/www/docs

It will make the documentation into docs dir and it will be visible at: http://localhost/docs

License

The MIT License (MIT)

Copyright (c) 2013 Vincenzo Ferrari wilk3ert@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

An easy-to-use implementation of the ExtJS/Sencha Touch proxy, using HTML5 WebSocket.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 97.7%
  • HTML 2.3%