Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tkurki committed Dec 4, 2023
1 parent 6d9905d commit 0277c4b
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/pipedproviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ interface PipedProviderConfig {
class PipedProvider {}

export function pipedProviders(
_app: SignalKMessageHub &
app: SignalKMessageHub &
WithConfig &
WithWrappedEmitter & {
propertyValues: PropertyValues
setProviderError: (providerId: string, msg: string) => void
}
) {
function createPipedProvider(providerConfig: PipedProviderConfig) {
const { propertyValues, ...sanitizedApp } = _app
const { propertyValues, ...sanitizedApp } = app
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const emitPropertyValue = (name: string, value: any) =>
propertyValues.emitPropertyValue({
Expand All @@ -81,8 +81,7 @@ export function pipedProviders(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const onPropertyValues = (name: string, cb: (value: any) => void) =>
propertyValues.onPropertyValues(name, cb)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const boundEventMethods = _app.wrappedEmitter.bindMethodsById(
const boundEventMethods = app.wrappedEmitter.bindMethodsById(
`connection:${providerConfig.id}` as EventsActorId
)
const appFacade = {
Expand Down Expand Up @@ -121,7 +120,6 @@ export function pipedProviders(
result.pipeElements[i].pipe(result.pipeElements[i + 1])
}

const app = _app
result.pipeElements[result.pipeElements.length - 1].pipe(new DevNull())
result.pipeElements[result.pipeElements.length - 1].on('data', (msg) => {
app.handleMessage(providerConfig.id, msg)
Expand All @@ -134,10 +132,10 @@ export function pipedProviders(
if (elementConfig.optionMappings) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
elementConfig.optionMappings.forEach(function (mapping: any) {
if (_.get(_app, mapping.fromAppProperty)) {
if (_.get(app, mapping.fromAppProperty)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(elementConfig.options as any)[mapping.toOption] = _.get(
_app,
app,
mapping.fromAppProperty
)
}
Expand All @@ -154,17 +152,17 @@ export function pipedProviders(
}

function startProviders() {
if (_app.config.settings.pipedProviders) {
if (app.config.settings.pipedProviders) {
const piped = (
_app.config.settings.pipedProviders as PipedProviderConfig[]
app.config.settings.pipedProviders as PipedProviderConfig[]
).reduce<PipedProvider[]>((result, config) => {
try {
if (typeof config.enabled === 'undefined' || config.enabled) {
result.push(createPipedProvider(config))
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
_app.setProviderError(config.id, e.message)
app.setProviderError(config.id, e.message)
console.error(e)
}
return result
Expand Down

0 comments on commit 0277c4b

Please sign in to comment.