(
type: 'context' | 'hooks' | 'props' | 'state',
id: number,
hookID: ?number,
path: Array<string | number>,
)
| 7247 | } |
| 7248 | |
| 7249 | function deletePath( |
| 7250 | type: 'context' | 'hooks' | 'props' | 'state', |
| 7251 | id: number, |
| 7252 | hookID: ?number, |
| 7253 | path: Array<string | number>, |
| 7254 | ): void { |
| 7255 | const devtoolsInstance = idToDevToolsInstanceMap.get(id); |
| 7256 | if (devtoolsInstance === undefined) { |
| 7257 | console.warn(`Could not find DevToolsInstance with id "${id}"`); |
| 7258 | return; |
| 7259 | } |
| 7260 | if (devtoolsInstance.kind !== FIBER_INSTANCE) { |
| 7261 | // TODO: Handle VirtualInstance. |
| 7262 | return; |
| 7263 | } |
| 7264 | const fiber = devtoolsInstance.data; |
| 7265 | if (fiber !== null) { |
| 7266 | const instance = fiber.stateNode; |
| 7267 | |
| 7268 | switch (type) { |
| 7269 | case 'context': |
| 7270 | // To simplify hydration and display of primitive context values (e.g. number, string) |
| 7271 | // the inspectElement() method wraps context in a {value: ...} object. |
| 7272 | // We need to remove the first part of the path (the "value") before continuing. |
| 7273 | path = path.slice(1); |
| 7274 | |
| 7275 | switch (fiber.tag) { |
| 7276 | case ClassComponent: |
| 7277 | if (path.length === 0) { |
| 7278 | // Simple context value (noop) |
| 7279 | } else { |
| 7280 | deletePathInObject(instance.context, path); |
| 7281 | } |
| 7282 | instance.forceUpdate(); |
| 7283 | break; |
| 7284 | case FunctionComponent: |
| 7285 | // Function components using legacy context are not editable |
| 7286 | // because there's no instance on which to create a cloned, mutated context. |
| 7287 | break; |
| 7288 | } |
| 7289 | break; |
| 7290 | case 'hooks': |
| 7291 | if (typeof overrideHookStateDeletePath === 'function') { |
| 7292 | overrideHookStateDeletePath(fiber, ((hookID: any): number), path); |
| 7293 | } |
| 7294 | break; |
| 7295 | case 'props': |
| 7296 | if (instance === null) { |
| 7297 | if (typeof overridePropsDeletePath === 'function') { |
| 7298 | overridePropsDeletePath(fiber, path); |
| 7299 | } |
| 7300 | } else { |
| 7301 | fiber.pendingProps = copyWithDelete(instance.props, path); |
| 7302 | instance.forceUpdate(); |
| 7303 | } |
| 7304 | break; |
| 7305 | case 'state': |
| 7306 | deletePathInObject(instance.state, path); |
nothing calls this directly
no test coverage detected