Permalink
Browse files

Add async data loading

  • Loading branch information...
koenbok committed May 15, 2014
1 parent 7f31ec8 commit a05732ae0ae8e89bd3184b2cf7898f37b9d31125
Showing with 40 additions and 0 deletions.
  1. +22 −0 framer/Utils.coffee
  2. +18 −0 test/tests/UtilsTest.coffee
@@ -255,6 +255,28 @@ Utils.domLoadScript = (url, callback) ->
script
Utils.domLoadData = (path, callback) ->
request = new XMLHttpRequest()
# request.addEventListener "progress", updateProgress, false
# request.addEventListener "abort", transferCanceled, false
request.addEventListener "load", ->
callback null, request.responseText
, false
request.addEventListener "error", ->
callback true, null
, false
request.open "GET", path, true
request.send null
Utils.domLoadJSON = (path, callback) ->
Utils.domLoadData path, (err, data) ->
callback err, JSON.parse data
Utils.domLoadDataSync = (path) ->
request = new XMLHttpRequest()
@@ -156,6 +156,20 @@ describe "Utils", ->
# Bla bla. This works. Doing a visual comparison is so much easier
# Start the cactus project and go to /test.html
describe "domLoadData", (callback) ->
it "should load data async", (callback) ->
data = Utils.domLoadData "static/test.txt", (err, data) ->
data.should.equal "TEST HELLO"
callback()
it "should load throw error on nonexisting", (callback) ->
data = Utils.domLoadData "static/test123.txt", (err, data) ->
err.should.equal true
callback()
describe "domLoadDataSync", ->
it "should load data async", ->
@@ -171,4 +185,8 @@ describe "Utils", ->

0 comments on commit a05732a

Please sign in to comment.