The #fetch utility acts in (roughly) the same way as Ruby's Hash#fetch function.
This addition should hopefully make constructors more rigorous and help to
prevent a few classes of errors.
This change gives adaptors/drivers more flexibility in halting. Additionally,
now, by default, all Adaptors/Drivers will remove all their event listeners
before halting, which should prevent some additional commands from being sent to
the adaptor during shutdown.
These events are being removed, as they're essentially useless in most cases, as
the events will already have been emitted before the work block is run to set up
handlers for them.
Also removes the find{Robot,RobotConnection,RobotDevice} methods. Additionally,
stops passing the Master through to the Robot constructor, we can just
require('./cylon') if we need to access anything in there.
This commit reframes the Utils module to be more self-contained, and now only
the Number prototype methods and the every/after/constantly methods are exposed
globally.
I'm unsure about whether these methods can be more scoped such that people can
turn them off if they want, but that's potentially something to look into in the
future.
This commit also updates most of the other source files in Cylon, requiring the
Utils module rather than assuming the methods are in the global namespace.
A similar batch of commits will need to be made for all other Cylon modules to
make sure they don't explode when they can't find #subclass or something like
that.
To make the previously-global methods available, both in submodules and for
people looking for them, all the utility functions are exported in Cylon.Utils.
Robots can now take a break and have #play functions instead of #work.
Internally they're treated the same, but it's a fun easter egg!
Example:
Cylon.robot({
name: 'Jack',
connections: [],
devices: [],
play: function play(my) {
every((5).seconds(), function() {
console.log("All work and no play makes %s a dull boy.", my.name);
});
}
});
I sincerely apologize for the repeated reference to The Shining, blame
@deadprogram.
Closes#189.
Acts exactly the same with much, much less code complexity.
This also introduces a pattern for providing core modules to external libraries.
Whereas previously Cylon modules were able to rely on Cylon.Adaptor or
Cylon.Driver being present in the namespace (due to being required in
./lib/cylon), they will now need to require Cylon first, like this:
var Cylon = require('cylon');
var Driver = Cylon.Driver,
Adaptor = Cylon.Adaptor,
DigitalPin = Cylon.IO.DigitalPin;