Skip to content

Commit e926b1f

Browse files
committed
refactor: rename store action types
1 parent 5ffd4f7 commit e926b1f

134 files changed

Lines changed: 713 additions & 744 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/lang/snapshot-action-lang.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,69 +27,69 @@ export const snapshotActionLang: Partial<
2727
(snapshot: Snapshot) => { label: string; icon: typeof FileEdit }
2828
>
2929
> = {
30-
'DOCUMENT/SET_NODE_CONTENT': (snapshot) => ({
30+
'document/update-node-content': (snapshot) => ({
3131
label:
3232
lang.modals_snapshots_updated_node +
3333
snapshot.context.affectedSection,
3434
icon: FileEdit,
3535
}),
36-
'DOCUMENT/INSERT_NODE': (snapshot) => ({
36+
'document/add-node': (snapshot) => ({
3737
label:
3838
lang.modals_snapshots_created_node +
3939
snapshot.context.affectedSection,
4040
icon: FilePlus,
4141
}),
42-
'DOCUMENT/DROP_NODE': (snapshot) => ({
42+
'document/drop-node': (snapshot) => ({
4343
label:
4444
lang.modals_snapshots_dropped_node +
4545
snapshot.context.affectedSection,
4646
icon: FileOutput,
4747
}),
48-
'DOCUMENT/LOAD_FILE': () => ({
48+
'document/file/load-from-disk': () => ({
4949
label: lang.modals_snapshots_document_loaded,
5050
icon: FileUp,
5151
}),
52-
'DOCUMENT/DELETE_NODE': (snapshot) => ({
52+
'document/delete-node': (snapshot) => ({
5353
label:
5454
lang.modals_snapshots_deleted_section +
5555
snapshot.context.affectedSection,
5656
icon: FileMinus,
5757
}),
58-
'DOCUMENT/MOVE_NODE': (snapshot) => ({
58+
'document/move-node': (snapshot) => ({
5959
label:
6060
lang.modals_snapshots_moved_node + snapshot.context.affectedSection,
6161
icon: FileOutput,
6262
}),
63-
'DOCUMENT/MERGE_NODE': (snapshot) => ({
63+
'document/merge-node': (snapshot) => ({
6464
label:
6565
lang.modals_snapshots_merged_node +
6666
snapshot.context.affectedSection,
6767
icon: Merge,
6868
}),
69-
'DOCUMENT/FORMAT_HEADINGS': () => ({
69+
'document/format-headings': () => ({
7070
label: lang.modals_snapshots_formatted_headings,
7171
icon: Heading1,
7272
}),
73-
'DOCUMENT/CUT_NODE': (snapshot) => ({
73+
'document/cut-node': (snapshot) => ({
7474
label:
7575
lang.modals_snapshots_cut_section +
7676
snapshot.context.affectedSection,
7777
icon: Scissors,
7878
}),
79-
'DOCUMENT/PASTE_NODE': (snapshot) => ({
79+
'document/paste-node': (snapshot) => ({
8080
label:
8181
lang.modals_snapshots_pasted_section +
8282
snapshot.context.affectedSection,
8383
icon: ClipboardPaste,
8484
}),
85-
'DOCUMENT/EXTRACT_BRANCH': (snapshot) => ({
85+
'document/extract-node': (snapshot) => ({
8686
label:
8787
lang.modals_snapshots_extracted_node +
8888
snapshot.context.affectedSection,
8989
icon: FileSymlink,
9090
iconHtml: customIcons.cards.svg,
9191
}),
92-
'DOCUMENT/SPLIT_NODE': (snapshot) => ({
92+
'document/split-node': (snapshot) => ({
9393
label:
9494
lang.modals_snapshots_split_node + snapshot.context.affectedSection,
9595
icon: Split,

src/lib/tree-utils/find/find-next-active-node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export const findNextActiveNode = (
99
node: string,
1010
action: DeleteNodeAction | JumpToNodeAction,
1111
) => {
12-
if (action.type === 'DOCUMENT/DELETE_NODE') {
12+
if (action.type === 'document/delete-node') {
1313
return findNextNodeAfterDeletion(columns, node);
14-
} else if (action.type === 'DOCUMENT/JUMP_TO_NODE') {
14+
} else if (action.type === 'view/set-active-node/keyboard-jump') {
1515
return findNodeToJumpTo(columns, node, action.payload.target);
1616
}
1717
};

src/main.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { Plugin, WorkspaceLeaf } from 'obsidian';
22
import { LINEAGE_VIEW_TYPE, LineageView } from './view/view';
33
import { createSetViewState } from 'src/obsidian/patches/create-set-view-state';
44
import { around } from 'monkey-around';
5-
import {
6-
SettingsActions,
7-
settingsReducer,
8-
} from 'src/stores/settings/settings-reducer';
5+
import { settingsReducer } from 'src/stores/settings/settings-reducer';
96
import { deepMerge } from 'src/helpers/deep-merge';
107
import { DEFAULT_SETTINGS } from 'src/stores/settings/default-settings';
118
import { Store } from 'src/lib/store/store';
@@ -37,6 +34,7 @@ import {
3734
} from 'src/workers/worker-instances';
3835
import { onVaultEvent } from 'src/stores/plugin/subscriptions/on-vault-event';
3936
import { onWorkspaceEvent } from 'src/stores/plugin/subscriptions/on-workspace-event';
37+
import { SettingsActions } from 'src/stores/settings/settings-store-actions';
4038

4139
export type SettingsStore = Store<Settings, SettingsActions>;
4240
export type PluginStore = Store<PluginState, PluginStoreActions>;

src/obsidian/commands/add-commands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const createCommands = (plugin: Lineage) => {
5353
return Boolean(getActiveLineageView(plugin));
5454
}
5555
plugin.settings.dispatch({
56-
type: 'VIEW/SCROLLING/TOGGLE_SCROLLING_MODE',
56+
type: 'settings/view/toggle-horizontal-scrolling-mode',
5757
});
5858
},
5959
});
@@ -66,7 +66,7 @@ const createCommands = (plugin: Lineage) => {
6666
return Boolean(getActiveLineageView(plugin));
6767
}
6868
plugin.settings.dispatch({
69-
type: 'settings/view/scrolling/toggle-vertical-scrolling-mode',
69+
type: 'settings/view/toggle-vertical-scrolling-mode',
7070
});
7171
},
7272
});
@@ -222,7 +222,7 @@ const createCommands = (plugin: Lineage) => {
222222
return Boolean(view);
223223
}
224224
plugin.settings.dispatch({
225-
type: 'VIEW/TOGGLE_MINIMAP',
225+
type: 'settings/view/toggle-minimap',
226226
});
227227
},
228228
});

src/obsidian/commands/helpers/extract-branch/extract-branch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const extractBranch = async (view: LineageView) => {
5555
await openFileInLineage(view.plugin, newFile, format, 'split');
5656

5757
view.documentStore.dispatch({
58-
type: 'DOCUMENT/EXTRACT_BRANCH',
58+
type: 'document/extract-node',
5959
payload: {
6060
nodeId: branch.nodeId,
6161
documentName: newFile.basename,

src/obsidian/helpers/inline-editor/inline-editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class InlineEditor {
224224
const content = this.getContent();
225225
const viewState = this.view.viewStore.getValue();
226226
this.view.documentStore.dispatch({
227-
type: 'DOCUMENT/SET_NODE_CONTENT',
227+
type: 'document/update-node-content',
228228
payload: {
229229
nodeId: nodeId,
230230
content: content,

src/stores/document/default-document-state.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const defaultDocumentState = (): DocumentState => ({
1010
section_id: {},
1111
},
1212
file: {
13-
path: null,
1413
frontmatter: '',
1514
},
1615
history: {

src/stores/document/document-reducer.ts

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
DocumentStoreAction,
2121
UndoableAction,
2222
} from 'src/stores/document/document-store-actions';
23-
import { defaultDocumentState } from 'src/stores/document/default-document-state';
2423
import { formatHeadings } from 'src/stores/document/reducers/content/format-content/format-headings';
2524
import { pasteNode } from 'src/stores/document/reducers/clipboard/paste-node/paste-node';
2625
import { updateSectionsDictionary } from 'src/stores/document/reducers/state/update-sections-dictionary';
@@ -45,18 +44,18 @@ const updateDocumentState = (
4544
let affectedNodeId: null | string = null;
4645
let affectedNodeContent: Content[string] | null = null;
4746
let affectedNodes: string[] | undefined = undefined;
48-
if (action.type === 'DOCUMENT/SET_NODE_CONTENT') {
47+
if (action.type === 'document/update-node-content') {
4948
const update = setNodeContent(state.document.content, action);
5049
if (!update) return NO_UPDATE;
5150
newActiveNodeId = action.payload.nodeId;
52-
} else if (action.type === 'DOCUMENT/INSERT_NODE') {
51+
} else if (action.type === 'document/add-node') {
5352
newActiveNodeId = insertNode(
5453
state.document,
5554
action.payload.position,
5655
action.payload.activeNodeId,
5756
action.payload.content,
5857
);
59-
} else if (action.type === 'DOCUMENT/DELETE_NODE') {
58+
} else if (action.type === 'document/delete-node') {
6059
affectedNodeContent =
6160
state.document.content[action.payload.activeNodeId];
6261
newActiveNodeId = deleteNode(
@@ -65,7 +64,7 @@ const updateDocumentState = (
6564
action.payload.selectedNodes,
6665
);
6766
affectedNodeId = action.payload.activeNodeId;
68-
} else if (action.type === 'DOCUMENT/EXTRACT_BRANCH') {
67+
} else if (action.type === 'document/extract-node') {
6968
affectedNodeContent = state.document.content[action.payload.nodeId];
7069
const update = setNodeContent(state.document.content, {
7170
payload: {
@@ -76,18 +75,18 @@ const updateDocumentState = (
7675
if (!update) return NO_UPDATE;
7776
removeExtractedBranch(state.document, action);
7877
newActiveNodeId = action.payload.nodeId;
79-
} else if (action.type === 'DOCUMENT/SPLIT_NODE') {
78+
} else if (action.type === 'document/split-node') {
8079
affectedNodeId = action.payload.target;
8180
affectedNodeContent = state.document.content[affectedNodeId];
8281
newActiveNodeId = splitNode(state.document, action);
83-
} else if (action.type === 'DOCUMENT/DROP_NODE') {
82+
} else if (action.type === 'document/drop-node') {
8483
dropNode(state.document, action);
8584
newActiveNodeId = action.payload.droppedNodeId;
86-
} else if (action.type === 'DOCUMENT/MOVE_NODE') {
85+
} else if (action.type === 'document/move-node') {
8786
moveNode(state.document, action);
8887
newActiveNodeId = action.payload.activeNodeId;
8988
affectedNodeId = newActiveNodeId;
90-
} else if (action.type === 'DOCUMENT/MERGE_NODE') {
89+
} else if (action.type === 'document/merge-node') {
9190
affectedNodeContent =
9291
state.document.content[action.payload.activeNodeId];
9392
newActiveNodeId = mergeNode(state.document, action);
@@ -96,7 +95,7 @@ const updateDocumentState = (
9695
sortDirectChildNodes(state.document, action.payload);
9796
newActiveNodeId = action.payload.id;
9897
affectedNodeId = newActiveNodeId;
99-
} else if (action.type === 'DOCUMENT/LOAD_FILE') {
98+
} else if (action.type === 'document/file/load-from-disk') {
10099
if (action.payload.__test_document__) {
101100
newActiveNodeId = loadDocumentFromJSON(
102101
state,
@@ -105,41 +104,34 @@ const updateDocumentState = (
105104
} else {
106105
newActiveNodeId = loadDocumentFromFile(state, action);
107106
}
108-
} else if (action.type === 'RESET_STORE') {
109-
const newState = defaultDocumentState();
110-
state.document = newState.document;
111-
state.history = newState.history;
112-
state.file = newState.file;
113-
} else if (action.type === 'HISTORY/SELECT_SNAPSHOT') {
107+
} else if (action.type === 'document/history/select-snapshot') {
114108
selectSnapshot(state.document, state.history, action);
115109
state.history = { ...state.history };
116-
} else if (action.type === 'HISTORY/APPLY_PREVIOUS_SNAPSHOT') {
110+
} else if (action.type === 'document/history/select-previous-snapshot') {
117111
undoAction(state.document, state.history);
118112
state.history = { ...state.history };
119-
} else if (action.type === 'HISTORY/APPLY_NEXT_SNAPSHOT') {
113+
} else if (action.type === 'document/history/select-next-snapshot') {
120114
redoAction(state.document, state.history);
121115
state.history = { ...state.history };
122-
} else if (action.type === 'FS/SET_FILE_PATH') {
123-
state.file.path = action.payload.path;
124-
} else if (action.type === 'DOCUMENT/FORMAT_HEADINGS') {
116+
} else if (action.type === 'document/format-headings') {
125117
formatHeadings(state.document.content, state.sections);
126118
newActiveNodeId = getIdOfSection(
127119
state.sections,
128120
state.history.context.activeSection,
129121
);
130-
} else if (action.type === 'DOCUMENT/PASTE_NODE') {
122+
} else if (action.type === 'document/paste-node') {
131123
const result = pasteNode(state.document, action);
132124
newActiveNodeId = result.nextNode;
133125
affectedNodes = result.rootNodes;
134-
} else if (action.type === 'DOCUMENT/CUT_NODE') {
126+
} else if (action.type === 'document/cut-node') {
135127
affectedNodeContent = state.document.content[action.payload.nodeId];
136128
newActiveNodeId = deleteNode(
137129
state.document,
138130
action.payload.nodeId,
139131
action.payload.selectedNodes,
140132
);
141133
affectedNodeId = action.payload.nodeId;
142-
} else if (action.type === 'FILE/UPDATE_FRONTMATTER') {
134+
} else if (action.type === 'document/file/update-frontmatter') {
143135
state.file.frontmatter = action.payload.frontmatter;
144136
return;
145137
} else if (action.type === 'document/pinned-nodes/pin') {
@@ -158,7 +150,7 @@ const updateDocumentState = (
158150
action.payload.sections,
159151
);
160152
return;
161-
} else if (action.type === 'META/REFRESH_GROUP_PARENT_IDS') {
153+
} else if (action.type === 'document/meta/refresh-group-parent-ids') {
162154
refreshGroupParentIds(state.document.columns, state.meta);
163155
return;
164156
}
@@ -175,7 +167,7 @@ const updateDocumentState = (
175167
}
176168

177169
// if file was modified externally, try to maintain active section
178-
if (action.type === 'DOCUMENT/LOAD_FILE') {
170+
if (action.type === 'document/file/load-from-disk') {
179171
const activeSection = action.payload.activeSection;
180172
if (activeSection) {
181173
const id = state.sections.section_id[activeSection];

src/stores/document/document-state-type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type DocumentState = {
1919
document: LineageDocument;
2020
sections: Sections;
2121
file: {
22-
path: string | null;
22+
// path: string | null;
2323
frontmatter: string;
2424
};
2525
meta: DocumentMeta;

src/stores/document/document-store-actions.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,14 @@ export type SavedDocument = {
2727
position: NodePosition | null;
2828
frontmatter: string;
2929
};
30-
type ResetStoreAction = { type: 'RESET_STORE' };
31-
type SetFilePathAction = {
32-
type: 'FS/SET_FILE_PATH';
33-
payload: {
34-
path: string | null;
35-
};
36-
};
3730

3831
export type DocumentStoreAction = DocumentAction | HistoryAction;
3932

4033
export type DocumentAction =
4134
| LoadDocumentAction
4235
| CreateNodeAction
43-
| ResetStoreAction
4436
| SetNodeContentAction
4537
| DropAction
46-
| SetFilePathAction
4738
| DeleteNodeAction
4839
| MoveNodeAction
4940
| MergeNodeAction
@@ -52,7 +43,7 @@ export type DocumentAction =
5243
| ExtractNodeAction
5344
| SplitNodeAction
5445
| {
55-
type: 'FILE/UPDATE_FRONTMATTER';
46+
type: 'document/file/update-frontmatter';
5647
payload: {
5748
frontmatter: string;
5849
};
@@ -86,7 +77,7 @@ export type CopyNodeAction = {
8677
};
8778

8879
export type CutNodeAction = {
89-
type: 'DOCUMENT/CUT_NODE';
80+
type: 'document/cut-node';
9081
payload: {
9182
nodeId: string;
9283
selectedNodes?: Set<string>;

0 commit comments

Comments
 (0)