From 6f7543e9cc5ad81263715bd5ea9962b88dd6296b Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 2 Jun 2016 17:50:55 +0200 Subject: [PATCH] demonstrate chaining of 'on' directives --- www/json/main.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/www/json/main.js b/www/json/main.js index 4d82b9183..e77004f91 100644 --- a/www/json/main.js +++ b/www/json/main.js @@ -30,33 +30,32 @@ define([ var rt = module.rt = RtListMap.create(config); rt.proxy.on('create', function (info) { - console.log("initializing!"); + console.log("initializing..."); window.location.hash = info.channel + secret.key; - console.log(info); }).on('ready', function (info) { - console.log("ready"); - - console.log(info); + console.log("...your realtime object is ready"); rt.proxy // on(event, path, cb) .on('change', [], function (o, n, p) { console.log("root change event firing for path [%s]: %s => %s", p.join(','), o, n); - }).on('change', ['a', 'b', 'c'], function (o, n, p) { + }) + .on('remove', [], function (o, p, root) { + console.log("Removal of value [%s] at path [%s]", o, p.join(',')); + }) + .on('change', ['a', 'b', 'c'], function (o, n, p) { console.log("Deeper change event at [%s]: %s => %s", p.join(','), o, n); console.log("preventing propogation..."); return false; + }) + .on('disconnect', function (info) { + setEditable(false); + window.alert("Network connection lost"); }); - rt.proxy.on('disconnect', function (info) { - setEditable(false); - console.log(info); - window.alert("Network connection lost"); - }); - // set up user interface hooks $repl.on('keyup', function (e) { - if (e.which === 13) { + if (e.which === 13 /* enter keycode */) { var value = $repl.val(); if (!value.trim()) { return; }