 
     console.log "######## post-code ########"
 
+    # local vars -> sheets
+    for sym of $blab.component.sheet
+        $blab.component.sheet[sym].fromLocal(eval(sym))
+
+    # update sinks
+    for c of $blab.component
+        for i of $blab.component[c]
+            item = $blab.component[c][i]
+            item.update() if item.spec.isSink is "true"
+
+    # update spec
     $blab.spec = {}
     for c of $blab.component
         $blab.spec[c] = {}
         for i of $blab.component[c]
-            $blab.spec[c][i] = $blab.component[c][i].spec
-            if c == "sheet"
-                $blab.component.sheet[i].fromLocal(eval(i))
-            else
-                $blab.component[c][i].update()
+            item = $blab.component[c][i]
+            $blab.spec[c][i] = item.spec
 
     console.log ">>>", JSON.stringify($blab.spec)
-    
-
-loadgist = (gistid, filename) ->
-
-    $.ajax(
-        url: "https://api.github.com/gists/#{gistid}"
-        type: 'GET'
-        dataType: 'jsonp'
-
-    ).success((gistdata) ->
-        specs = JSON.parse(gistdata.data.files[filename].content)
-        build = (w) ->
-            $blab["component"][w] = {}
-            $blab["component"][w][spec.id] = new toolbox[w] spec for spec in specs[w]
-
+
+
+class App
+
+    token: dev.token
+    gistId: dev.gistId
+    
+    constructor: ->
+
+        github = new Github
+            token: @token
+            auth: "oauth"
+
+        @gist = github.getGist(@gistId)
+        
+        console.log "gist", @gist
+
+        @readGist()
+
+    readGist: ->
+        @gist.read((err, gist)=> @buildSpec(err,gist))
+
+    buildSpec: (err,gist) ->
+
+        specs = JSON.parse(gist.files["app.json"].content)
+
+        build = (item) ->
+            $blab["component"][item] = {}
+            for sym of specs[item]
+                $blab["component"][item][sym] = new toolbox[item] specs[item][sym]
+                
         $blab["component"] = {}
-
         for spec of specs
             build(spec)
 
-        compute()
-        
-    ).error (e) ->
-        # ajax error
-        return
-
-loadgist("f673df3f600fdeb17608", "app.json")
-
-
+        @updateSpec()
+        @saveGist($blab.spec)
+
+    saveGist: (json) ->
+        
+        data =
+            "description": "the description for this gist"
+            "files":
+                "app2.json":
+                    "content": JSON.stringify($blab.spec)
+
+        @gist.update(data, (err, gist) -> console.log "save?", err, gist)
+
+    updateSpec: ->
+
+        $blab.spec = {}
+        for c of $blab.component
+            $blab.spec[c] = {}
+            for i of $blab.component[c]
+                item = $blab.component[c][i]
+                $blab.spec[c][i] = item.spec
+
+        console.log ">>>", JSON.stringify($blab.spec)
+
+new App
+
+


$("#widget-menu").menu select: (event, ui) ->
    console.log "ui type?", ui.item[0].innerHTML
    return

$("#tabs").tabs()

marked.setOptions
    renderer: new (marked.Renderer)

    figure: PlotXY
    table: Table
    markdown: Markdown
    slider: Slider

# user code

