ADP-Chat-Client
Introduction/API Usage

Update Component

Dynamically update mounted component configuration using the update method

Use the update method to dynamically update the configuration of a mounted component without recreating the component instance.

ADPChatComponent.update(container?: string, config?: Partial<ChatConfig>)

Parameters

ParameterTypeDefaultDescription
containerstring'body'CSS selector for mount container
configPartial<ChatConfig>-Configuration items to update (incremental update)

Return Value

ReturnTypeDescription
successbooleantrue indicates success, false indicates no component found for the container

Basic Usage

// Initialize component
ADPChatComponent.init('#chat-container', {
  theme: 'light',
  logoTitle: 'AI Assistant'
});

// Update theme
ADPChatComponent.update('#chat-container', {
  theme: 'dark'
});

Update Multiple Config Items

ADPChatComponent.update('#chat-container', {
  theme: 'dark',
  logoTitle: 'Smart Assistant',
  aiWarningText: 'Content generated by AI, please verify'
});

Update API Configuration

// Update Authorization Token
ADPChatComponent.update('#chat-container', {
  apiConfig: {
    headers: {
      'Authorization': 'Bearer new-token'
    }
  }
});

// Update baseURL
ADPChatComponent.update('#chat-container', {
  apiConfig: {
    baseURL: 'https://new-api.example.com'
  }
});

Update User Information

ADPChatComponent.update('#chat-container', {
  user: {
    name: 'New Username',
    avatarUrl: 'https://example.com/new-avatar.png'
  }
});

Update i18n Configuration

ADPChatComponent.update('#chat-container', {
  sideI18n: {
    more: 'View More',
    collapse: 'Collapse List'
  },
  chatI18n: {
    loading: 'Loading...',
    thinking: 'AI is thinking...'
  }
});

Use with getProps

// Get current config
const props = ADPChatComponent.getProps('#chat-container');

// Toggle based on current config
if (props) {
  ADPChatComponent.update('#chat-container', {
    theme: props.theme === 'light' ? 'dark' : 'light'
  });
}

Notes

  • The update method can only update components initialized via the init method
  • The passed configuration will be merged with existing config (incremental update), won't override unpassed items
  • If the component is not initialized, a warning will be logged and false will be returned
  • Updates take effect immediately, the component will automatically re-render

getProps - Get Current Configuration

Use the getProps method to get the current configuration of a mounted component.

ADPChatComponent.getProps(container?: string)

Parameters

ParameterTypeDefaultDescription
containerstring'body'CSS selector for mount container

Return Value

ReturnTypeDescription
propsRecord<string, any> | undefinedCurrent component config object, undefined if not found

Usage Example

// Get current config
const currentProps = ADPChatComponent.getProps('#chat-container');
console.log(currentProps?.theme); // 'light' or 'dark'
console.log(currentProps?.logoTitle); // Current logo title

On this page