From 4a2c8147aa6f0b4fd990f67413ddec0e1eb55fa3 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 10 May 2016 22:40:49 -0400 Subject: [PATCH] Enable and disable the IoT demo spawn/kill buttons. Previous commit changed DOM fragment representation to use strings instead of Seal'd quasi-sexprs, and so eliminated any distinction between textually-identical DOM fragments in the dataspace. This patch disables the "spawn" buttons for components in the IoT demo to avoid (mostly harmless) duplication of actor instances. It also demonstrates use of react{} outside a *lexically*-enclosing actor{}. --- js/examples/iot/index.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/js/examples/iot/index.js b/js/examples/iot/index.js index 8ff23b3..445698c 100644 --- a/js/examples/iot/index.js +++ b/js/examples/iot/index.js @@ -183,12 +183,32 @@ function spawnFailureMonitor() { function spawnChaosMonkey() { actor { + monitorComponent('power draw monitor', + '#spawn-power-draw-monitor', + '#kill-power-draw-monitor', + spawnPowerDrawMonitor); + monitorComponent('stove switch', + '#spawn-stove-switch', + '#kill-stove-switch', + spawnStoveSwitch); + } + + function monitorComponent(name, spawnButtonSelector, killButtonSelector, spawnFunction) { + var jSpawnButtons = $(spawnButtonSelector); + var jKillButtons = $(killButtonSelector); react { - on message jQueryEvent('#spawn-power-draw-monitor', 'click', _) { - spawnPowerDrawMonitor(); + during componentPresent(name) { + do { + jSpawnButtons.prop('disabled', true); + jKillButtons.prop('disabled', false); + } + finally { + jSpawnButtons.prop('disabled', false); + jKillButtons.prop('disabled', true); + } } - on message jQueryEvent('#spawn-stove-switch', 'click', _) { - spawnStoveSwitch(); + on message jQueryEvent(spawnButtonSelector, 'click', _) { + spawnFunction(); } } }