From 1d4d076070507412ccc7e541f2ec759e71fde9b9 Mon Sep 17 00:00:00 2001 From: BluJ Date: Thu, 27 Apr 2023 11:31:01 -0600 Subject: [PATCH] chore: Make some things lazy --- lib/actions/setupActions.ts | 18 ++++++++++-------- lib/mainFn/LocalBinding.ts | 19 ++++++++++++------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/actions/setupActions.ts b/lib/actions/setupActions.ts index 21cbe64..1a6e60c 100644 --- a/lib/actions/setupActions.ts +++ b/lib/actions/setupActions.ts @@ -3,14 +3,16 @@ import { ActionMetaData } from "../types" import { CreatedAction } from "./createAction" export function setupActions(...createdActions: CreatedAction[]) { - const actions: Record = {} - for (const action of createdActions) { - actions[action.metaData.id] = action.exportedAction - } - - const actionsMetadata = createdActions.map((x) => x.metaData) return { - actions, - actionsMetadata, + get actions() { + const actions: Record = {} + for (const action of createdActions) { + actions[action.metaData.id] = action.exportedAction + } + return actions + }, + get actionsMetadata() { + return createdActions.map((x) => x.metaData) + }, } } diff --git a/lib/mainFn/LocalBinding.ts b/lib/mainFn/LocalBinding.ts index 6775517..e5cb986 100644 --- a/lib/mainFn/LocalBinding.ts +++ b/lib/mainFn/LocalBinding.ts @@ -17,15 +17,20 @@ export const ipv6 = once( export class LocalBinding { constructor(readonly localHost: string, readonly ipHosts: string[]) {} createOrigins(protocol: string) { + const ipHosts = this.ipHosts return { local: new Origin(protocol, this.localHost), - ip: this.ipHosts.map((x) => new Origin(protocol, x)), - ipv4: this.ipHosts - .filter(regexToTestIp4().test) - .map((x) => new Origin(protocol, x)), - ipv6: this.ipHosts - .filter(ipv6().test) - .map((x) => new Origin(protocol, x)), + get ip() { + return ipHosts.map((x) => new Origin(protocol, x)) + }, + get ipv4() { + return ipHosts + .filter(regexToTestIp4().test) + .map((x) => new Origin(protocol, x)) + }, + get ipv6() { + return ipHosts.filter(ipv6().test).map((x) => new Origin(protocol, x)) + }, } } }