Skip to content

Instantly share code, notes, and snippets.

@girliemac
Created December 11, 2014 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save girliemac/4efa2cb98591b857ba69 to your computer and use it in GitHub Desktop.
Save girliemac/4efa2cb98591b857ba69 to your computer and use it in GitHub Desktop.
Data Sync Christmas Tree Demo
<!-- Include the PubNub Library (use the beta version)-->
<script src="js/pubnub.js"></script>
var pubnub = PUBNUB.init({
publish_key: 'Your Publish Key Here',
subscribe_key: 'Your Subscribe Key Here'
});
var tree = pubnub.sync('tree');
tree.on.ready(function(ref){
var status = ref.value().light;
if(status === true)
...
});
if(lightSwitch.checked) {
tree.merge({'light': true});
} else {
tree.merge({'light': false});
}
tree.on.merge(function(ref){
// sync the UI here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment