Hone logo
Hone
Problems

Angular DevTools Integration: Custom Tab and Data Display

This challenge focuses on extending the Angular DevTools with a custom tab that displays specific application data. Integrating custom DevTools extensions allows developers to gain deeper insights into their Angular applications, aiding in debugging, performance analysis, and understanding application state. This challenge will guide you through creating a simple custom tab that displays a component's input properties.

Problem Description

You are tasked with creating a custom tab for the Angular DevTools that displays the input properties of a selected Angular component. The DevTools will already be installed and running. Your solution should:

  1. Create an Angular library: This library will contain the custom DevTools extension.
  2. Define a DevTools extension: This extension will register a new tab within the DevTools interface.
  3. Select a Component: The extension should allow the user to select an Angular component from the DevTools' component tree.
  4. Display Input Properties: Once a component is selected, the custom tab should display a list of that component's @Input() properties and their current values.
  5. Handle No Selection: If no component is selected, the tab should display a message indicating that no component is selected.
  6. Update on Selection Change: The displayed input properties should update dynamically whenever the user selects a different component in the DevTools.

Key Requirements:

  • The extension must be compatible with the latest Angular DevTools.
  • The extension should not interfere with the existing DevTools functionality.
  • The extension should be well-structured and maintainable.
  • The extension should be able to handle components with no @Input() properties gracefully.

Expected Behavior:

  • A new tab labeled "Custom Input Properties" appears in the Angular DevTools.
  • When a component is selected in the DevTools component tree, the "Custom Input Properties" tab displays a list of its @Input() properties and their values.
  • When no component is selected, the "Custom Input Properties" tab displays a message like "No component selected."
  • When the selected component changes, the "Custom Input Properties" tab updates to reflect the new component's input properties.

Edge Cases to Consider:

  • Components with no @Input() properties.
  • Components with complex @Input() values (e.g., objects, arrays). For simplicity, display these as [object] or [array] rather than attempting to deeply inspect them.
  • Performance implications of inspecting large components. (While not a primary focus, consider how to avoid excessive computation).
  • Handling errors gracefully if the component's input properties cannot be accessed.

Examples

Example 1:

Input: A component with the following `@Input()` properties:
- `name: string` (value: "John Doe")
- `age: number` (value: 30)
- `isActive: boolean` (value: true)

Output: In the "Custom Input Properties" tab:
- name: John Doe
- age: 30
- isActive: true

Example 2:

Input: A component with no `@Input()` properties.

Output: In the "Custom Input Properties" tab:
- No component selected.

Example 3:

Input: A component with an `@Input()` property that is an array:
- `items: string[]` (value: ["apple", "banana", "cherry"])

Output: In the "Custom Input Properties" tab:
- items: [array]

Constraints

  • Angular Version: The solution should be compatible with Angular 16 or later.
  • DevTools Version: The solution should be compatible with the latest stable version of the Angular DevTools.
  • Library Size: The resulting Angular library should be reasonably small (ideally under 50KB gzipped).
  • Performance: The extension should not significantly impact the performance of the Angular DevTools or the application being debugged. Avoid complex DOM manipulations or unnecessary computations.
  • Input Property Display: Display only the name and value of the @Input() properties. Do not attempt to display the component's template or other internal details.

Notes

  • You'll need to use the @angular/devtools API to register your custom extension. Refer to the official Angular DevTools documentation for details: https://angular.io/guide/devtools
  • Consider using RxJS Observables to react to changes in the selected component.
  • The component selection mechanism is already provided by the Angular DevTools. You don't need to implement your own component tree. You'll need to listen for the selection event.
  • Focus on the core functionality of displaying input properties. Advanced features like filtering or sorting can be considered as optional enhancements.
  • This is a good opportunity to practice building Angular libraries and interacting with external APIs.
Loading editor...
typescript