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

Core: Add untilEvent and toChannelEvent to UniversalStore #30709

Open
wants to merge 7 commits into
base: next
Choose a base branch
from

Conversation

JReinhold
Copy link
Contributor

@JReinhold JReinhold commented Feb 27, 2025

What I did

This PR adds two methods to the UniversalStore, in anticipation of their needs later:

  1. untilEvent - wait for an event to fire once, or optionally also another event that rejects the promise instead
  2. toChannelEvent - converts a universal store event to a raw channel event that can be sent directly on the channel when necessary.

Also added usage examples to all methods in JSDocs

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 79.7 MB 79.7 MB 106 B 0.44 0%
initSize 79.7 MB 79.7 MB 106 B 0.44 0%
diffSize 97 B 97 B 0 B - 0%
buildSize 7.31 MB 7.31 MB 5.34 kB 1.09 0.1%
buildSbAddonsSize 1.9 MB 1.9 MB 1.31 kB 0.67 0.1%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.89 MB 1.89 MB 3.6 kB 0.5 0.2%
buildSbPreviewSize 0 B 0 B 0 B - -
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.98 MB 3.99 MB 4.91 kB 2.02 0.1%
buildPreviewSize 3.33 MB 3.33 MB 437 B 0.4 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 19.8s 8s -11s -767ms -0.97 -146%
generateTime 18.7s 21.7s 3s 0.75 13.9%
initTime 4.3s 4.8s 517ms 0.18 10.7%
buildTime 8.2s 9s 814ms -0.57 9%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 5.3s 6.3s 997ms 1.72 🔺15.6%
devManagerResponsive 5.1s 5.9s 785ms 1.54 🔺13.1%
devManagerHeaderVisible 781ms 914ms 133ms 0.6 14.6%
devManagerIndexVisible 791ms 994ms 203ms 0.87 20.4%
devStoryVisibleUncached 1.7s 2.6s 897ms 2.51 🔺34.1%
devStoryVisible 810ms 993ms 183ms 0.58 18.4%
devAutodocsVisible 842ms 884ms 42ms 0.82 4.8%
devMDXVisible 703ms 888ms 185ms 0.94 20.8%
buildManagerHeaderVisible 665ms 803ms 138ms 0.55 17.2%
buildManagerIndexVisible 727ms 900ms 173ms 0.95 19.2%
buildStoryVisible 649ms 788ms 139ms 0.75 17.6%
buildAutodocsVisible 581ms 704ms 123ms 0.64 17.5%
buildMDXVisible 547ms 747ms 200ms 1.53 🔺26.8%

Greptile Summary

I'll provide a concise review of the PR that adds untilEvent and toChannelEvent methods to the UniversalStore class.

This PR enhances the UniversalStore with two new utility methods that improve event handling and channel communication capabilities.

  • Added untilEvent method to UniversalStore that returns a Promise resolving when a specific event occurs, with optional rejection on another event
  • Added toChannelEvent method to convert store events to raw channel events for direct channel emission
  • Updated MockUniversalStore to properly spy on these new methods when test utilities are provided
  • Added comprehensive test coverage for both methods in index.test.ts
  • Enhanced documentation with JSDocs examples for all methods, improving developer experience

The implementation is well-typed and follows the existing patterns in the codebase, making it a solid addition to the UniversalStore API.

Greptile AI: Universal Store event handling improvements

@JReinhold JReinhold self-assigned this Feb 27, 2025
Copy link

nx-cloud bot commented Feb 27, 2025

View your CI Pipeline Execution ↗ for commit f380eca.

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 1m 58s View ↗

☁️ Nx Cloud last updated this comment at 2025-02-27 20:29:10 UTC

@JReinhold JReinhold assigned yannbf and unassigned yannbf Feb 27, 2025
@JReinhold JReinhold requested review from yannbf and Copilot February 27, 2025 14:49
@JReinhold JReinhold marked this pull request as ready for review February 27, 2025 14:49

Choose a reason for hiding this comment

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

PR Overview

This PR enhances the UniversalStore with two new methods – untilEvent and toChannelEvent – and updates documentation and unit tests accordingly.

  • Added untilEvent to wait for one or two events with resolve/reject behavior
  • Implemented toChannelEvent to convert store events for direct channel communication
  • Updated unit tests and the mock store to reflect these new methods

Reviewed Changes

File Description
code/core/src/shared/universal-store/index.test.ts Adds unit tests for untilEvent and toChannelEvent methods
code/core/src/shared/universal-store/index.ts Adds documentation examples and implementations for new methods
code/core/src/shared/universal-store/mock.ts Updates mocks to include the new untilEvent and toChannelEvent methods

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile

@storybook-pr-benchmarking
Copy link

storybook-pr-benchmarking bot commented Feb 27, 2025

Package Benchmarks

Commit: f380eca, ran on 27 February 2025 at 20:35:53 UTC

The following packages have significant changes to their size or dependencies:

storybook

Before After Difference
Dependency count 52 52 0
Self size 19.41 MB 19.46 MB 🚨 +46 KB 🚨
Dependency size 14.26 MB 14.26 MB 0 B
Bundle Size Analyzer Link Link

sb

Before After Difference
Dependency count 53 53 0
Self size 1 KB 1 KB 0 B
Dependency size 33.67 MB 33.72 MB 🚨 +46 KB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 357 357 0
Self size 278 KB 278 KB 0 B
Dependency size 84.15 MB 84.20 MB 🚨 +47 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 275 275 0
Self size 617 KB 617 KB 0 B
Dependency size 65.74 MB 65.79 MB 🚨 +47 KB 🚨
Bundle Size Analyzer Link Link

@JReinhold JReinhold requested a review from ndelangen February 27, 2025 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants