-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update all DI to be reactive controllers
- Loading branch information
Shibani Basava
authored and
Shibani Basava
committed
Feb 13, 2024
1 parent
e16dc15
commit e6f18be
Showing
10 changed files
with
242 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { type ReactiveController, type ReactiveControllerHost } from 'lit'; | ||
|
||
export class ChatContextController implements ReactiveController { | ||
host: ReactiveControllerHost; | ||
|
||
constructor(host: ReactiveControllerHost) { | ||
(this.host = host).addController(this); | ||
} | ||
|
||
hostConnected() { | ||
// no-op | ||
} | ||
|
||
hostDisconnected() { | ||
// no-op | ||
} | ||
|
||
private _state: Record<string, any> = {}; | ||
|
||
private _selectedChatEntry: ChatThreadEntry | undefined = undefined; | ||
|
||
private _apiUrl: string = ''; | ||
|
||
private _interactionModel: 'ask' | 'chat' = 'chat'; | ||
|
||
private _isChatStarted: boolean = false; | ||
|
||
public set isChatStarted(value: boolean) { | ||
this._isChatStarted = value; | ||
this.host.requestUpdate(); | ||
} | ||
|
||
public get isChatStarted() { | ||
return this._isChatStarted; | ||
} | ||
|
||
public setState(key: string, value: any) { | ||
this._state[key] = value; | ||
this.host.requestUpdate(); | ||
} | ||
|
||
public getState(key: string) { | ||
return this._state[key]; | ||
} | ||
|
||
public set selectedChatEntry(entry: ChatThreadEntry | undefined) { | ||
this._selectedChatEntry = entry; | ||
this.host.requestUpdate(); | ||
} | ||
|
||
public get selectedChatEntry() { | ||
return this._selectedChatEntry; | ||
} | ||
|
||
public set apiUrl(url: string) { | ||
this._apiUrl = url; | ||
this.host.requestUpdate(); | ||
} | ||
|
||
public get apiUrl() { | ||
return this._apiUrl; | ||
} | ||
|
||
public set interactionModel(model: 'ask' | 'chat') { | ||
this._interactionModel = model; | ||
this.host.requestUpdate(); | ||
} | ||
|
||
public get interactionModel() { | ||
return this._interactionModel; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { injectable } from 'inversify'; | ||
import { container, type CitationActionComponent, ComponentType } from './composable.js'; | ||
import { container, type CitationController, ControllerType, ComposableReactiveControllerBase } from './composable.js'; | ||
import { html } from 'lit'; | ||
|
||
@injectable() | ||
export class CitationPreviewer implements CitationActionComponent { | ||
export class CitationPreviewer extends ComposableReactiveControllerBase implements CitationController { | ||
render(citation: Citation, url: string) { | ||
return html`<document-previewer url="${url}"></document-previewer>`; | ||
} | ||
} | ||
|
||
container.bind<CitationActionComponent>(ComponentType.CitationActionComponent).to(CitationPreviewer); | ||
container.bind<CitationController>(ControllerType.Citation).to(CitationPreviewer); |
Oops, something went wrong.