Skip to content

client db

Frank van Viegen edited this page Sep 9, 2015 · 2 revisions

This module provides client-side access to the synchronized data stores. For each happening, there are several different stores available:

  • shared, synchronized across all devices of all happening members,
  • admin, synchronized across all devices of all happening admins,
  • personal, synchronized across all devices of the logged in happening member, and
  • local, not synchronized, only available on the local client device.

Except for the local store, these stores can only be modified from your server-side plugin code. Client-side code can read and observe the data though, subject to the above limitations of course. There is one exception: when in a Server.sync prediction function, client-side code is allowed to modify any of the stores. Changes are only temporary though; they will be reverted once a response from the server has been received (which will hopefully apply the same or similar changes).

Objects

shared

A read-only Observable that maps to the root of the shared store.

personal

A read-only Observable that maps to the root of the personal store for the logged in user.

admin

A read-only Observable that maps to the root of the shared admin store.

local

An Observable that maps to the root of the local store.

Example

A simple chat example, client-side code:

Db = require 'db'
Dom = require 'dom'

if messages = Db.shared.ref("messages")
	messages.iterate (message) ->
		# using reactive iteration, see the obs module for how this works
		Dom.div ->
			Dom.text message.get('text')

sendMessage = (text) ->
	require('server').call "sendMessage", text

Server-side code:

Db = require 'db'

exposed.client_sendMessage = (info, text) ->
	maxId = Db.shared.modify (v) -> (v||0)+1
	Db.shared.set "messages", maxId, {text: text}

Also see the db server module reference.

Additionally, there is an admin store that is shared between all happening admin, and a local store: it is writable as well and changes are only saved on the local device. Use it as scratch space.

Basic topics

API reference

  • API Reference
    • Client
      • [client plugin](client plugin)
      • [client dom](client dom)
      • [client obs](client obs)
      • [client db](client db)
      • [client server](client server)
      • [client page](client page)
      • [client ui](client ui)
      • [client form](client form)
      • [client icon](client icon)
      • [client modal](client modal)
      • [client photo](client photo)
      • [client photoview](client photoview)
      • [client time](client time)
      • [client share](client share)
      • [client map](client map)
      • [client geoloc](client geoloc)
    • Server
      • [server event](server event)
      • [server plugin](server plugin)
      • [server http](server http)
      • [server db](server db)
      • [server photo](server photo)
      • [server time](server time)
  • Example UI elements

Advanced topics

Clone this wiki locally