Skip to content

Commit c4ee242

Browse files
committed
chapter 02: worsen the genericEncoder adding the method prepareData that also violates the open/closed principle
1 parent 0ac5c23 commit c4ee242

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

chapter-02-the-open-closed-principle/genericEncoder.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ function genericEncoder() {
1616
return encoder.encode(data);
1717
}
1818

19+
function prepareData(data, format) {
20+
switch (format) {
21+
case 'json': {
22+
data = this.forceArray(data);
23+
data = this.fixKeys(data);
24+
}
25+
case 'xml': {
26+
data = this.fixAttributes(data);
27+
break;
28+
}
29+
default: {
30+
throw new Error('Format not supported');
31+
}
32+
}
33+
34+
return data;
35+
}
36+
1937
return {
2038
encodeToFormat,
2139
};

0 commit comments

Comments
 (0)