Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(files): Organize event subscriptions
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Aug 22, 2024
commit 3b185b1156e684ffbc84815d03b0bb29865b9c65
24 changes: 10 additions & 14 deletions apps/files/src/views/folderTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const queue = new PQueue({ concurrency: 5, intervalCap: 5, interval: 200 })

const registerQueue = new PQueue({ concurrency: 5, intervalCap: 5, interval: 200 })

const registerTreeNodes = async (path: string = '/') => {
const registerTreeChildren = async (path: string = '/') => {
await queue.add(async () => {
const nodes = await getFolderTreeNodes(path)
const promises = nodes.map(node => registerQueue.add(() => registerTreeNodeView(node)))
Expand All @@ -52,7 +52,7 @@ const getLoadChildViews = (node: TreeNode | Folder) => {
}
// @ts-expect-error Custom property
view.loading = true
await registerTreeNodes(node.path)
await registerTreeChildren(node.path)
// @ts-expect-error Custom property
view.loading = false
// @ts-expect-error Custom property
Expand Down Expand Up @@ -168,13 +168,13 @@ const onMoveNode = ({ node, oldSource }) => {
const onUserConfigUpdated = async ({ key, value }) => {
if (key === 'show_hidden') {
showHiddenFiles = value
await registerTreeNodes()
await registerTreeChildren()
// @ts-expect-error No payload
emit('files:folder-tree:initialized')
}
}

const registerFolderTreeRoot = () => {
const registerTreeRoot = () => {
Navigation.register(new View({
id: folderTreeId,

Expand All @@ -188,20 +188,16 @@ const registerFolderTreeRoot = () => {
}))
}

const registerFolderTreeChildren = async () => {
await registerTreeNodes()
export const registerFolderTreeView = async () => {
if (!isFolderTreeEnabled) {
return
}
registerTreeRoot()
await registerTreeChildren()
subscribe('files:node:created', onCreateNode)
subscribe('files:node:deleted', onDeleteNode)
subscribe('files:node:moved', onMoveNode)
subscribe('files:config:updated', onUserConfigUpdated)
// @ts-expect-error No payload
emit('files:folder-tree:initialized')
}

export const registerFolderTreeView = async () => {
if (!isFolderTreeEnabled) {
return
}
registerFolderTreeRoot()
await registerFolderTreeChildren()
}