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

Make use of old block decorator in implementation of new tagged template decorator #358

Conversation

pmalacho-mit
Copy link
Collaborator

No description provided.

@@ -21,9 +21,6 @@ export const blockBundleEvent = tryCreateBundleTimeEvent<BlockFunctionMetadata>(
export const getAccessorPrefix = "__getter__";
export const setAccessorPrefix = "__setter__";

export const reporter = makeDecorator("reporter");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these from here to avoid a circular dependency

import { TypedMethodDecorator } from ".";

// This should be defined elsewhere
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: I have to imagine this is defined somewhere?!

export type MapToScratch<T extends any[], Internal extends TRemoveUtil<T> = TRemoveUtil<T>> = {
[k in keyof Internal]: Argument<Internal[k]>
}
}

interface TemplateEngine<TBlockType> {
// TODO: Restrict return based on Scratch type
Copy link
Collaborator Author

@pmalacho-mit pmalacho-mit May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually mean that we should make use of TBlockType by restricting the Return generic parameter based on the mapping we have of Block types to which method return types. ReturnTypeByBlockType I believe

instance: This,
tag: Utility.TaggedTemplate<Argument.MapToScratch<Args>, BlockMetadata<(...args: Args) => Return>>
) => BlockMetadata<(...args: Args) => Return>
): TypedMethodDecorator<This, Args, Return, Utility.Method<This, Args, Return>>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the nesting of angle boys and what not got things confused here, as well as the multiple levels of functions-as-arguments.

This execute function type definition takes a single argument, which is a function called "builder". "builder" is a function that takes two arguments, the second one being "tag". "tag" is a function that takes two arguments ... etc. etc. Importantly, the execute function is the thing that returns the TypedMethodDecorator

simpleReporterString(x: string, y: string) {
return x + y;
}
@(scratch.reporter`Add ${{ type: "string", defaultValue: "yee" }} to ${{ type: "string", defaultValue: "haw" }}: strings simple`)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, typescript is requiring us to wrap the decorator invocation in ( )s, not sure why, and I dont like it!

@pmalacho-mit
Copy link
Collaborator Author

@mayarajan3 chez it out! some TODOs for you to check out as well

@pmalacho-mit pmalacho-mit changed the title changes Make use of old block decorator in implementation of new tagged template decorator May 24, 2024
}

return (function () { return this[internalFuncName].call(this, ...arguments) });
const input: any = typeof builderOrStrings == "function"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably this shouldn't be any but I anticipate this being fairly challenging to make typescript happy about

reporterWithCallbackString(x: string, y: string) {
return x + y;
}
@(scratch.reporter((instance, $) => $`Add ${{ type: "string", defaultValue: "oo" }} to ${{ type: "string", defaultValue: "wee" }}: strings complex`))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Explore how the current implementation handles excess whitespace / new lines. E.g. what if this was formatted like this:

  @(scratch.reporter((instance, $) => $`Add 
    ${{ type: "string", defaultValue: "oo" }} to
    ${{ type: "string", defaultValue: "wee" }}: strings complex
  `))

Let's think about it, but imagine we should remove all new lines, and likely excess white space (so any consecutive spaces / tabs / new lines are reduced to a single space). This gives the developer freedom to format their templated string in a way that works for them without causing weird spacing in the look of their block.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this function effectively does this kind of thing (maybe not exactly the same, but fire it up in the typescript playground and see how it behaves):

https://github.com/mitmedialab/prg-ai-storybook-web/blob/main/packages/authoring/dialogue.ts#L48

@pmalacho-mit pmalacho-mit deleted the tagged-template-block_make-use-of-block-decorator branch June 21, 2024 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants