Code Monkey home page Code Monkey logo

ext.ux.data.proxy.websocket's Introduction

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).

Requirements

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

Python 2.7

I suggest to use virtualenv to test the demo.

First of all, you need virtualenv:

$ sudo apt-get install virtualenv

Then, make a virtual environment:

$ virtualenv venv

And install Tornado:

$ . venv/bin/activate
(venv)$ pip install tornado

Finally, start the server:

(venv)$ cd /var/www/Ext.ux.data.proxy.WebSocket/demo/ && python server.py 8888 9999 10000

Python 3.3

First of all, install Tornado:

$ sudo apt-get install python3-tornado

Then, start the server:

$ python3.3 /var/www/ExtJS-WebSocket/demo/server.py 8888 9999 10000

Now, you have three websockets listening at 8888, 9999 and 10000 port 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 [email protected]

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.

ext.ux.data.proxy.websocket's People

Contributors

wilk avatar juleq avatar

Watchers

Ernesto J Rodriguez avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.