Skip to content

Commit 4e1d92a

Browse files
committed
Address comments for chapter 09
1 parent c49e766 commit 4e1d92a

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

09-behavioral-design-patterns/01-strategy-multiformat-config/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class Config {
2424

2525
async save (filePath) {
2626
console.log(`Serializing to ${filePath}`)
27-
await fs.writeFile(filePath, this.formatStrategy.serialize(this.data))
27+
await fs.writeFile(filePath,
28+
this.formatStrategy.serialize(this.data))
2829
}
2930
}

09-behavioral-design-patterns/03-template-multiformat-config/configTemplate.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import objectPath from 'object-path'
44
export class ConfigTemplate {
55
async load (file) {
66
console.log(`Deserializing from ${file}`)
7-
this.data = this._deserialize(await fsPromises.readFile(file, 'utf-8'))
7+
this.data = this._deserialize(
8+
await fsPromises.readFile(file, 'utf-8'))
89
}
910

1011
async save (file) {

09-behavioral-design-patterns/03-template-multiformat-config/jsonConfig.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ConfigTemplate } from './configTemplate.js'
33
export class JsonConfig extends ConfigTemplate {
44
_deserialize (data) {
55
return JSON.parse(data)
6-
};
6+
}
77

88
_serialize (data) {
99
return JSON.stringify(data, null, ' ')

09-behavioral-design-patterns/08-iterator-two-way/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ const twoWay = twoWayGenerator()
1212
twoWay.next()
1313
console.log(twoWay.next('world'))
1414

15-
console.log('throw():')
15+
console.log('Using throw():')
1616
const twoWayException = twoWayGenerator()
1717
twoWayException.next()
1818
console.log(twoWayException.throw(new Error('Boom!')))
1919

20-
console.log('return():')
20+
console.log('Using return():')
2121
const twoWayReturn = twoWayGenerator()
2222
console.log(twoWayReturn.return('myReturnValue'))

09-behavioral-design-patterns/09-iterator-matrix-generator/matrix.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ export class Matrix {
44
}
55

66
get (row, column) {
7-
if (row >= this.data.length || column >= this.data[row].length) {
7+
if (row >= this.data.length ||
8+
column >= this.data[row].length) {
89
throw new Error('Out of bounds')
910
}
1011
return this.data[row][column]
1112
}
1213

1314
set (row, column, value) {
14-
if (row >= this.data.length || column >= this.data[row].length) {
15+
if (row >= this.data.length ||
16+
column >= this.data[row].length) {
1517
throw new Error('Out of bounds')
1618
}
1719
this.data[row][column] = value

09-behavioral-design-patterns/14-command/invoker.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import request from 'superagent'
1+
import superagent from 'superagent'
22

33
// The Invoker
44
export class Invoker {
@@ -26,7 +26,7 @@ export class Invoker {
2626
}
2727

2828
async runRemotely (cmd) {
29-
await request
29+
await superagent
3030
.post('http://localhost:3000/cmd')
3131
.send({ json: cmd.serialize() })
3232

0 commit comments

Comments
 (0)