Skip to content

Commit aeb1dc7

Browse files
committed
Improve examples
1 parent db79e4b commit aeb1dc7

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

JavaScript/1-simple.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class AccountQuery {
1717
}
1818

1919
class BankAccount {
20+
static collection = new Map();
21+
2022
constructor(name) {
2123
this.name = name;
2224
this.balance = 0;
@@ -28,14 +30,12 @@ class BankAccount {
2830
}
2931
}
3032

31-
BankAccount.collection = new Map();
32-
33-
const operations = {
34-
Withdraw: (command) => {
33+
const OPERATIONS = {
34+
withdraw: (command) => {
3535
const account = BankAccount.find(command.account);
3636
account.balance -= command.amount;
3737
},
38-
Income: (command) => {
38+
income: (command) => {
3939
const account = BankAccount.find(command.account);
4040
account.balance += command.amount;
4141
},
@@ -47,12 +47,11 @@ class Bank {
4747
this.queries = [];
4848
}
4949

50-
operation(account, amount) {
51-
const operation = amount < 0 ? 'Withdraw' : 'Income';
52-
const execute = operations[operation];
53-
const command = new AccountCommand(
54-
account.name, operation, Math.abs(amount)
55-
);
50+
operation(account, value) {
51+
const operation = value < 0 ? 'withdraw' : 'income';
52+
const execute = OPERATIONS[operation];
53+
const amount = Math.abs(value);
54+
const command = new AccountCommand(account.name, operation, amount);
5655
this.commands.push(command);
5756
console.dir(command);
5857
execute(command);
@@ -89,10 +88,10 @@ console.table([account1, account2]);
8988
const res1 = bank.select({ account: 'Marcus Aurelius' });
9089
console.table(res1);
9190

92-
const res2 = bank.select({ account: 'Antoninus Pius', operation: 'Income' });
91+
const res2 = bank.select({ account: 'Antoninus Pius', operation: 'income' });
9392
console.table(res2);
9493

95-
const res3 = bank.select({ operation: 'Withdraw' });
94+
const res3 = bank.select({ operation: 'withdraw' });
9695
console.table(res3);
9796

9897
console.log('Query logs:');

JavaScript/2-scale.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class AccountQuery {
2020
}
2121

2222
class BankAccount {
23+
static collection = new Map();
24+
2325
constructor(name) {
2426
this.name = name;
2527
this.balance = 0;
@@ -31,14 +33,12 @@ class BankAccount {
3133
}
3234
}
3335

34-
BankAccount.collection = new Map();
35-
36-
const operations = {
37-
Withdraw: (command) => {
36+
const OPERATIONS = {
37+
withdraw: (command) => {
3838
const account = BankAccount.find(command.account);
3939
account.balance -= command.amount;
4040
},
41-
Income: (command) => {
41+
income: (command) => {
4242
const account = BankAccount.find(command.account);
4343
account.balance += command.amount;
4444
},
@@ -49,12 +49,11 @@ class BankWrite {
4949
this.commands = [];
5050
}
5151

52-
operation(account, amount) {
53-
const operation = amount < 0 ? 'Withdraw' : 'Income';
54-
const execute = operations[operation];
55-
const command = new AccountCommand(
56-
account.name, operation, Math.abs(amount)
57-
);
52+
operation(account, value) {
53+
const operation = value < 0 ? 'withdraw' : 'income';
54+
const execute = OPERATIONS[operation];
55+
const amount = Math.abs(value);
56+
const command = new AccountCommand(account.name, operation, amount);
5857
this.commands.push(command);
5958
eventBus.emit('command', command);
6059
console.dir(command);
@@ -106,11 +105,13 @@ console.table([account1, account2]);
106105
const res1 = readApi1.select({ account: 'Marcus Aurelius' });
107106
console.table(res1);
108107

109-
const res2 = readApi2
110-
.select({ account: 'Antoninus Pius', operation: 'Income' });
108+
const res2 = readApi2.select({
109+
account: 'Antoninus Pius',
110+
operation: 'income',
111+
});
111112
console.table(res2);
112113

113-
const res3 = readApi3.select({ operation: 'Withdraw' });
114+
const res3 = readApi3.select({ operation: 'withdraw' });
114115
console.table(res3);
115116

116117
console.table(readApi3.queries);

0 commit comments

Comments
 (0)