-
Notifications
You must be signed in to change notification settings - Fork 151
upgrade: event-bus package upgrade for Solid 2.0 #860
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
davedbase
merged 5 commits into
solidjs-community:next
from
davedbase:update/v2/event-bus
May 14, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
37b1bab
Ported to Solid 2.0 beta 10
davedbase 632a95d
Merge branch 'next' into update/v2/event-bus
davedbase e843b45
Added deprecation
davedbase a8d769d
Merge branch 'update/v2/event-bus' of https://github.com/davedbase/so…
davedbase 319f7ef
Added missing SSR test and adjusted cleanups
davedbase File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --- | ||
| "@solid-primitives/event-bus": major | ||
| --- | ||
|
|
||
| Migrate to Solid.js v2.0 (beta.10) | ||
|
|
||
| ## Breaking Changes | ||
|
|
||
| **Peer dependency**: `solid-js@^2.0.0-beta.10` is now required. | ||
|
|
||
| ### `batchEmits` | ||
|
|
||
| In Solid 2.0, all signal writes are automatically batched via microtasks. `batchEmits` is now a no-op that returns the bus unchanged. The `batch` wrapper has been removed. | ||
|
|
||
| ### `toEffect` | ||
|
|
||
| Updated to use the Solid 2.0 split `createEffect(compute, apply)` signature. The `on()` helper (removed in Solid 2.0) has been replaced with the split effect pattern. The reactive owner is now explicitly captured at creation time and forwarded via `runWithOwner` in the apply phase, since the apply phase is unowned in Solid 2.0. | ||
|
|
||
| ### `createEventStack` | ||
|
|
||
| The internal stack signal is created with `{ ownedWrite: true }` to allow writes from event listeners called within reactive contexts (e.g. `createRoot`, effects). Signal reads are now deferred in Solid 2.0, so the stack value emitted in event payloads is now computed inside the setter callback to ensure it reflects the updated state. | ||
|
|
||
| ### Tests | ||
|
|
||
| Tests that read signal values after `emit()` now require `flush()` to commit pending signal updates before assertions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { describe, test, expect, vi } from "vitest"; | ||
| import { createRoot } from "solid-js"; | ||
| import { createEventBus } from "../src/eventBus.js"; | ||
| import { createEmitter } from "../src/emitter.js"; | ||
| import { createEventStack } from "../src/eventStack.js"; | ||
| import { createEventHub } from "../src/eventHub.js"; | ||
|
|
||
| describe("API doesn't break in SSR", () => { | ||
| test("createEventBus() - SSR", () => | ||
| createRoot(dispose => { | ||
| const bus = createEventBus<string>(); | ||
| const cb = vi.fn(); | ||
| bus.listen(cb); | ||
| bus.emit("foo"); | ||
| expect(cb).toBeCalledWith("foo"); | ||
| dispose(); | ||
| })); | ||
|
|
||
| test("createEmitter() - SSR", () => | ||
| createRoot(dispose => { | ||
| const emitter = createEmitter<{ a: number }>(); | ||
| const cb = vi.fn(); | ||
| emitter.on("a", cb); | ||
| emitter.emit("a", 1); | ||
| expect(cb).toBeCalledWith(1); | ||
| dispose(); | ||
| })); | ||
|
|
||
| test("createEventStack() - SSR", () => | ||
| createRoot(dispose => { | ||
| const stack = createEventStack<{ text: string }>(); | ||
| expect(stack.value()).toEqual([]); | ||
| dispose(); | ||
| })); | ||
|
|
||
| test("createEventHub() - SSR", () => | ||
| createRoot(dispose => { | ||
| const hub = createEventHub({ | ||
| busA: createEventBus<number>(), | ||
| busB: createEventBus<string>(), | ||
| }); | ||
| const cb = vi.fn(); | ||
| hub.on("busA", cb); | ||
| hub.emit("busA", 42); | ||
| expect(cb).toBeCalledWith(42); | ||
| dispose(); | ||
| })); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.