Skip to content

Commit

Permalink
refactor(graph.ts): 関数名の変更
Browse files Browse the repository at this point in the history
  • Loading branch information
mzkmnk committed Jan 13, 2025
1 parent c818ce6 commit 02cf1f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions projects/ngrx-extension/src/lib/helpers/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type TNodeItem = string | { [key: string]: TNodeItem[] };
* @param prefix A combined prefix string from parent nodes, etc.
* @param callback A callback to be invoked when a key is found (taking key, fullKeyPath, objectState).
*/
export function writeDfs(
export function traverseAndWrite(
currentState: Record<string, unknown>,
nodes: TNodeItem[],
prefix: string,
Expand All @@ -25,7 +25,7 @@ export function writeDfs(
const nestedState = currentState[key] as Record<string, unknown>;
const newPrefix = prefix === '' ? key : `${prefix}-${key}`;

writeDfs(nestedState, childNode, newPrefix, callback);
traverseAndWrite(nestedState, childNode, newPrefix, callback);
}
}
}
Expand All @@ -39,7 +39,7 @@ export function writeDfs(
* @param prefix A combined prefix string from parent nodes, etc.
* @param callback A callback that receives the final key (fullKeyPath).
*/
export function readDfs(
export function traverseAndRead(
nodes: TNodeItem[],
prefix: string,
callback: (fullKeyPath: string) => void,
Expand All @@ -51,7 +51,7 @@ export function readDfs(
} else {
for (const [key, childNode] of Object.entries(node)) {
const newPrefix = prefix === '' ? key : `${prefix}-${node}`;
readDfs(childNode, newPrefix, callback);
traverseAndRead(childNode, newPrefix, callback);
}
}
}
Expand All @@ -67,7 +67,7 @@ export function readDfs(
* @param currentState The state object currently being assembled.
* @returns The object constructed according to the node hierarchy.
*/
export function createObject(
export function buildNestedState(
jsonString: string,
nodesPath: string[],
nodesIdx: number,
Expand All @@ -84,5 +84,5 @@ export function createObject(
return recordState;
}

return createObject(jsonString, nodesPath, nodesIdx - 1, recordState);
return buildNestedState(jsonString, nodesPath, nodesIdx - 1, recordState);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
type TNodeItem,
createObject,
readDfs,
writeDfs,
buildNestedState,
traverseAndRead,
traverseAndWrite,
} from '@/projects/ngrx-extension/src/lib/helpers/graph';
import { effect } from '@angular/core';
import {
Expand Down Expand Up @@ -52,7 +52,7 @@ export function withStorageSync({
writeToStorage(): void {
const currentState = getState(store) as Record<string, unknown>;

writeDfs(
traverseAndWrite(
currentState,
nodes,
prefix,
Expand All @@ -79,7 +79,7 @@ export function withStorageSync({

// Reads data from the storage and saves it into the store
readFromStorage(): void {
readDfs(nodes, prefix, (fullKeyPath) => {
traverseAndRead(nodes, prefix, (fullKeyPath) => {
const jsonString: string | null = storage.getItem(fullKeyPath);

if (jsonString === null) {
Expand All @@ -89,7 +89,7 @@ export function withStorageSync({
const slicedKeys: string[] = fullKeyPath
.split('-')
.filter((x) => x !== prefix);
const recordState = createObject(
const recordState = buildNestedState(
jsonString,
slicedKeys,
slicedKeys.length - 1,
Expand Down

0 comments on commit 02cf1f8

Please sign in to comment.