Skip to content

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

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

Merged

Conversation

m-risto
Copy link
Contributor

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

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
});

Copy link

vercel bot commented Sep 16, 2024

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

Copy link

vercel bot commented Sep 16, 2024

@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
Copy link
Contributor Author

m-risto commented Sep 16, 2024

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

@matthewlipski matthewlipski merged commit efb420b into TypeCellOS:main Sep 18, 2024
4 checks passed
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