Giter Site home page Giter Site logo

porchetta-client's Introduction

Porchetta Client Build Status

A bad-ass client for porchetta-server.

Installation

$ bower install [email protected]:activecell/porchetta-client.git --save

Or copy index.js and socket.io-client.js to vendor folder.

Example

Assume you started porchetta-server on http://localhost:4000 with npm start.

porchetta = new Porchetta('http://localhost:4000', app.company.id);

# Watch collections
porchetta
  .addCollection(app.vendors, 'vendors')
  .addCollection(app.tasks, 'tasks')
  .addCollection(app.accounts, 'accounts')
  .addModel(app.company, 'company')
  .addModel(app.user, 'user')

porchetta.on 'connect', ->
  console.log('connected to the server')

porchetta.on 'viewers', (viewers) ->
  if viewers.length > 1
    console.log('Porchetta is active for ' + viewers.length + ' viewers');
  else
    console.log('Porchetta is inactive');

# Porchetta emits event after every sync with pattern: <name>:<event>
porchetta.on 'vendors:add',     (json) -> console.log('new vendor added', json)
porchetta.on 'tasks:change',    (json) -> console.log('task changed', json)
porchetta.on 'accounts:remove', (json) -> console.log('account removed', json)

API

In general porchetta-client is wrapper around socket.io-client. Porchetta starts to work when has more than one connected user.

new Porchetta(url, room, [socketIoOptions])

Connect to porchetta server, that started on url, and join selected room. socketIoOptions is an optional parameter with specific options for socket.io.

Events

Porchetta's instance is event emiiter. Subscribe to specific events with on and once methods

porchetta.on 'connect', ->
  console.log('connected to the server')

Available events (for more examples, check test suite):

  • connect - after succesfull connect.
  • viewers - someone connected or disconnected.
  • <name>:<event> - after sync event.

porchetta#addCollection(collection, name)

Sync Backbone.Collection events: add, change, remove. Make sure that name is unique identificator. For collections, which do not have id, you have to define findByJSON method.

porchetta#addModel(model, name)

Sync Backbone.Model instance through porchetta-server. It tracks only change event. Logic is similar to addCollection.

Development

  • npm install - to install npm/bower dependencies
  • npm test - to run tests
  • npm start - to start local watch server on http://localhost:7357

porchetta-client's People

Contributors

alekseykulikov avatar

Watchers

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