Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9c7db3a

Browse files
Fix code snippets indentation
1 parent 0c19907 commit 9c7db3a

23 files changed

+725
-696
lines changed

‎src/static/patterns/behavioral_chainOfResponsibility.js‎

Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4,125 +4,126 @@ const CHAIN_OF_RESPONSIBILITY = {
44
type: 'behavioral',
55
hint: 'delegates commands to a chain of processing objects',
66
codeES5: `function ShoppingCart() {
7-
this.products = [];
7+
this.products = [];
88
9-
this.addProduct = function(p) {
10-
this.products.push(p);
11-
};
9+
this.addProduct = function(p) {
10+
this.products.push(p);
11+
};
1212
}
1313
1414
function Discount() {
15-
this.calc = function(products) {
16-
var ndiscount = new NumberDiscount();
17-
var pdiscount = new PriceDiscount();
18-
var none = new NoneDiscount();
15+
this.calc = function(products) {
16+
var ndiscount = new NumberDiscount();
17+
var pdiscount = new PriceDiscount();
18+
var none = new NoneDiscount();
1919
20-
ndiscount.setNext(pdiscount);
21-
pdiscount.setNext(none);
20+
ndiscount.setNext(pdiscount);
21+
pdiscount.setNext(none);
2222
23-
return ndiscount.exec(products);
24-
};
23+
return ndiscount.exec(products);
24+
};
2525
}
2626
2727
function NumberDiscount() {
28-
this.next = null;
29-
this.setNext = function(fn) {
30-
this.next = fn;
31-
};
28+
this.next = null;
29+
this.setNext = function(fn) {
30+
this.next = fn;
31+
};
3232
33-
this.exec = function(products) {
34-
var result = 0;
35-
if (products.length > 3) result = 0.05;
33+
this.exec = function(products) {
34+
var result = 0;
35+
if (products.length > 3) result = 0.05;
3636
37-
return result + this.next.exec(products);
38-
};
37+
return result + this.next.exec(products);
38+
};
3939
}
4040
4141
function PriceDiscount() {
42-
this.next = null;
43-
this.setNext = function(fn) {
44-
this.next = fn;
45-
};
46-
this.exec = function(products) {
47-
var result = 0;
48-
var total = products.reduce(function(a, b) {
49-
return a + b;
50-
});
42+
this.next = null;
43+
this.setNext = function(fn) {
44+
this.next = fn;
45+
};
46+
this.exec = function(products) {
47+
var result = 0;
48+
var total = products.reduce(function(a, b) {
49+
return a + b;
50+
});
5151
52-
if (total >= 500) result = 0.1;
52+
if (total >= 500) result = 0.1;
5353
54-
return result + this.next.exec(products);
55-
};
54+
return result + this.next.exec(products);
55+
};
5656
}
5757
5858
function NoneDiscount() {
59-
this.exec = function() {
60-
return 0;
61-
};
59+
this.exec = function() {
60+
return 0;
61+
};
6262
}
6363
6464
module.exports = [ShoppingCart, Discount];`,
6565
codeES6: `class ShoppingCart {
66-
constructor() {
67-
this.products = [];
68-
}
66+
constructor() {
67+
this.products = [];
68+
}
6969
70-
addProduct(p) {
71-
this.products.push(p);
72-
}
70+
addProduct(p) {
71+
this.products.push(p);
72+
}
7373
}
7474
7575
class Discount {
76-
calc(products) {
77-
let ndiscount = new NumberDiscount();
78-
let pdiscount = new PriceDiscount();
79-
let none = new NoneDiscount();
80-
ndiscount.setNext(pdiscount);
81-
pdiscount.setNext(none);
82-
return ndiscount.exec(products);
83-
}
76+
calc(products) {
77+
let ndiscount = new NumberDiscount();
78+
let pdiscount = new PriceDiscount();
79+
let none = new NoneDiscount();
80+
ndiscount.setNext(pdiscount);
81+
pdiscount.setNext(none);
82+
83+
return ndiscount.exec(products);
84+
}
8485
}
8586
8687
class NumberDiscount {
87-
constructor() {
88-
this.next = null;
89-
}
88+
constructor() {
89+
this.next = null;
90+
}
9091
91-
setNext(fn) {
92-
this.next = fn;
93-
}
92+
setNext(fn) {
93+
this.next = fn;
94+
}
9495
95-
exec(products) {
96-
let result = 0;
97-
if (products.length > 3) result = 0.05;
96+
exec(products) {
97+
let result = 0;
98+
if (products.length > 3) result = 0.05;
9899
99-
return result + this.next.exec(products);
100-
}
100+
return result + this.next.exec(products);
101+
}
101102
}
102103
103104
class PriceDiscount {
104-
constructor() {
105-
this.next = null;
106-
}
105+
constructor() {
106+
this.next = null;
107+
}
107108
108-
setNext(fn) {
109-
this.next = fn;
110-
}
109+
setNext(fn) {
110+
this.next = fn;
111+
}
111112
112-
exec(products) {
113-
let result = 0;
114-
let total = products.reduce((a, b) => a + b);
113+
exec(products) {
114+
let result = 0;
115+
let total = products.reduce((a, b) => a + b);
115116
116-
if (total >= 500) result = 0.1;
117+
if (total >= 500) result = 0.1;
117118
118-
return result + this.next.exec(products);
119-
}
119+
return result + this.next.exec(products);
120+
}
120121
}
121122
122123
class NoneDiscount {
123-
exec() {
124-
return 0;
125-
}
124+
exec() {
125+
return 0;
126+
}
126127
}
127128
128129
export { ShoppingCart, Discount };`

‎src/static/patterns/behavioral_command.js‎

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,105 +4,115 @@ const COMMAND = {
44
type: 'behavioral',
55
hint: 'creates objects which encapsulate actions and parameters',
66
codeES5: `function Cockpit(instruction) {
7-
this.instruction = instruction;
7+
this.instruction = instruction;
88
}
9+
910
Cockpit.prototype.execute = function() {
10-
this.instruction.execute();
11+
this.instruction.execute();
1112
};
1213
1314
function Turbine() {
14-
this.speed = 0;
15-
this.state = false;
15+
this.speed = 0;
16+
this.state = false;
1617
}
1718
1819
Turbine.prototype.on = function() {
19-
this.state = true;
20-
this.speed = 100;
20+
this.state = true;
21+
this.speed = 100;
2122
};
2223
2324
Turbine.prototype.off = function() {
24-
this.speed = 0;
25-
this.state = false;
25+
this.speed = 0;
26+
this.state = false;
2627
};
2728
2829
Turbine.prototype.speedDown = function() {
29-
if (!this.state) return;
30+
if (!this.state) return;
3031
31-
this.speed -= 100;
32+
this.speed -= 100;
3233
};
3334
3435
Turbine.prototype.speedUp = function() {
35-
if (!this.state) return;
36+
if (!this.state) return;
3637
37-
this.speed += 100;
38+
this.speed += 100;
3839
};
3940
4041
function OnInstruction(turbine) {
41-
this.turbine = turbine;
42+
this.turbine = turbine;
4243
}
44+
4345
OnInstruction.prototype.execute = function() {
44-
this.turbine.on();
46+
this.turbine.on();
4547
};
4648
4749
function OffInstruction(turbine) {
48-
this.turbine = turbine;
50+
this.turbine = turbine;
4951
}
52+
5053
OffInstruction.prototype.execute = function() {
51-
this.turbine.off();
54+
this.turbine.off();
5255
};
5356
5457
function SpeedUpInstruction(turbine) {
55-
this.turbine = turbine;
58+
this.turbine = turbine;
5659
}
60+
5761
SpeedUpInstruction.prototype.execute = function() {
58-
this.turbine.speedUp();
62+
this.turbine.speedUp();
5963
};
6064
6165
function SpeedDownInstruction(turbine) {
62-
this.turbine = turbine;
66+
this.turbine = turbine;
6367
}
68+
6469
SpeedDownInstruction.prototype.execute = function() {
65-
this.turbine.speedDown();
70+
this.turbine.speedDown();
6671
};
6772
6873
module.exports = [Cockpit, Turbine, OnInstruction, OffInstruction, SpeedUpInstruction, SpeedDownInstruction];`,
6974
codeES6: `class Cockpit {
70-
constructor(instruction) {
71-
this.instruction = instruction;
72-
}
73-
execute() {
74-
this.instruction.execute();
75-
}
75+
constructor(instruction) {
76+
this.instruction = instruction;
77+
}
78+
79+
execute() {
80+
this.instruction.execute();
81+
}
7682
}
7783
7884
class Turbine {
79-
constructor() {
80-
this.state = false;
81-
}
82-
on() {
83-
this.state = true;
84-
}
85-
off() {
86-
this.state = false;
87-
}
85+
constructor() {
86+
this.state = false;
87+
}
88+
89+
on() {
90+
this.state = true;
91+
}
92+
93+
off() {
94+
this.state = false;
95+
}
8896
}
8997
9098
class OnInstruction {
91-
constructor(turbine) {
92-
this.turbine = turbine;
93-
}
94-
execute() {
95-
this.turbine.on();
96-
}
99+
constructor(turbine) {
100+
this.turbine = turbine;
101+
}
102+
103+
execute() {
104+
this.turbine.on();
105+
}
97106
}
98107
99108
class OffInstruction {
100-
constructor(turbine) {
101-
this.turbine = turbine;
102-
}
103-
execute() {
104-
this.turbine.off();
105-
}
109+
constructor(turbine) {
110+
this.turbine = turbine;
111+
}
112+
113+
execute() {
114+
this.turbine.off();
115+
}
106116
}
107117
108118
export { Cockpit, Turbine, OnInstruction, OffInstruction };`

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /