Skip to content

client event

Frank van Viegen edited this page Sep 23, 2015 · 1 revision

Creating events (push notifications) is done serverside. This module is for displaying the client side of this interaction. Mostly the green or gray bubbles and determine what is 'new' content.

##renderBubble (path, opts) This renders the gray or green bubble with an number in it. The number describes how many unread events have occurred. The bubble is green if the user is subscribed to that channel, and gray if he isn't.

  • path: The identifier of the location where the event is fired. It should, for this to work, be the same as the navigation path. It must be an array.
  • opts: An object containing further details on how to render the bubble. At this time, only the style property is supported.

Example:

client.coffee:
	Dom = require 'dom'
	Event = require 'event'
	Page = require 'page'
	Server = require 'server'
	Ui = require 'ui'

	renderSubpage = !->
		Ui.bigButton "Renerate event", !->
			Server.call("renerateEvent")
		Event.showStar()

	exports.render = !->
		if Page.state.get(0) is 'subpage'
			renderSubpage()
			return
		Dom.section !->
			Dom.style Box: 'left'
			Dom.div !->
				Dom.style Flex: 1
				Dom.text "Click to go to Subpage"
			Dom.text "bubble: "
			Event.renderBubble ["subpage"],
				style margin: '0px'
			Dom.onTap !->
				Page.nav {0:"subpage"}

server.coffee:
	Event = require 'event'

	exports.client_renerateEvent = !->
		log "renerate event"
		Event.create
			unit: 'msg'
			text: 'dummy event'
			path: ['subpage']

##getUnread (path) Similar to Event.renderBubble, but without the bubble creation. It returns how many events the user has yet to read.

Example:

client.coffee:
	Dom = require 'dom'
	Event = require 'event'
	Page = require 'page'
	Server = require 'server'
	Ui = require 'ui'

	renderSubpage = !->
		Ui.bigButton "Renerate event", !->
			Server.call("renerateEvent")
		Event.showStar()

	exports.render = !->
		if Page.state.get(0) is 'subpage'
			renderSubpage()
			return
		Dom.section !->
			Dom.style Box: 'left'
			Dom.div !->
				Dom.style Flex: 1
				Dom.text "Click to go to Subpage"
			Dom.text "unread: " + Event.getUnread ["subpage"]
			Dom.onTap !->
				Page.nav {0:"subpage"}

server.coffee:
	Event = require 'event'

	exports.client_renerateEvent = !->
		log "renerate event"
		Event.create
			unit: 'msg'
			text: 'dummy event'
			path: ['subpage']

##markRead (path) Flag given path as read.

##isNew (time, path) Compares your given time with the last time the user visited the given path.

##styleNew (time, path) Styles the current element as 'new' if it is.

example:

Dom = require 'dom'
Db = require 'db'
Event = require 'event'

item = Db.shared.get('message') # which contains a `time`, `text` and `by` field.
Dom.div !->
	Event.styleNew (item.time)
	Dom.text item.text + ", by " + item.by

##getLast (path) Returns an array containing details about the last pushed event of the path. formatted: [text, path[pluginCode, subpage, subpage...]]

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