-
Notifications
You must be signed in to change notification settings - Fork 152
Core modules
hackape edited this page Jul 19, 2017
·
1 revision
We have 3 core modules: File, Editor, Tab. These 3 are closely related with each other.
So I put them together for easy reference.
File
is the data model for an abstract file, which can map to a real file, a temp file, or a lib, etc.
interface File {
constructor(fileProps: FileProps): File
update(fileProps: FileProps): void
name: string
// the display name of file, usually the last part on path components
path: string
// just like id, file can be identified by it's path
get id(): string
// alias to this.path
isDir: boolean
// see if it has children
contentType: string
content: string
size: number
gitStatus: object
isRoot: boolean
// see if this file is the root node
depth: number
// depth calc from file path, root's depth is 0
parent: File
children: File[]
siblings: File[]
// all files in the same directory, including self
firstChild: File
// this.children[0]
lastChild: File
// this.children[this.children.length - 1]
prev: File
next: File
// previous/next file in same directory, return undefined if not found
}
FileStore
is the manager to File related stuffs
interface FileStore {
get(path: string): File
// get file by path
isValid(file: File): boolean
// test if an object is instance of File
// @fixme: probably should rename this method
loadNodeData(filePropsList: FileProps[]): void
// load file data, identify files by it's path
fetchProjectRoot(): void
// api.fetchPath('/').then(loadNodeData)
updateFile(fileProps: FileProps): void
// update props of a file node, path is required
removeNode(file: File): void
// remove the file node from state.entities
}
Editor
is the data model to be passed to <AnyEditorComponents editor={editor} />
interface EditorProps {
tabId: string
filePath: string
gitBlame: object
cm: CodeMirror
}
interface Editor {
id: string
tabId: string
filePath: string
get file(): File
// return file base on this.filePath
get content(): string
// short cut to this.file.content
gitBlame: {
show: boolean
data: Any[]
}
update(editorProps: EditorProps): void
}
Tab
is the data model for a tab view inside a pane.
interface Tab {
title: string
// title of tab, default to "untitled", if has file, then it'll be the file name
editor: Editor
// editor instance attach to tab
file: File
// shortcut to this.editor.file
index: number
// index of tab in tabGroup
flags: $mobx
// tab flags, a simple observable object
tabGroup: TabGroup
// getter returns it's parent
isActive: boolean
// active status of this tab in tabGroup
siblings: Tab[]
// return siblings tabs including itself in its tabGroup
prev: Tab
next: Tab
// previous/next tab in tabGroup
getAdjacent(checkNextFirst: boolean): Tab;
// whenever it's possible, return an adjacent tab without specifying prev or next
activate(): void
// activate the tab and the containing tabGroup
destroy(): void
// remove this tab by invoking `tabGroup.remove(this)` and delete it from state.tabs
}
TabStore
is the manager to tab related business. It serves as an access point for all tab related data and actions.
interface TabStore {
createTab(tabProps): void
// new Tab(tabProps)
removeTab(tabId: string): void
// tab.destroy()
removeOtherTab(tabId: string): void
// activate given tab and close others from tabGroup
// @fixme: the name's misleading
removeAllTab(tabId: string): void
// get the siblings of given tab and destroy them all
activateTab(tabId: string): void
createGroup(groupId?: string): void
// new TabGroup({ id: groupId })
updateTab(tabProps: { id: string, ...others }): void
// update the tab with provide tabProps, id is required in tabProps
moveTabToGroup(tabId: string, groupId: string): void
// move tab to tabGroup
insertTabBefore(tabId: string, beforeTabId: string): void
// insert tab (by id) before another tab (by id)
}