                         @painter.fillCellPending cell
         @firstVisibleRow = i
 
-window.fattable = (params)->
+
+fattable = (params)->
     new TableView params
 
-window.fattable.TableData = TableData
-window.fattable.TableView = TableView
-window.fattable.CellPainter = CellPainter
-window.fattable.PagedAsyncTableData = PagedAsyncTableData
-window.fattable.SyncTableData = SyncTableData+ns =
+    TableData: TableData
+    TableView: TableView
+    CellPainter: CellPainter
+    PagedAsyncTableData: PagedAsyncTableData
+    SyncTableData: SyncTableData
+    bound: bound
+
+for k,v of ns
+    fattable[k] = v
+
+window.fattable = fattable

    visible: (x,y)->
        # returns the square
        #   [ i_a -> i_b ]  x  [ j_a, j_b ]
        j = binary_search @columnOffset, x
        i = (y / @rowHeight | 0)
        i = Math.max(0, i)
        i = Math.min(i, @nbRows - @nbRowsVisible)
        j = Math.max(0, j)
        j = Math.min(j, @nbCols - @nbColsVisible)
        [i, j]

    setup: ->

document.addEventListener "DOMContentLoaded", =>
    document.removeEventListener "DOMContentLoaded", arguments.callee


bound = (x, m, M)->
    if (x < m) then m else if (x > M) then M else x

class Promise

