-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter06_factoryTest.js
62 lines (49 loc) · 1.19 KB
/
chapter06_factoryTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
UnderlinedCell = winWidth +
function TextCell(text){
this.text = text.split("\n");
}
TextCell.prototype.minWidth = function(){
//this.text is always and array, possibly with many entries
let result = this.text.reduce((max, current) => Math.max(max, current.length), 0);
return result;
}
TextCell.prototype.minHeight = function(){
return this.text.length;
}
TextCell.prototype.draw = function(width, height){
// return an array with cell content formatted as strings, one array element per line
let result = [];
// console.log("in TC.pt.draw: %s %s", width, height)
for(let i = 0; i < height; i++){
var line = this.text[i] || "";
result.push(line + repeat(" ", width - line.length))
}
return result
}
*/
const minWidth = (state) => ({
minWidth: () => state.text.reduce((max, current) => Math.max(max, current.length), 0)
})
function minWidth(state){
return
}
const draw = (state) => ({
draw: () => state.text
})
const TextCell = (text) => {
let state = {
text,
meaningOfLife: 42
}
return Object.assign(
{},
minWidth(state),
draw(state)
/*,
minHeight(state),
*/
)
}
const myCell = TextCell("mytext")
console.log(myCell.draw())