Skip to content

Latest commit

 

History

History
50 lines (40 loc) · 1.67 KB

extension-state-summary.md

File metadata and controls

50 lines (40 loc) · 1.67 KB

ExtensionStateContext State Management Summary

The ExtensionStateContext manages the state for the extension using Jotai, a state management library for React. Here's an overview of how the state is structured and managed:

State Structure

The main state is contained in the extensionStateAtom, which is a derived atom combining various individual state atoms. The state includes:

  1. version
  2. claudeMessages
  3. taskHistory
  4. useUdiff
  5. currentTask
  6. currentTaskId
  7. shouldShowAnnouncement
  8. shouldShowKoduPromo
  9. apiConfiguration
  10. uriScheme
  11. maxRequestsPerTask
  12. customInstructions
  13. fingerprint
  14. technicalBackground
  15. alwaysAllowReadOnly
  16. experimentalTerminal
  17. fpjsKey
  18. extensionName
  19. themeName
  20. user
  21. alwaysAllowWriteOnly
  22. creativeMode

State Management

  1. Individual atoms are created for each piece of state using atom() from Jotai.
  2. The extensionStateAtom combines all individual atoms into a single state object.
  3. The ExtensionStateProvider component manages the state updates:
    • It sets up event listeners for messages from the extension.
    • Updates the state based on received messages.
    • Provides the state to child components.
  4. The useExtensionState hook allows components to access the state and update functions:
    • It returns the current state and setter functions for various state properties.

State Updates

State updates occur through:

  1. Message events from the extension (e.g., 'claudeMessages', 'state', 'action').
  2. Setter functions provided by the useExtensionState hook.

This structure allows for centralized state management and easy access to state and update functions throughout the application.