Skip to content

Commit bb95a1c

Browse files
committed
Improve examples
1 parent 8c17890 commit bb95a1c

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

JavaScript/bank.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ class BankAccount {
77
}
88
}
99

10-
const operations = {
11-
Create: (command, bank) => {
10+
const OPERATIONS = {
11+
create: (command, bank) => {
1212
const account = bank.find(command.account);
1313
if (!account) bank.createAccount(command.account);
1414
},
15-
Withdraw: (command, bank) => {
15+
withdraw: (command, bank) => {
1616
const account = bank.find(command.account);
1717
account.balance -= command.amount;
1818
},
19-
Income: (command, bank) => {
19+
income: (command, bank) => {
2020
const account = bank.find(command.account);
2121
account.balance += command.amount;
2222
},
@@ -37,7 +37,7 @@ class Bank {
3737
}
3838

3939
execute(command) {
40-
const operation = operations[command.operation];
40+
const operation = OPERATIONS[command.operation];
4141
operation(command, this);
4242
console.dir(command);
4343
}

JavaScript/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ console.table(res1);
2727
const marcusBalance1 = readApi1.getAccount(marcus);
2828
console.dir({ marcusBalance1 });
2929

30-
const res2 = readApi2.select({ account: pius, operation: 'Income' });
30+
const res2 = readApi2.select({ account: pius, operation: 'income' });
3131
console.table(res2);
3232

33-
const res3 = readApi3.select({ operation: 'Withdraw' });
33+
const res3 = readApi3.select({ operation: 'withdraw' });
3434
console.table(res3);

JavaScript/writer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ class BankWrite {
1818
}
1919

2020
createAccount(account) {
21-
const operation = 'Create';
21+
const operation = 'create';
2222
const command = new AccountCommand(account, operation);
2323
this.commands.push(command);
2424
this.eventBus.emit('command', command);
2525
this.bank.execute(command);
2626
}
2727

28-
operation(account, amount) {
29-
const operation = amount < 0 ? 'Withdraw' : 'Income';
30-
const command = new AccountCommand(account, operation, Math.abs(amount));
28+
operation(account, value) {
29+
const operation = value < 0 ? 'withdraw' : 'income';
30+
const amount = Math.abs(value);
31+
const command = new AccountCommand(account, operation, amount);
3132
this.commands.push(command);
3233
this.eventBus.emit('command', command);
3334
this.bank.execute(command);

0 commit comments

Comments
 (0)