Created
December 11, 2014 00:26
-
-
Save girliemac/4efa2cb98591b857ba69 to your computer and use it in GitHub Desktop.
Data Sync Christmas Tree Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Include the PubNub Library (use the beta version)--> | |
<script src="js/pubnub.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pubnub = PUBNUB.init({ | |
publish_key: 'Your Publish Key Here', | |
subscribe_key: 'Your Subscribe Key Here' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tree = pubnub.sync('tree'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tree.on.ready(function(ref){ | |
var status = ref.value().light; | |
if(status === true) | |
... | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(lightSwitch.checked) { | |
tree.merge({'light': true}); | |
} else { | |
tree.merge({'light': false}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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