-
Notifications
You must be signed in to change notification settings - Fork 41
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
Make use of old block
decorator in implementation of new tagged template decorator
#358
Conversation
@@ -21,9 +21,6 @@ export const blockBundleEvent = tryCreateBundleTimeEvent<BlockFunctionMetadata>( | |||
export const getAccessorPrefix = "__getter__"; | |||
export const setAccessorPrefix = "__setter__"; | |||
|
|||
export const reporter = makeDecorator("reporter"); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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>>; |
There was a problem hiding this comment.
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`) |
There was a problem hiding this comment.
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!
@mayarajan3 chez it out! some TODOs for you to check out as well |
block
decorator in implementation of new tagged template decorator
} | ||
|
||
return (function () { return this[internalFuncName].call(this, ...arguments) }); | ||
const input: any = typeof builderOrStrings == "function" |
There was a problem hiding this comment.
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`)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
No description provided.