chore: Make some things lazy

This commit is contained in:
BluJ
2023-04-27 11:31:01 -06:00
parent c7d38fc7ce
commit 1d4d076070
2 changed files with 22 additions and 15 deletions

View File

@@ -3,14 +3,16 @@ import { ActionMetaData } from "../types"
import { CreatedAction } from "./createAction" import { CreatedAction } from "./createAction"
export function setupActions(...createdActions: CreatedAction<any, any>[]) { export function setupActions(...createdActions: CreatedAction<any, any>[]) {
return {
get actions() {
const actions: Record<string, ExportedAction> = {} const actions: Record<string, ExportedAction> = {}
for (const action of createdActions) { for (const action of createdActions) {
actions[action.metaData.id] = action.exportedAction actions[action.metaData.id] = action.exportedAction
} }
return actions
const actionsMetadata = createdActions.map((x) => x.metaData) },
return { get actionsMetadata() {
actions, return createdActions.map((x) => x.metaData)
actionsMetadata, },
} }
} }

View File

@@ -17,15 +17,20 @@ export const ipv6 = once(
export class LocalBinding { export class LocalBinding {
constructor(readonly localHost: string, readonly ipHosts: string[]) {} constructor(readonly localHost: string, readonly ipHosts: string[]) {}
createOrigins(protocol: string) { createOrigins(protocol: string) {
const ipHosts = this.ipHosts
return { return {
local: new Origin(protocol, this.localHost), local: new Origin(protocol, this.localHost),
ip: this.ipHosts.map((x) => new Origin(protocol, x)), get ip() {
ipv4: this.ipHosts return ipHosts.map((x) => new Origin(protocol, x))
},
get ipv4() {
return ipHosts
.filter(regexToTestIp4().test) .filter(regexToTestIp4().test)
.map((x) => new Origin(protocol, x)), .map((x) => new Origin(protocol, x))
ipv6: this.ipHosts },
.filter(ipv6().test) get ipv6() {
.map((x) => new Origin(protocol, x)), return ipHosts.filter(ipv6().test).map((x) => new Origin(protocol, x))
},
} }
} }
} }