Skip to content

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

@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

This comment was marked as abuse.

@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