-
Notifications
You must be signed in to change notification settings - Fork 0
20240910 クラス(JavaScript) #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 12 commits
af9e537
3a6be0e
5cada90
9fb1338
615278a
b652d11
f6c4670
f884a7f
b3e75c7
86921e2
e9a43b2
36d8dd8
38245af
bfa9e8d
2175c99
8fc5a52
f03ccb4
c403443
f92aa83
93db65b
89b6bde
20665ea
f3288c8
c194940
86fe4a9
f5ce052
748d963
9aac457
d5e0e7d
f11b24f
5690b10
be2fa74
2b281ee
3164ab7
66e6ef1
0ca3b85
1ad1a24
bfd1058
5c6bb39
6d30a0c
874405b
3b820c0
8051761
19192a2
b26f70b
c09c1a7
5ce7476
98b82e4
da3d426
8a9f10b
1e9207f
bb2dfa5
6feccac
b58dd99
8417087
67f9782
a87ed58
a038466
8b7d0dc
8acbaa5
5806291
9401114
d519f13
adc2b7d
5389332
5a9d3bf
7b8b2bf
ce0a070
82ceffd
176ed38
5bac5d6
740f2ed
cec5c9d
2399ee4
e988392
d9cc68e
e407227
11101c5
e8603c7
547a645
6e42d3d
7385187
9fbff4a
9e78123
3e0fdb7
ecb8ccc
d5aaae1
68b2cc3
da5a39e
8578808
a1939c3
8ec8247
f0a4c37
24d614a
a4c3d34
29bc0c8
7385c44
5753e3b
dbda513
5e37171
3da8156
04b26b5
e4725e6
3ba39f7
07372dd
91edcb8
4fb6530
75d1487
dfeb341
0d103b4
385c5a4
a7db3b7
4dfcc22
39c7dec
92760af
8cb0312
fbcee09
e5e4ecb
219798e
e3b23f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Node.js標準モジュール | ||
| import { readFileSync } from "fs"; | ||
| import { createInterface } from "readline"; | ||
| import { stdin as input, stdout as output } from "process"; | ||
|
|
||
| // プロジェクト内からのインポート | ||
| import { INSERT_MEMO } from "../db/queries.js"; | ||
| import { FILE_ENCODING } from "../config/settings.js"; | ||
| import { checkIfEmpty } from "./memoHelpers.js"; | ||
| import { | ||
| ADD_MEMO_LOG_MESSAGES, | ||
| COMMON_LOG_MESSAGES, | ||
| logMessage, | ||
| handleError, | ||
| } from "../config/log.js"; | ||
|
|
||
| export function addMemo(db) { | ||
| if (!input.isTTY) { | ||
| const inputContent = readFileSync(0, FILE_ENCODING); | ||
| saveMemo(db, inputContent); | ||
| } else { | ||
| const rl = createInterface({ input, output }); | ||
| logMessage(ADD_MEMO_LOG_MESSAGES.PROMPT); | ||
|
|
||
| const content = []; | ||
| rl.on("line", (line) => { | ||
| content.push(line); | ||
| }); | ||
|
|
||
| rl.on("close", () => { | ||
| checkIfEmpty(content, logMessage, ADD_MEMO_LOG_MESSAGES.EMPTY); | ||
| const memoContent = content.join("\n"); | ||
| saveMemo(db, memoContent); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| function saveMemo(db, memoContent) { | ||
| db.run(INSERT_MEMO, [memoContent.trim()], (err) => { | ||
| if (handleError(err, COMMON_LOG_MESSAGES.ERROR)) return; | ||
| logMessage(ADD_MEMO_LOG_MESSAGES.SUCCESS); | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { addMemo } from "./addMemo.js"; | ||
| import { listMemos } from "./listMemos.js"; | ||
| import { readMemo } from "./readMemo.js"; | ||
| import { deleteMemo } from "./deleteMemo.js"; | ||
|
|
||
| export class MemoApp { | ||
| constructor(database) { | ||
| this.db = database.getDb(); | ||
| } | ||
|
|
||
| addMemo() { | ||
| addMemo(this.db); | ||
| } | ||
|
|
||
| listMemos() { | ||
| listMemos(this.db); | ||
| } | ||
|
|
||
| readMemo() { | ||
| readMemo(this.db); | ||
| } | ||
|
|
||
| deleteMemo() { | ||
| deleteMemo(this.db); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. これらのコードが
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer 指摘内容の推測
自分が推測した上記2点の理由から、以下のような対応を行いました。 推測をもとに行った修正
memo.js#!/usr/bin/env node
import { MemoDatabase } from "./memoApp/db/database.js";
import { addMemo } from "./memoApp/actions/addMemo.js";
import { listMemos } from "./memoApp/actions/listMemos.js";
import { readMemo } from "./memoApp/actions/readMemo.js";
import { deleteMemo } from "./memoApp/actions/deleteMemo.js";
import { OPTIONS } from "./memoApp/config/settings.js";
const DBInstance = new MemoDatabase();
await DBInstance.connect();
const database = DBInstance.databaseConnection;
const args = process.argv.slice(2);
switch (args[0]) {
case OPTIONS.LIST:
listMemos(database);
break;
case OPTIONS.READ:
readMemo(database);
break;
case OPTIONS.DELETE:
deleteMemo(database);
break;
default:
addMemo(database);
break;
}そもそもなぜ無駄なカプセル化を行ったのか?現状はメモ作成・メモリスト表示・各メモ内容表示・メモ削除の4つの機能だが、もし今以上に機能が増えることを仮定すると、このメモアプリがどのような機能で構成されているものなのかが見えずらいと感じ、 質問・依頼
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. import している関数に処理を委譲するような形で実装しているのはなぜでしょう? 理由を教えてください。また、これだとクラスから単に他の関数を呼び出しているだけで、オブジェクトが状態を持っていないので、クラスを定義する意味がないですね。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { DELETE_MEMO_BY_ID } from "../db/queries.js"; | ||
| import { DELETE_MEMO_LOG_MESSAGES } from "../config/log.js"; | ||
| import { handleMemoAction } from "./memoHelpers.js"; | ||
|
|
||
| export async function deleteMemo(db) { | ||
| await handleMemoAction( | ||
| db, | ||
| DELETE_MEMO_LOG_MESSAGES.PROMPT, | ||
| DELETE_MEMO_BY_ID, | ||
| () => DELETE_MEMO_LOG_MESSAGES.SUCCESS, | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { SELECT_ALL_MEMOS } from "../db/queries.js"; | ||
| import { checkIfEmpty } from "./memoHelpers.js"; | ||
| import { | ||
| LIST_MEMOS_LOG_MESSAGES, | ||
| COMMON_LOG_MESSAGES, | ||
| logMessage, | ||
| handleError, | ||
| } from "../config/log.js"; | ||
|
|
||
| export function listMemos(db) { | ||
| db.all(SELECT_ALL_MEMOS, [], (err, rows) => { | ||
| if (handleError(err, COMMON_LOG_MESSAGES.ERROR)) return; | ||
| checkIfEmpty(rows, logMessage, LIST_MEMOS_LOG_MESSAGES.NOT_FOUND); | ||
| logMessage(LIST_MEMOS_LOG_MESSAGES.TITLE); | ||
| rows.forEach((row) => { | ||
| logMessage(`・${row.memo.split("\n")[0]}\n`); | ||
| }); | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // 外部ライブラリ | ||
| import inquirer from "inquirer"; | ||
|
|
||
| // プロジェクト内からのインポート | ||
| import { SELECT_ALL_MEMOS } from "../db/queries.js"; | ||
| import { | ||
| COMMON_LOG_MESSAGES, | ||
| MEMO_HELPERS_LOG_MESSAGES, | ||
| logMessage, | ||
| handleError, | ||
| } from "../config/log.js"; | ||
|
|
||
| export async function handleMemoAction( | ||
| db, | ||
| promptMessage, | ||
| query, | ||
| successMessage, | ||
| ) { | ||
| const selectedMemoId = await selectMemo(db, promptMessage); | ||
|
|
||
| if (selectedMemoId) { | ||
| db.get(query, [selectedMemoId], (err, result) => { | ||
| if (handleError(err, COMMON_LOG_MESSAGES.ERROR)) return; | ||
| if (result) { | ||
| logMessage(successMessage(result)); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| export async function selectMemo(db, message) { | ||
| return new Promise((resolve, reject) => { | ||
| db.all(SELECT_ALL_MEMOS, [], async (err, rows) => { | ||
| if (handleError(err, COMMON_LOG_MESSAGES.ERROR)) return reject(err); | ||
| checkIfEmpty( | ||
| rows, | ||
| logMessage, | ||
| MEMO_HELPERS_LOG_MESSAGES.NO_MEMOS, | ||
| resolve, | ||
| ); | ||
|
|
||
| const choices = rows.map((row) => ({ | ||
| name: row.memo.split("\n")[0], | ||
| value: row.id, | ||
| })); | ||
|
|
||
| const answer = await inquirer.prompt([ | ||
| { | ||
| type: "list", | ||
| name: "selectedMemo", | ||
| message: message, | ||
| choices: choices, | ||
| }, | ||
| ]); | ||
|
|
||
| resolve(answer.selectedMemo); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| export function checkIfEmpty(array, logMessage, message, resolve = null) { | ||
| if (array.length === 0) { | ||
| logMessage(message); | ||
| if (resolve) { | ||
| return resolve(null); | ||
| } | ||
| return; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { SELECT_MEMO_BY_ID } from "../db/queries.js"; | ||
| import { READ_MEMO_LOG_MESSAGES } from "../config/log.js"; | ||
| import { handleMemoAction } from "./memoHelpers.js"; | ||
|
|
||
| export async function readMemo(db) { | ||
| await handleMemoAction( | ||
| db, | ||
| READ_MEMO_LOG_MESSAGES.PROMPT, | ||
| SELECT_MEMO_BY_ID, | ||
| (row) => `\n${row.memo}\n`, | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // ログ出力関数(標準出力) | ||
| export function logMessage(message) { | ||
| process.stdout.write(message); | ||
| } | ||
|
|
||
| // ログ出力関数(エラー出力) | ||
| export function logError(message) { | ||
| process.stderr.write(message); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer |
||
|
|
||
| export function handleError(err, logMessage) { | ||
| if (err) { | ||
| logError(`${logMessage}${err.message}\n`); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 非同期処理のプラクティスで例外処理について触れているのだから、エラーは boolean ではなく例外として取り扱うべきでしょう。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer
また、 |
||
|
|
||
| // 共通ログメッセージ | ||
| export const COMMON_LOG_MESSAGES = { | ||
| ERROR: "エラー: ", | ||
| }; | ||
|
|
||
| // database.js 専用のログメッセージ | ||
| export const DATABASE_LOG_MESSAGES = { | ||
| SETUP_ERROR: "テーブル作成中にエラーが発生しました: ", | ||
| CONNECTION_ERROR: "データベース接続エラー: ", | ||
| SUCCESS: "データベースのセットアップが完了しました。\n", | ||
| }; | ||
|
|
||
| // addMemo.js 専用のログメッセージ | ||
| export const ADD_MEMO_LOG_MESSAGES = { | ||
| PROMPT: | ||
| "メモの内容を入力してください(終了するにはCtrl + Dを押してください):\n", | ||
| EMPTY: "メモの内容が空です。保存されませんでした。\n", | ||
| SUCCESS: "メモを追加しました。\n", | ||
| }; | ||
|
|
||
| // listMemos.js 専用のログメッセージ | ||
| export const LIST_MEMOS_LOG_MESSAGES = { | ||
| TITLE: "メモ一覧:\n", | ||
| NOT_FOUND: "メモが存在しません。\n", | ||
| }; | ||
|
|
||
| // readMemo.js 専用のログメッセージ | ||
| export const READ_MEMO_LOG_MESSAGES = { | ||
| PROMPT: "表示するメモを選んでください:", | ||
| NOT_FOUND: "メモが見つかりません。\n", | ||
| }; | ||
|
|
||
| // deleteMemo.js 専用のログメッセージ | ||
| export const DELETE_MEMO_LOG_MESSAGES = { | ||
| PROMPT: "削除するメモを選んでください:", | ||
| SUCCESS: "メモを削除しました。\n", | ||
| NOT_FOUND: "削除するメモが見つかりません。\n", | ||
| }; | ||
|
|
||
| // memoHelpers.js 専用のログメッセージ | ||
| export const MEMO_HELPERS_LOG_MESSAGES = { | ||
| NO_MEMOS: "メモが存在しません。\n", | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // データベースのパス | ||
| export const DATABASE_PATH = "./db/memo.db"; | ||
|
|
||
| // ファイルのエンコーディング | ||
| export const FILE_ENCODING = "utf-8"; | ||
|
|
||
| // コマンドラインオプション設定 | ||
| export const OPTIONS = { | ||
| LIST: "-l", | ||
| READ: "-r", | ||
| DELETE: "-d", | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // 外部ライブラリ | ||
| import sqlite3 from "sqlite3"; | ||
|
|
||
| // プロジェクト内からのインポート | ||
| import { CREATE_TABLE_MEMOS } from "./queries.js"; | ||
| import { DATABASE_LOG_MESSAGES, handleError } from "../config/log.js"; | ||
| import { DATABASE_PATH } from "../config/settings.js"; | ||
|
|
||
| export class Database { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer |
||
| constructor() { | ||
| this.db = new sqlite3.Database(DATABASE_PATH, (err) => { | ||
| if (handleError(err, DATABASE_LOG_MESSAGES.CONNECTION_ERROR)) return; | ||
| this.setupDatabase(); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 非同期処理の課題で、コールバックベースのものを Promise として扱うことを学んでいるのだから、Promise として扱うようにしてほしいです。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer constructor
connect
openDatabase
createMemosTable
export class MemoDatabase {
constructor() {
this.db = null;
}
async connect() {
try {
this.db = await this.#openDatabase(DATABASE_PATH);
await this.#createMemosTable();
} catch (err) {
handleError(err, DATABASE_LOG_MESSAGES.CONNECTION_ERROR);
}
}
#openDatabase(path) {
return new Promise((resolve, reject) => {
const db = new sqlite3.Database(path, (err) => {
if (err) {
reject(err);
} else {
resolve(db);
}
});
});
}
#createMemosTable() {
return new Promise((resolve, reject) => {
this.db.run(CREATE_MEMOS_TABLE, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
get databaseConnection() {
return this.db;
}
}memo.jsインスタンス作成後connectメソッドをawaitを用いて呼び出すことで、SQLiteデータベース・memosテーブルが正常に作成された後にメモアプリが起動する流れになるようになりました。 const database = new MemoDatabase();
await database.connect(); |
||
| } | ||
|
|
||
| setupDatabase() { | ||
| this.db.run(CREATE_TABLE_MEMOS, (err) => { | ||
| if (handleError(err, DATABASE_LOG_MESSAGES.SETUP_ERROR)) return; | ||
| }); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 他のクラスから実行されないメソッドは可視性を private にしてください。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. node-sqlite3 の処理がコールバックベースで扱われているので、現状の実装だと CREATE TABLE の処理の完了を待つことなく、後続の処理が実行されてしまうと思いますよ。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer |
||
|
|
||
| getDb() { | ||
| return this.db; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getter を定義する仕組みがあるのでそれを使ってください。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer database.js修正対象箇所 get databaseConnection() {
return this.db;
}appManager.js修正対象箇所 constructor(database) {
this.db = database.databaseConnection;
}参考記事 |
||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. データベースファイルはコミットしないでください。データベースのデータに変更があるたびに git の差分が生じるからです。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // メモのテーブルを作成するクエリ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. コードを読めば分かることをコメントとして残すのはやめましょう。コードやコメントの変更にともなって両者の乖離が発生すると、どちらの内容が正しいのか分からなくなってしまうからです。コードからは分からないことのみ、コメントとして残すようにしてください。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer export const CREATE_TABLE_MEMOS = `CREATE TABLE IF NOT EXISTS memos (id INTEGER PRIMARY KEY AUTOINCREMENT, memo TEXT)`;
export const INSERT_MEMO = `INSERT INTO memos (memo) VALUES (?)`;
export const SELECT_ALL_MEMOS = `SELECT id, memo FROM memos`;
export const SELECT_MEMO_BY_ID = `SELECT * FROM memos WHERE id = ?`;
export const DELETE_MEMO_BY_ID = `DELETE FROM memos WHERE id = ?`;
コードからは分からないことだったり、どうしても可読性が低くなってしまう場合や視認性が低いコードを書かなければいけない場合にのみ使用していきます。 |
||
| export const CREATE_TABLE_MEMOS = ` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この定数だけ、他の定数と名前付けが揃っていないです。他と合わせるのなら、
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer |
||
| CREATE TABLE IF NOT EXISTS memos ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| memo TEXT | ||
| ) | ||
| `; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. テンプレート文字列を使って複数行の文字列を定義し、かつそれをインデントすると、インデント分の余分な空白が先頭に挿入されてしまいます。SQL に余分な空白が含まれていて実行上の問題はないものの、不要なものなので好ましくはないです。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer export const CREATE_TABLE_MEMOS = `CREATE TABLE IF NOT EXISTS memos (id INTEGER PRIMARY KEY AUTOINCREMENT, memo TEXT)`;
....... |
||
|
|
||
| // メモを作成するクエリ | ||
| export const INSERT_MEMO = ` | ||
| INSERT INTO memos (memo) VALUES (?) | ||
| `; | ||
|
|
||
| // メモを全て取得するクエリ | ||
| export const SELECT_ALL_MEMOS = ` | ||
| SELECT id, memo FROM memos | ||
| `; | ||
|
|
||
| // メモをIDで取得するクエリ | ||
| export const SELECT_MEMO_BY_ID = ` | ||
| SELECT * FROM memos WHERE id = ? | ||
| `; | ||
|
|
||
| // メモをIDで削除するクエリ | ||
| export const DELETE_MEMO_BY_ID = ` | ||
| DELETE FROM memos WHERE id = ? | ||
| `; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. このファイルは
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { Database } from "./db/database.js"; | ||
| import { MemoApp } from "./actions/appManager.js"; | ||
| import { OPTIONS } from "./config/settings.js"; | ||
|
|
||
| const database = new Database(); | ||
| const memoApp = new MemoApp(database); | ||
| const args = process.argv.slice(2); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 理解度を確認するために
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cafedomancer こちら、カレンダーのプラクティスと同様にオプション周りの実装は |
||
|
|
||
| switch (args[0]) { | ||
| case OPTIONS.LIST: | ||
| memoApp.listMemos(); | ||
| break; | ||
| case OPTIONS.READ: | ||
| memoApp.readMemo(); | ||
| break; | ||
| case OPTIONS.DELETE: | ||
| memoApp.deleteMemo(); | ||
| break; | ||
| default: | ||
| memoApp.addMemo(); | ||
| break; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ファイル名とクラス名を一致させてください。他にも処理が定義されているのなら
appManager.jsという名前でよい可能性もありますが、現状はMemoAppクラスしか定義されていないからです。Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cafedomancer
修正内容
ファイル名を
appManager.jsからmemoApp.jsに変更しました。質問
memoApp.jsにしたのですが、クラス名と全く同じMemoAppのようにパスカルケースにした方が良いでしょうか?