Skip to content

Commit

Permalink
Add async data loading
Browse files Browse the repository at this point in the history
  • Loading branch information
koenbok committed May 15, 2014
1 parent 7f31ec8 commit a05732a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions framer/Utils.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -255,6 +255,28 @@ Utils.domLoadScript = (url, callback) ->


script 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) -> Utils.domLoadDataSync = (path) ->


request = new XMLHttpRequest() request = new XMLHttpRequest()
Expand Down
18 changes: 18 additions & 0 deletions test/tests/UtilsTest.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ describe "Utils", ->
# Bla bla. This works. Doing a visual comparison is so much easier # Bla bla. This works. Doing a visual comparison is so much easier
# Start the cactus project and go to /test.html # 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", -> describe "domLoadDataSync", ->


it "should load data async", -> it "should load data async", ->
Expand All @@ -171,4 +185,8 @@ describe "Utils", ->












0 comments on commit a05732a

Please sign in to comment.