 
 
   constructor: (el, @changeCallback) ->
-    @runner = new ReactiveRunner()
-    @runner.onChange @changeCallback
-    @runner.addProvidedStreams CoreFunctions
-    @runner.addProvidedStreams TimeFunctions
-    @runner.addProvidedStreams PageFunctions
-    @runner.onChange (name, value) => @_updateTable name, value
-    @loader = new TextLoader(@runner)
+    @sheet = Freesheet.createSheet(el.attr('id') or 'sheet1')
+    @sheet.onChange @changeCallback
+    @sheet.addFunctions CoreFunctions
+    @sheet.addFunctions TimeFunctions
+    @sheet.addFunctions PageFunctions
+    @sheet.onChange (name, value) => @_updateTable name, value
     @data = ({name: null, formula: null, value: null} for i in [1..5] )
 
     @table = new Handsontable el.get(0), {

ReactiveRunner = require('reactive-runner')
TextLoader = require('text-loader')
TextParser = require('text-parser')
CoreFunctions = require('core-functions')
PageFunctions = require('page-functions')
TimeFunctions = require('time-functions')

      console.log 'beforeRemoveRow', index, numberOfRows, self.data
      for row in self.data[index...index + numberOfRows]
        console.log 'Removing row', row
        self.sheet.remove row.name

  updateFormula: (name, formula, oldName, nextName) ->
    console.log 'updateFormula', name, formula, oldName, nextName
    if name and formula then @sheet.update name, formula, oldName, nextName
    if name and not formula then @sheet.remove name
    if not name and oldName then @sheet.remove oldName


  asText: -> @sheet.text()

  loadText: (text) ->
    @loading = true
    @sheet.clear()
    @data.length = 0
    @sheet.load text
    @_newRow null
    @loading = false

