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

Allow refreshBlocks() to specify extension #228

Merged
merged 4 commits into from
Dec 26, 2024

Conversation

FurryR
Copy link

@FurryR FurryR commented Oct 6, 2024

Resolves

The base of dynamic blocks.

Proposed Changes

Added a optional parameter to refreshBlocks, allowing specify which extension to refresh.

Reason for Changes

Performance considerations. This change was originally made by Gandi IDE, used for dynamic blocks (maybe), and I think we also need one.

Test Coverage

N/A. No tests for refreshBlocks found.

@LilyMakesThings
Copy link

Oh this'd be amazing

Copy link
Member

@yuri-kiss yuri-kiss left a comment

Choose a reason for hiding this comment

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

Works as intended. No issues with existing category's or extensions occurred during testing.

Testing extension
Af of now pressing any of these buttons would refresh ALL of the extensions updating the labels and count for every extension, on this pr it only does it for the individual extension you choose to refresh.

(function(Scratch) {
  let countA = -1;
  class extensionA {
    getInfo() {
      return {
        id: '0znzwRefTest1',
        name: 'Refresh Test (A)',
        blocks: [{
          blockType: Scratch.BlockType.LABEL,
          text: `Extension refreshed ${++countA} times`,
        }],
      };
    }
  }
  let countB = -1;
  class extensionB {
    getInfo() {
      return {
        id: '0znzwRefTest2',
        name: 'Refresh Test (B)',
        blocks: [{
          blockType: Scratch.BlockType.LABEL,
          text: `Extension refreshed ${++countB} times`,
        }],
      };
    }
  }
  class extensionC {
    getInfo() {
      return {
        id: '0znzwRefTest3',
        name: 'Refresh Test (C)',
        blocks: [{
          blockType: Scratch.BlockType.LABEL,
          text: `Extensions refreshed total ${(countA + countB)} times`,
        }, {
          blockType: Scratch.BlockType.BUTTON,
          func: 'refreshALL',
          text: 'Refresh all',
        }, {
          blockType: Scratch.BlockType.BUTTON,
          func: 'refreshA',
          text: 'Refresh (A)',
        }, {
          blockType: Scratch.BlockType.BUTTON,
          func: 'refreshB',
          text: 'Refresh (B)',
        }, {
          blockType: Scratch.BlockType.BUTTON,
          func: 'refreshC',
          text: 'Refresh (C)',
        }],
      };
    }
    refreshALL() {
      Scratch.vm.extensionManager.refreshBlocks();
    }
    refreshA() {
      Scratch.vm.extensionManager.refreshBlocks('0znzwRefTest1');
    }
    refreshB() {
      Scratch.vm.extensionManager.refreshBlocks('0znzwRefTest2');
    }
    refreshC() {
      Scratch.vm.extensionManager.refreshBlocks('0znzwRefTest3');
    }
  }
  Scratch.extensions.register(new extensionA());
  Scratch.extensions.register(new extensionB());
  Scratch.extensions.register(new extensionC());
})(Scratch);

@GarboMuffin
Copy link
Member

do you have any complaints about making unknown extensions be an error instead of silently ignoring it and refreshing all the extensions ?

@yuri-kiss
Copy link
Member

do you have any complaints about making unknown extensions be an error instead of silently ignoring it and refreshing all the extensions ?

Nope, I think it should error as it clarifys things more

@GarboMuffin GarboMuffin merged commit 56825e3 into TurboWarp:develop Dec 26, 2024
1 check passed
GarboMuffin added a commit to TurboWarp/types-tw that referenced this pull request Dec 26, 2024
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.

4 participants