Skip to content

feat(repsonse): generalized response structure #75

Open
@sudojunior

Description

@sudojunior

https://github.com/slash-create/docs-bot/blob/99905ffe8e330bb772f76f9409e05e1eb98f92b7/src/modules/discord/responses.ts#L1-L13

Rework to { name, value, toString } or...

... a proxy

... ok never mind

type ResponseProxy<T, M> = {
    (): T;
} & { readonly [K in keyof M]: M[K] };

function response<T>(name: string, value?: T): ResponseProxy<{ name: string, value: T }, T> {
  return new Proxy({ name, value }, {
    apply(target, thisArg, argumentsList) {
        console.log("inside", target, thisArg, argumentsList);
        console.log("inside", name);
        return name;
    }
  }) as unknown as ResponseProxy<{ name: string, value: T }, T>;
}

const select = response<string>("Please select a `library` before using this option.", "null");

console.log(select.name, select.value);
console.log(select());

The other option would probably be json or xml format like what's being considered for #73

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions