feat(hub): support functional/boolean when on dock entries#87
Closed
antfubot wants to merge 1 commit into
Closed
Conversation
Widen dock-entry `when` to `string | boolean | (() => string | boolean | undefined)`,
resolved to the existing `string | undefined` wire contract once per
`DevframeDocksHost.values()`/`projectView` serialization pass.
This lets a host give a dock registered via `docks.register(...)` or
mounted via `mountDevframe(ctx, def, { dock })` the same dynamic
visibility the built-in `~terminals`/`~messages` entries get from an
object-literal getter — a function survives `mountDevframe`'s
`...options.dock` spread by reference, where a getter would only run
once. Clients and `whenexpr` are unaffected; the resolved value is
still a plain string expression or `undefined`.
✅ Deploy Preview for devfra ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
What
Widens the dock-entry
whenfield (DevframeDockEntryBase.when, shared by every dock entry type) fromstringto:Adds a
resolveWhen()helper (packages/hub/src/node/when.ts, re-exported from@devframes/hub/node) that resolves any of those forms down to the existing wire contract —string | undefined— and wires it intoDevframeDocksHost'sprojectView(), the single place a registered entry is turned into its serializable form forvalues(). The resolution happens on a shallow copy, so the stored entry (and anywhenfunction on it) is left untouched for the next serialization pass.defineDockEntry'swhentype is widened the same way, andmountDevframe'sdockoption doc comment now calls out the function form.Why
whenon a dock entry is a string expression evaluated client-side. The built-in~terminals/~messagesdocks get dynamic visibility today via an object-literal getter (get when() { … }) on the entry returned fresh fromvalues()every call. That trick doesn't work for a dock registered viadocks.register(...)or mounted viamountDevframe(ctx, def, { dock }): the entry is stored once, andmountDevframe's...options.dockspread would evaluate a getter a single time and freeze it. A function value, by contrast, survives an object spread by reference, so allowingwhento be a function gives mounted/registered docks the same dynamic behavior the built-ins have, without any client-side changes.The wire contract is unchanged — clients and
whenexprkeep interpretingwhenexactly as before. The function/boolean form is purely a server-side authoring convenience resolved during serialization:false→'false'(unconditionally hidden)true/null/undefined→undefined(unconditionally visible)Testing
host-docks.test.ts(functionwhenre-resolves pervalues()call reflecting current state, boolean resolution, string passthrough, no mutation of the stored entry) andmount-devframe.test.ts(a functionwhenflows through the...options.dockspread and re-resolves per call).pnpm lint && pnpm test && pnpm typecheck && pnpm buildall pass, including the Next.js Turbopack example (had to move the newresolveWhenhelper into its ownnode/when.tsmodule rather than the existingnode/utils.ts, since the latter transitively pulls inmlly'stoDataURL, which broke that example's build oncehost-docks.tsimported from it).docs/guide/when-clauses.md.Created with the help of an agent.