Skip to content

feat: make callback return value optional in forEachBlock function - #1081

Merged
matthewlipski merged 1 commit into
TypeCellOS:mainfrom
m-risto:for-each-block-optional-return
Sep 18, 2024
Merged

feat: make callback return value optional in forEachBlock function#1081
matthewlipski merged 1 commit into
TypeCellOS:mainfrom
m-risto:for-each-block-optional-return

Conversation

@m-risto

@m-risto m-risto commented Sep 16, 2024

Copy link
Copy Markdown
Contributor

This pull request introduces an enhancement to the forEachBlock function by making the callback return value optional. Previously, the forEachBlock function expected the callback to return a value that is explicitly checked against false to determine whether to break out of the loop. With this update, the callback return value becomes optional, and the loop will continue to the next block if the callback returns undefined or true.

Changes:

  1. Modified the forEachBlock function logic:

    if (callback(block) === false) {
      return false;
    }

    has been altered to handle optional return values more gracefully.

  2. Updated Usage:

    • If the callback returns false, the function will still exit early.
    • If the callback returns undefined or true, the function will continue iterating through the blocks.

Reasons for Change:

  • Flexibility: This change provides more flexibility in using the forEachBlock function by not forcing callbacks to always return a value.
  • Backward Compatibility: Existing code that relies on the callback returning false to break the loop will continue to function as expected. Hence, this is a non-breaking change.
  • Cleaner Code: Allows for cleaner callback implementations where returning a value is unnecessary.

Example Usage:

Before:

forEachBlock(block, (block) => {
  // some logic
  return true; // or return false explicitly
});

After:

forEachBlock(block, (block) => {
  // some logic
  // no need to return true explicitly
});

@vercel

vercel Bot commented Sep 16, 2024

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
blocknote ✅ Ready (Inspect) Visit Preview Sep 18, 2024 1:57pm
blocknote-website ✅ Ready (Inspect) Visit Preview Sep 18, 2024 1:57pm

@vercel

vercel Bot commented Sep 16, 2024

Copy link
Copy Markdown

@m-risto is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@m-risto
m-risto force-pushed the for-each-block-optional-return branch from dac261d to 3f16da3 Compare September 16, 2024 19:07
@m-risto
m-risto force-pushed the for-each-block-optional-return branch from 3f16da3 to 86d93e7 Compare September 16, 2024 19:08
@m-risto

m-risto commented Sep 16, 2024

Copy link
Copy Markdown
Contributor Author

Updated it, before there were some changes to import ordering by my ide.

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.

3 participants