Last active
August 29, 2015 13:56
-
-
Save mdobson/9113296 to your computer and use it in GitHub Desktop.
Alternatives to async provision
This file contains hidden or 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 HelloApp = module.exports = function() { | |
this.name = 'hello'; | |
}; | |
HelloApp.prototype.init = function(fog) { | |
fog.provision('photosensor', function(photosensor){ | |
photosensor.on('change', function(value) { | |
if (value < 100) { | |
led.call('turn-on'); | |
} else { | |
led.call('turn-off'); | |
} | |
fog.expose('/photosensor', photosensor); | |
}); | |
}); | |
fog.provision('led', function(led){ | |
led.on('turn-on', function() { | |
console.log('turning on led'); | |
}); | |
led.on('turn-off', function() { | |
console.log('turning off led'); | |
}); | |
fog.expose('/led', led); | |
}); | |
}; |
This file contains hidden or 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 HelloApp = module.exports = function() { | |
this.name = 'hello'; | |
}; | |
HelloApp.prototype.init = function(fog) { | |
var photosensor = fog.provision('photosensor'); | |
var led = fog.provision('led'); | |
led.on('ready', function() { | |
led.on('turn-on', function() { | |
console.log('turning on led'); | |
}); | |
led.on('turn-off', function() { | |
console.log('turning off led'); | |
}); | |
fog.expose('/led', led); | |
}); | |
photosensor.on('ready', function() { | |
photosensor.on('change', function(value) { | |
if (value < 100) { | |
led.call('turn-on'); | |
} else { | |
led.call('turn-off'); | |
} | |
}); | |
fog.expose('/photosensor', photosensor); | |
}); | |
}; |
This file contains hidden or 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 HelloApp = module.exports = function() { | |
this.name = 'hello'; | |
}; | |
HelloApp.prototype.init = function(fog) { | |
fog.provision('photosensor'); | |
fog.provision('led'); | |
HelloApp.on('ready', function(photosensor, led) { | |
led.on('turn-on', function() { | |
console.log('turning on led'); | |
}); | |
led.on('turn-off', function() { | |
console.log('turning off led'); | |
}); | |
photosensor.on('change', function(value) { | |
if (value < 100) { | |
led.call('turn-on'); | |
} else { | |
led.call('turn-off'); | |
} | |
}); | |
fog.expose('/led', led); | |
fog.expose('/photosensor', photosensor); | |
}); | |
}; |
This file contains hidden or 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 HelloApp = module.exports = function() { | |
this.name = 'hello'; | |
this.photosensor = fog.provision('photosensor'); | |
this.led = fog.provision('led'); | |
}; | |
HelloApp.prototype.ready = function(fog) { | |
this.led.on('turn-on', function() { | |
console.log('turning on led'); | |
}); | |
this.led.on('turn-off', function() { | |
console.log('turning off led'); | |
}); | |
this.photosensor.on('change', function(value) { | |
if (value < 100) { | |
this.led.call('turn-on'); | |
} else { | |
this.led.call('turn-off'); | |
} | |
}); | |
fog.expose('/led', this.led); | |
fog.expose('/photosensor', this.photosensor); | |
}; |
module.exports = function(elroy) {
elroy.get('photosensor', function(err, photosensor) {
elroy.get('led', function(err, led) {
led.on('turn-on', function() {
console.log('on');
});
led.on('turn-off', function() {
console.log('off');
});
photosensor.on('change', function(value) {
if (value < 100) {
led.call('turn-on');
} else {
led.call('turn-off');
}
});
led.on('error', function(err) {
if (typeof err !== elroy.TransitionError) {
throw err;
}
});
elroy.expose(led);
});
elroy.expose(photosensor);
});
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Settled on this: