rxpoweredup
Version:
A Typescript RxJS-based library for controlling LEGO Powered UP hubs & peripherals.
76 lines (75 loc) • 4.67 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
import { inject, injectable } from 'tsyringe';
import { Hub } from './hub';
import { HUB_CONNECTION_ERRORS_FACTORY } from './i-hub-connection-errors-factory';
import { CHARACTERISTIC_DATA_STREAM_FACTORY } from './i-characteristic-data-stream-factory';
import { OUTBOUND_MESSAGE_FACTORY } from './i-outbound-messenger-factory';
import { HUB_PROPERTY_FEATURE_FACTORY } from './i-hub-properties-feature-factory';
import { MOTORS_FEATURE_FACTORY } from './i-motors-feature-factory';
import { PORTS_FEATURE_FACTORY } from './i-ports-feature-factory';
import { INBOUND_MESSAGE_LISTENER_FACTORY } from './i-inbound-message-listener-factory';
import { GENERIC_ERRORS_REPLIES_PARSER } from './generic-errors-reply-parser';
import { PREFIXED_CONSOLE_LOGGER_FACTORY } from './i-prefixed-console-logger-factory';
import { HUB_CONFIG_DEFAULTS } from './hub-config';
import { HUB_ACTIONS_FEATURE_FACTORY } from './i-hub-actions-feature-factory';
import { RGB_LIGHT_FEATURE_FACTORY } from './i-rgb-light-feature-factory';
let HubFactory = class HubFactory {
connectionErrorFactory;
outboundMessengerFactory;
hubPropertiesFactory;
ioFeatureFactoryService;
characteristicsDataStreamFactory;
motorsFeatureFactory;
ledFeatureFactory;
genericErrorsReplyParser;
messageListenerFactory;
loggerFactory;
hubActionsFeatureFactory;
constructor(connectionErrorFactory, outboundMessengerFactory, hubPropertiesFactory, ioFeatureFactoryService, characteristicsDataStreamFactory, motorsFeatureFactory, ledFeatureFactory, genericErrorsReplyParser, messageListenerFactory, loggerFactory, hubActionsFeatureFactory) {
this.connectionErrorFactory = connectionErrorFactory;
this.outboundMessengerFactory = outboundMessengerFactory;
this.hubPropertiesFactory = hubPropertiesFactory;
this.ioFeatureFactoryService = ioFeatureFactoryService;
this.characteristicsDataStreamFactory = characteristicsDataStreamFactory;
this.motorsFeatureFactory = motorsFeatureFactory;
this.ledFeatureFactory = ledFeatureFactory;
this.genericErrorsReplyParser = genericErrorsReplyParser;
this.messageListenerFactory = messageListenerFactory;
this.loggerFactory = loggerFactory;
this.hubActionsFeatureFactory = hubActionsFeatureFactory;
}
create(device, config = {}) {
const combinedConfig = this.mergeConfigs(config);
return new Hub(device, config.logger ?? this.loggerFactory.createLogger(device.name ?? device.id, combinedConfig.logLevel), combinedConfig, this.connectionErrorFactory, this.outboundMessengerFactory, this.hubPropertiesFactory, this.ioFeatureFactoryService, this.characteristicsDataStreamFactory, this.motorsFeatureFactory, this.genericErrorsReplyParser, this.messageListenerFactory, this.hubActionsFeatureFactory, this.ledFeatureFactory);
}
mergeConfigs(...configs) {
return Object.assign({}, HUB_CONFIG_DEFAULTS, ...configs);
}
};
HubFactory = __decorate([
injectable(),
__param(0, inject(HUB_CONNECTION_ERRORS_FACTORY)),
__param(1, inject(OUTBOUND_MESSAGE_FACTORY)),
__param(2, inject(HUB_PROPERTY_FEATURE_FACTORY)),
__param(3, inject(PORTS_FEATURE_FACTORY)),
__param(4, inject(CHARACTERISTIC_DATA_STREAM_FACTORY)),
__param(5, inject(MOTORS_FEATURE_FACTORY)),
__param(6, inject(RGB_LIGHT_FEATURE_FACTORY)),
__param(7, inject(GENERIC_ERRORS_REPLIES_PARSER)),
__param(8, inject(INBOUND_MESSAGE_LISTENER_FACTORY)),
__param(9, inject(PREFIXED_CONSOLE_LOGGER_FACTORY)),
__param(10, inject(HUB_ACTIONS_FEATURE_FACTORY)),
__metadata("design:paramtypes", [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object])
], HubFactory);
export { HubFactory };