A quick method of preventing an infinite propagation loop:
// Infinite loop prevention
var bounceProtection = {
remoteUpdate: false, // remote toggle
local: function(cb) {
if (this.remoteUpdate) return;
cb();
},
remote: function(cb) {
this.remoteUpdate = true;
cb();
this.remoteUpdate = false;
}
};
var myRoom = platform.room('myRoom');
var myKey = myRoom.key('myKey');
myKey.on('set', function(textAreaContent) {
bounceProtection.local(function() {
$('textarea').val(textAreaContent);
});
});
$('textarea').on('change', function(){
var textAreaContent = $(this).val();
bounceProtection.remote(function() {
myKey.set(textAreaContent, function(err) {
if (err) throw err;
});
});
});