-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Notebook and Profile modal controllers to use PreactContainer
- Loading branch information
1 parent
1a40d97
commit aa7aa7a
Showing
4 changed files
with
18 additions
and
36 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 |
---|---|---|
@@ -1,28 +1,21 @@ | ||
import { render } from 'preact'; | ||
|
||
import type { Destroyable } from '../types/annotator'; | ||
import type { ProfileConfig } from './components/ProfileModal'; | ||
import ProfileModal from './components/ProfileModal'; | ||
import type { EventBus } from './util/emitter'; | ||
import { createShadowRoot } from './util/shadow-root'; | ||
import { PreactContainer } from './util/preact-container'; | ||
|
||
export class Profile implements Destroyable { | ||
private _outerContainer: HTMLElement; | ||
public shadowRoot: ShadowRoot; | ||
private _container: PreactContainer; | ||
|
||
constructor(element: HTMLElement, eventBus: EventBus, config: ProfileConfig) { | ||
this._outerContainer = document.createElement('hypothesis-profile'); | ||
element.appendChild(this._outerContainer); | ||
this.shadowRoot = createShadowRoot(this._outerContainer); | ||
|
||
render( | ||
<ProfileModal eventBus={eventBus} config={config} />, | ||
this.shadowRoot, | ||
); | ||
this._container = new PreactContainer('profile', () => ( | ||
<ProfileModal eventBus={eventBus} config={config} /> | ||
)); | ||
element.append(this._container.element); | ||
this._container.render(); | ||
} | ||
|
||
destroy(): void { | ||
render(null, this.shadowRoot); | ||
this._outerContainer.remove(); | ||
this._container.destroy(); | ||
} | ||
} |
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