Expand CompanionActionDefinition type#225
Conversation
…e-base into feat/insufficient-permissions-status
…hHooks and CompanionActionDefintionWithoutHooks, to mandate the presence of optionsToMonitorForSubscribe when either a subscribe or unsubscribe callback is ppresent, and make sure optionsToMonitorForSubscribe and skipUnsubscribeOnOptionsChange are absent when neither subscribe or unsubscribe are present
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRefactors action typing: extracts shared fields into ChangesAction type refactor
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 59 minutes.Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/base/src/module-api/action.ts (1)
99-99: Consider exportingCompanionActionDefinitionWithSubscribeHooksfor symmetry 📦Small thing —
CompanionActionDefinitionWithoutSubscribeHooksis exported on line 84, but its sibling here is kept private. Module authors who want to type a helper or a factory specifically for the "with hooks" variant currently can't reference it by name. Exporting it would make the two branches of the union equally addressable, and matches what the PR title (“ExpandCompanionActionDefinitiontype”) implies for the public API surface. Totally optional though — happy either way!♻️ Suggested change
-type CompanionActionDefinitionWithSubscribeHooks<TOptions extends CompanionOptionValues = CompanionOptionValues> = +export type CompanionActionDefinitionWithSubscribeHooks<TOptions extends CompanionOptionValues = CompanionOptionValues> = CompanionActionDefinitionBase<TOptions> & {
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ad05b4a2-5e3e-45d1-b728-fee273b5c9d6
📒 Files selected for processing (1)
packages/base/src/module-api/action.ts
|
After some more thought, I think at least the subscribe property should be mandatory, for the sake of simpler types, and because I can't think of an instance where you would want an unsubscribe without a subscribe; however I will wait until others have a chance to chime in before making further changes. |
|
If #217 is taken in some form, It's entirely possible this is simply unavoidable. Still, worth flagging to see if we can somehow manage to keep the complexity down, to the extent possible. |
|
Making at least the subscribe property mandatory would make the |
|
I have very little sense of how sub/unsub tends to be used. But I think it's quite reasonable to say if you want one, you have to do 'em both. (The only module I control that uses subscribe/unsubscribe, does so essentially as hackaround to avoid creating a mass of variables up front. I would have no complaints about having to define a vacuous unsubscribe, if it came to it.) |
|
From memory (ie, untrustworthy) the only module I've worked on with an unsubscribe flow for actions is the Qsys one. I find them a bit more common for feedbacks; especially if the module is checking feedbacks by id (which I've come to use fairly often of late because I prefer the development flow (rather than for performance gains)). |
|
I've changed |
|
@phillipivan I've pushed a commit to this branch, adjusting it to use composition instead of inheritence. The hope is to avoid naming many flavours once we add a second type of variation. Let me know what you think, I'm open to reverting my change if you disagree. I havent checked (either version), but hopefully the typedoc will remain sane |
|
Haven't tested but lgtm. The only downside I can see, which is more theoretical that anything, is if someone wanted to explicitly type an action definition with subscribe hooks that would be more fiddly (rather than just leaving it to the type system to figure it out). However given this is not an option anyone has had to date, I expect no one will think to use it or miss it. |
yeah that is my hope. and I think the modularity will be a benefit to us, so if it discourages using specific interfaces in typing then that could also be a good thing |
Make
CompanionActionDefinitiona union ofCompanionActionDefinitionWithSubscribeHooksandCompanionActionDefinitionWithoutSubscribeHooks. Discussed here on slack.Thus when the
subscribecallback is present,optionsToMonitorForSubscribemust be present. The purpose of this is to prompt developers to set this field during development, rather than waiting to find the current run time log messages warning the field is absent.optionsToMonitorForSubscribeandskipUnsubscribeOnOptionsChangemust be absent when the subscribe and unsubscribe callbacks are absent to avoid a confusing and pointless, but probably harmless configuration.No longer relevant:
Summary by CodeRabbit