diff --git a/extensions/src/common/extension/decorators/blocks.ts b/extensions/src/common/extension/decorators/blocks.ts index b3b45c4e7..de473fa84 100644 --- a/extensions/src/common/extension/decorators/blocks.ts +++ b/extensions/src/common/extension/decorators/blocks.ts @@ -22,6 +22,7 @@ export const getAccessorPrefix = "__getter__"; export const setAccessorPrefix = "__setter__"; export const reporter = makeDecorator("reporter"); +export const command = makeDecorator("command"); /** * This a decorator function that should be associated with methods of your Extension class, all in order to turn your class methods diff --git a/extensions/src/common/extension/decorators/newBlocks.ts b/extensions/src/common/extension/decorators/newBlocks.ts index fb725961d..75198a0c9 100644 --- a/extensions/src/common/extension/decorators/newBlocks.ts +++ b/extensions/src/common/extension/decorators/newBlocks.ts @@ -24,8 +24,10 @@ export function makeDecorator(type: T): TemplateEngine["execute"] { // function takes T and returns a function of TemplateEngine type // TemplateEngine returns based on the ScratchType of the block - return function(builderOrStrings, ...args) { - return function(target, context) { + return function decoratorFn< + const Return + >(builderOrStrings, ...args) { + return function (target, context) { // Defining block characteristics const opcode = target.name; const internalFuncName = getImplementationName(opcode); @@ -74,7 +76,8 @@ export function makeDecorator(type: T): TemplateEngine["execute"] { } // Push the block - type Fn = (this: ExtensionInstance, value: any, util: BlockUtilityWithID) => void; + //type Fn = (this: This extends ExtensionInstance, value: any, util: BlockUtilityWithID) => void; + type Fn = (...args) => Return; const blockInfo = { type: blockType, text: textFunction, args: argList }; context.addInitializer(function () { this.pushBlock(opcode, blockInfo as BlockMetadata, target) }); diff --git a/extensions/src/simple_example/index.ts b/extensions/src/simple_example/index.ts index 69a3f222a..cd265e518 100644 --- a/extensions/src/simple_example/index.ts +++ b/extensions/src/simple_example/index.ts @@ -1,4 +1,4 @@ -import { ArgumentType, BlockType, BlockUtilityWithID, Environment, ExtensionMenuDisplayDetails, Language, Menu, SaveDataHandler, block, buttonBlock, extension, tryCastToArgumentType, untilTimePassed, reporter } from "$common"; +import { ArgumentType, BlockType, BlockUtilityWithID, Environment, ExtensionMenuDisplayDetails, Language, Menu, SaveDataHandler, block, buttonBlock, extension, tryCastToArgumentType, untilTimePassed, reporter, command } from "$common"; import jibo from "./jibo.png"; import five from "./five.png"; @@ -70,11 +70,16 @@ export default class SimpleTypescript extends extension(details, "ui", "customSa return x + y; } - @reporter((instance, $) => $`Add ${{type: "number", defaultValue: 3}} to ${"number"}: number complex`) + @reporter((self, $) => $`Add ${{type: "number", defaultValue: 3}} to ${"number"}: number complex`) reporterWithCallbackNumber(x: number, y: number) { return x + y; } + @command`Hello ${{type: "string", defaultValue: "there"}}` + simpleCommand(text: string) { + console.log(text); + } + @block({ type: "command", args: [