MCPcopy Create free account
hub / github.com/Power-Playground/app / createQuickAccessInstance

Function createQuickAccessInstance

core/src/components/QuickAccess.tsx:90–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

88const commands = new Map<string, QuickAccess.CommandHandler>()
89
90export const createQuickAccessInstance = () => {
91 const activeCommandListeners: ((command: string) => void)[] = []
92 let activeCommandName: string | null = null
93 return {
94 asyncFeature: Feature.create<QuickAccess.Result>(),
95 onActiveCommandChange(lis) {
96 activeCommandListeners.push(lis)
97 return () => {
98 const index = activeCommandListeners.indexOf(lis)
99 if (index !== -1) {
100 activeCommandListeners.splice(index, 1)
101 }
102 }
103 },
104 run(command) {
105 activeCommandName = command
106 this.asyncFeature = this.asyncFeature.reset()
107 activeCommandListeners.forEach(lis => lis(command))
108 return this.asyncFeature.promise
109 },
110 get activeCommandHandler() {
111 return activeCommandName
112 ? commands.get(activeCommandName)
113 : undefined
114 },
115 register(command, handler) {
116 commands.set(command, handler)
117 return () => {
118 commands.delete(command)
119 }
120 }
121 } as QuickAccessContextValue
122}
123
124export const QuickAccessContext = createContext<QuickAccessContextValue>(null!)
125

Callers 1

MainFunction · 0.90

Calls 1

createMethod · 0.80

Tested by

no test coverage detected