-
Notifications
You must be signed in to change notification settings - Fork 446
refactor(desktop): share the feature services context and pass bridge namespaces through #4590
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { createContext, useContext, type ReactElement, type ReactNode } from 'react'; | ||
|
|
||
| export interface ServicesContext<S> { | ||
| /** Mounts one services object for the feature's subtree. */ | ||
| readonly Provider: (props: { | ||
| readonly services: S; | ||
| readonly children?: ReactNode; | ||
| }) => ReactElement; | ||
| /** Reads the mounted services; throws when the Provider is missing. */ | ||
| readonly useServices: () => S; | ||
| } | ||
|
|
||
| /** | ||
| * One services context per feature slice. | ||
| * | ||
| * A slice declares its inward-facing services type in `ports.ts` and gets the | ||
| * Provider/hook pair from here instead of restating twenty lines of | ||
| * `createContext` boilerplate. `providerName` is the Provider's displayName | ||
| * and the name in the error a consumer sees when nothing is mounted, so the | ||
| * message stays `<Feature>ServicesProvider is missing` for every slice. | ||
| */ | ||
| export function createServicesContext<S>(providerName: string): ServicesContext<S> { | ||
| const Context = createContext<S | null>(null); | ||
| function Provider(props: { | ||
| readonly services: S; | ||
| readonly children?: ReactNode; | ||
| }): ReactElement { | ||
| return <Context.Provider value={props.services}>{props.children}</Context.Provider>; | ||
| } | ||
| Provider.displayName = providerName; | ||
| function useServices(): S { | ||
| const services = useContext(Context); | ||
| if (!services) throw new Error(`${providerName} is missing`); | ||
| return services; | ||
| } | ||
| return { Provider, useServices }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,19 +27,6 @@ export function createDesktopSessionNavigationServices( | |
| bridge: DesktopSessionNavigationBridge = window.maka, | ||
| ): SessionNavigationServices { | ||
| return { | ||
| sessions: { | ||
| list: () => bridge.sessions.list(), | ||
| setFlagged: (sessionId, flagged, options) => | ||
| bridge.sessions.setFlagged(sessionId, flagged, options), | ||
| archive: (sessionId, options) => | ||
| bridge.sessions.archive(sessionId, options), | ||
| unarchive: (sessionId, options) => | ||
| bridge.sessions.unarchive(sessionId, options), | ||
| rename: (sessionId, name, options) => | ||
| bridge.sessions.rename(sessionId, name, options), | ||
| remove: (sessionId, options) => | ||
| bridge.sessions.remove(sessionId, options), | ||
| previewRemoval: (sessionId) => bridge.sessions.previewRemoval(sessionId), | ||
| }, | ||
| sessions: bridge.sessions, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3, recording the trade-off rather than blocking it. This is the widest of the six pass-throughs: |
||
| }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: this line is 128 characters, over the repo's
lineWidth: 100(biome.jsonc:47). CI cannot catch it becauseapps/desktop/**is excluded from the formatter (biome.jsonc:56), but the rest of desktop keeps to 100, andconnection-settings/services-context.tsxin this same PR wraps the identical call. Six of the nine rewritten files are over: module-hub 104, task-entry 104, session-settings 116, session-navigation 120, session-collaboration 126, this one 128. Smallest fix: wrap them the way connection-settings does.