UNPKG

biodome

Version:

Home automation you can live with

44 lines (36 loc) 1.64 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var CommandDispatcher = (function () { function CommandDispatcher(events) { _classCallCheck(this, CommandDispatcher); this.events = events; } _createClass(CommandDispatcher, [{ key: 'on', value: function on(id) { this.dispatch({ id: id, value: 1 }); } }, { key: 'off', value: function off(id) { this.dispatch({ id: id, value: 0 }); } }, { key: 'dispatch', value: function dispatch(cmd) { var mode = cmd.value === undefined ? 'read' : 'write'; var selector = cmd.id ? { id: cmd.id } : { type: cmd.type }; this.events.emit('command', { selector: selector, instruction: { type: mode, value: cmd.value } }); } }]); return CommandDispatcher; })(); exports['default'] = CommandDispatcher; module.exports = exports['default'];