refactor(web): dependency management (#2386)

This commit is contained in:
Mo
2023-08-05 12:48:39 -05:00
committed by GitHub
parent b07da5b663
commit d8d4052a52
274 changed files with 4065 additions and 3873 deletions

View File

@@ -1,9 +1,19 @@
import { WebApplication } from '@/Application/WebApplication'
import { removeFromArray } from '@standardnotes/utils'
import { FileItem, SNNote } from '@standardnotes/snjs'
import {
AlertService,
ComponentManagerInterface,
FileItem,
ItemManagerInterface,
MutatorClientInterface,
PreferenceServiceInterface,
SNNote,
SessionsClientInterface,
SyncServiceInterface,
} from '@standardnotes/snjs'
import { NoteViewController } from './NoteViewController'
import { FileViewController } from './FileViewController'
import { TemplateNoteViewControllerOptions } from './TemplateNoteViewControllerOptions'
import { IsNativeMobileWeb } from '@standardnotes/ui-services'
type ItemControllerGroupChangeCallback = (activeController: NoteViewController | FileViewController | undefined) => void
@@ -12,10 +22,19 @@ export class ItemGroupController {
changeObservers: ItemControllerGroupChangeCallback[] = []
eventObservers: (() => void)[] = []
constructor(private application: WebApplication) {}
constructor(
private items: ItemManagerInterface,
private mutator: MutatorClientInterface,
private sync: SyncServiceInterface,
private sessions: SessionsClientInterface,
private preferences: PreferenceServiceInterface,
private components: ComponentManagerInterface,
private alerts: AlertService,
private _isNativeMobileWeb: IsNativeMobileWeb,
) {}
public deinit(): void {
;(this.application as unknown) = undefined
;(this.items as unknown) = undefined
this.eventObservers.forEach((removeObserver) => {
removeObserver()
@@ -42,11 +61,32 @@ export class ItemGroupController {
let controller!: NoteViewController | FileViewController
if (context.file) {
controller = new FileViewController(this.application, context.file)
controller = new FileViewController(context.file, this.items)
} else if (context.note) {
controller = new NoteViewController(this.application, context.note)
controller = new NoteViewController(
context.note,
this.items,
this.mutator,
this.sync,
this.sessions,
this.preferences,
this.components,
this.alerts,
this._isNativeMobileWeb,
)
} else if (context.templateOptions) {
controller = new NoteViewController(this.application, undefined, context.templateOptions)
controller = new NoteViewController(
undefined,
this.items,
this.mutator,
this.sync,
this.sessions,
this.preferences,
this.components,
this.alerts,
this._isNativeMobileWeb,
context.templateOptions,
)
} else {
throw Error('Invalid input to createItemController')
}