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{}.
This commit is contained in:
Tony Garnock-Jones 2016-05-10 22:40:49 -04:00
parent dede7f08a7
commit 4a2c8147aa
1 changed files with 24 additions and 4 deletions

View File

@ -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();
}
}
}