Allow registering only specific action groups#333
Open
myabc wants to merge 1 commit into
Open
Conversation
3 tasks
There was a problem hiding this comment.
Pull request overview
Adds a new “action group” abstraction so library consumers can initialize TurboPower with only a selected subset of Turbo Stream actions (while still always registering morph via turbo-morph). This implements the API proposed in issue #20 and includes tests + README documentation to validate and explain the new behavior.
Changes:
- Introduces
ActionGroup,ActionGroups, andallActionGroups, and updatesActions.register()to accept an optional list of groups (defaulting to all). - Updates
TurboPower.initialize()to accept an optional second argument for selecting which groups to register, and re-exports the new group-related APIs. - Adds a comprehensive new test suite for default/all-groups behavior, subsets, empty arrays (morph-only), and export consistency; documents usage in the README.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/initialize.test.js | New tests covering default vs subset registration, morph always-on behavior, and export consistency/guards. |
| src/index.ts | Exposes and re-exports action group APIs; updates initialize() to accept action group selection; augments default export. |
| src/actions.ts | Implements the ActionGroup interface, central ActionGroups record, derived exports, allActionGroups, and updated register(). |
| README.md | Documents the new “register only specific actions” usage and lists available action groups. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
myabc
force-pushed
the
selective-action-groups
branch
from
June 27, 2026 13:59
3721065 to
f4c7b33
Compare
Add an optional second argument to `initialize()` (and `Actions.register()`)
so consumers can enable a subset of actions instead of all-or-nothing:
TurboPower.initialize(Turbo.StreamActions, [AttributeActions, BrowserActions])
Each module's register function is wrapped in a named `ActionGroup`
(`AttributeActions`, `BrowserActions`, ...). The groups are defined once in a
single `ActionGroups` record from which the named consts, `allActionGroups`,
and the default-export members are all derived, so adding a new group only
requires one edit.
When no groups are passed, every group is registered as before, keeping
existing callers working. The `morph` action from turbo-morph is always
registered regardless of the groups passed.
Closes marcoroth#20
Co-authored-by: Klaus Zanders <k.zanders@openproject.com>
myabc
force-pushed
the
selective-action-groups
branch
from
June 27, 2026 14:16
f4c7b33 to
eb38f53
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #20
Warning
This PR branches off
main(Turbo 7.x) and only touches the action-registration layer (src/actions.ts,src/index.ts), so it's orthogonal to #332 (Upgrade @hotwired/turbo to 8.x). The two don't conflict logically, but whichever lands second will need a trivial rebase. No behavioural interaction is expected — happy to rebase on top of #332 if you'd prefer to merge that first.What
Adds an optional second argument to
TurboPower.initialize()(andActions.register()) so consumers can enable a subset of actions instead of all-or-nothing:This matches the API proposed in #20 verbatim.
Why
This would help us cleanup our Turbo setup in a downstream project: https://github.com/opf/openproject/blob/dev/frontend/src/turbo/setup.ts#L59
How
ActionGroupinterface ({ register(streamActions): void }).ActionGroupsrecord. The named consts (AttributeActions,BrowserActions, …), theallActionGroupsarray, and the default-export members are all derived from that record — adding a new action group only requires one edit.register(streamActions, actionGroups = allActionGroups)iterates the groups. With no argument, every group registers as before, so existing callers are unaffected.allActionGroupsis frozen and typedreadonly, so consumer mutation can't corrupt the default used byregister.morph(fromturbo-morph) is always registered regardless of which groups are passed.allActionGroups,ActionGroups, and theActionGrouptype, and mirrors them all on the default export for UMD consumers.Tests
New
test/initialize/initialize.test.jscovering: all-groups default, subset, empty array (morph still registered), directActions.registerwith a subset, a table-driven smoke test that registers each group on its own and asserts a representative action (guards against a mis-wired mapping), every group present on the default export, named exports identical to default-export members, and anallActionGroupscount guard against list drift.Full suite: 224 passing.
Note for review
The friendly group names drop the plural the internal registrars use (
AttributeActions→registerAttributesActions,EventActions→registerEventsActions). They're self-consistent and match the spelling in #20, but since these become permanent public API, happy to adjust the naming if you'd prefer a different convention.Credit
Based on the original implementation by @klaustopher in opf#1 (credited as co-author on the commit).