Cumulo Client
Client side toolkits for Cumulo architechture.
Usage
This is a CommonJS package you can use with Browserify:
npm i --save-dev cumulo-client
cumulo-client
exposes several objects and contructors:
# a session manager exports.session = require './session'# a router like event hub exports.transmitter = require './transmitter' # data store to be synced with server exports.Store = require './store' # websocket interface exports.ws = null= action = namedata raw = JSONstringify actionnull2 @wssend raw
Session
cumulo = require 'cumulo-client'session = cumulosessionsessioninit key: 'chat-distract' # localStorageKey initialSession: # a default object
session.get
returns an object.
session.set(obj)
obj
is an object that will be lodash.assign
to session object.
Session Object will be written to localStorage on onbeforeunload
.
Transmitter
cumulo = require 'cumulo-client'transmitter = cumulotransmitter # an interface for debugging, create logs for events = consoleinfo action # transmitter pipes actions from websocket = raw = messageObjectdata action = JSONparse raw transmitterdispatch action # and listens events like an router, notice that # .dispatch({name: '', data: {}}) # .register(name, (data)->) transmitterregister 'client/patch' storepatch data
Store
Cumulo store in client is simply listening to events and updating data:
cumulo = require 'cumulo-client' transmitter = cumulotransmitter # initial data is required, mind that it's used in patching # data is mostly {} or [], see what you need in patching store = data: module.exports = store transmitterregister 'preview/sync' storesync data transmitterregister 'preview/patch' storepatch data
Send
Well, send
is just an alias, and you need to attach ws
to cumulo:
# websocket interface exports.ws = null= # on server, there's a router receiving this action action = namedata raw = JSONstringify actionnull2 @wssend raw
See chat-distract for Details.
License
MIT