-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
tiler.view.ts
59 lines (50 loc) · 1.28 KB
/
tiler.view.ts
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
namespace $.$$ {
/** Presents items as tiles. */
export class $mol_tiler extends $.$mol_tiler {
@ $mol_mem
sub() {
return this.groupChilds([ ])
}
@ $mol_mem_key
groupItems( path : number[] ) : readonly $mol_view[] {
var items = ( path.length === 0 )
? this.items()
: this.groupItems( path.slice( 0 , path.length - 1 ) )
if( items.length < 2 ) return items
if( path.length != 0 ) {
var cut = Math.floor( items.length / 2 )
items = path[ path.length -1 ]
? items.slice( cut )
: items.slice( 0 , cut )
}
return items
}
@ $mol_mem_key
groupChilds( path : number[] ) {
var items = this.groupItems( path )
if( items.length <= 2 ) return items.map( ( _ , index )=> this.item( path.concat( index ) ) )
return [
this.child( path.concat( 0 ) ) ,
this.child( path.concat( 1 ) ) ,
]
}
@ $mol_mem_key
child( path : number[] ) {
return ( this.groupItems( path ).length > 1 )
? this.group( path )
: this.item( path )
}
@ $mol_mem_key
group( path : number[] ) : $mol_view {
return $mol_view.make({
sub : () => this.groupChilds( path )
})
}
@ $mol_mem_key
item( path : number[] ) : $mol_view {
return $mol_view.make({
sub : () => this.groupItems( path )
})
}
}
}