3.2.11 • Published 9 years ago

pojosync v3.2.11

Weekly downloads
3
License
BSD
Repository
github
Last release
9 years ago

Syncing POJOs between clients/browsers, and your node.js server, with socket.io

##What it does

This library allows you to keep data objects up to date between multiple clients and a server.

How it works

Once you have shared an object with Client.put(object), it (and any other objects it refers to) is assigned an ID, flattened for transport, and pushed to the server. Shared objects are then broadcast to all connected clients.

##Usage

###Server

Example use with express.js. (For alternate socket.io setups, see socket.io's How To . )

   var pojosync = require('pojosync')
     , app = express()
     , server = require('http').createServer(app)
     , io = require('socket.io').listen(server, {log:false})
     , Dataserver = new pojosync.Server(io);

###Client

(Use browserify to create a file for use in browser, then reference it with a script tag. You will also need to add:

<script src="/socket.io/socket.io.js"></script>
//io defined by socket.io.js
var pojo = require('pojosync');
var Client = new pojo.Client(io);
var flossy = { type: 'Sheep', name: 'Flossy', age: 3 };
Client.put(flossy); 

Saves flossy to the server and shares the object with other clients.

var farms = Client.list({type: 'Farm'}, optional_callback); 

farms will initially be an empty array, but will fill with data once the server has returned it.

flossy.farm = {type:'Farm', name: 'Greenacres' };
Client.put(flossy);

farms will then include the new object, and flossy will be updated on all clients.

API

Client.put

Takes an object and shares it with the server (which broadcasts it to other clients). The object can be new, or a locally updated version of an already-shared object.

Client.list

Takes an object pattern and returns an array of any objects matching that pattern. This array will be kept up to date as objects are .put.

##Storage

Currently data is simply persisted on your server as a JSON file. This is simple but has its limitations - all the data must be loaded into memory at once. It should not be difficult to add persistence to other backends, such as MongoDB.

3.2.11

9 years ago

3.2.10

9 years ago

3.2.9

9 years ago

3.2.8

9 years ago

3.2.7

9 years ago

3.2.6

9 years ago

3.2.5

9 years ago

3.2.4

10 years ago

2.2.4

10 years ago

2.2.3

10 years ago

2.2.2

10 years ago

2.2.1

10 years ago

1.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago