Skip to content

Instantly share code, notes, and snippets.

@benfoxall
Last active August 7, 2016 11:19
Show Gist options
  • Save benfoxall/794f29efff7221402b16523cf80c1638 to your computer and use it in GitHub Desktop.
Save benfoxall/794f29efff7221402b16523cf80c1638 to your computer and use it in GitHub Desktop.

cojs.co libraries

Debug script conversion

document.currentScript.className = 'visible'

util

import {background} from 'util'

// change the background of a page
background('#08f')

text('hello')

html(`
  <h1>HELLO</h1>
  <h2>World</h2>
`)

css(`
h1 {color: red}
`)

Store

Local storage (backed by localforage), shared between other clients.

All values are cast to String, and limited to 60 characters

import {setItem, getItem, getItems, subItem, subItems} from 'store'

// store a key
setItem('name', 'ben')

// get a key
setItem('name')
  .then(n => console.log("hi, " + n))
  

// get all (remote) values
getItems('name')
  .then(names => console.log("hi, " + names.join(', '))


// subscribe to a local key
subItem('name', (n) => {
  console.log(n)
})

// subscribe to remote keys
subItems('name', (names) => {
  console.log(names)
})

Messaging

import {subscribe} from 'messaging'

subscribe('dial', value => console.log(value) )


subscribe('a', value => console.log(value) ) 
subscribe('b', value => console.log(value) ) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment