Created
December 5, 2014 21:38
-
-
Save girliemac/0be039191a5855f58204 to your computer and use it in GitHub Desktop.
Data Sync 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
var home = pubnub.sync('home'); |
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(lightSwitchCheckbox.checked) { | |
// Light switch is turned on | |
home.merge({'light': true}); | |
} else { | |
// Light switch is turned off | |
home.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
home.on.merge(function(ref){ | |
console.log(JSON.stringify(ref.value())); | |
lightSwitchCheckbox.checked = true; // sync UI across every devices | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment