Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(repsonse): generalized response structure #75

Open
sudojunior opened this issue Dec 14, 2024 · 0 comments
Open

feat(repsonse): generalized response structure #75

sudojunior opened this issue Dec 14, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@sudojunior
Copy link
Member

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

@sudojunior sudojunior added the enhancement New feature or request label Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant