Skip to content

Commit

Permalink
commands and minor improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
mayarajan3 committed May 24, 2024
1 parent d1be1dc commit 4e950d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions extensions/src/common/extension/decorators/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions extensions/src/common/extension/decorators/newBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export function makeDecorator<T>(type: T): TemplateEngine<T>["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);
Expand Down Expand Up @@ -74,7 +76,8 @@ export function makeDecorator<T>(type: T): TemplateEngine<T>["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<Fn>, target) });

Expand Down
9 changes: 7 additions & 2 deletions extensions/src/simple_example/index.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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: [
Expand Down

0 comments on commit 4e950d0

Please sign in to comment.