Add editorconfig, resolve differences
This includes newlines, tabs, among other things.
This commit is contained in:
parent
80d0a69dab
commit
b4fb21475c
90 changed files with 1707 additions and 1701 deletions
|
|
@ -8,27 +8,27 @@ module.exports = function($window, Promise) {
|
|||
function xhr(args) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var useBody = typeof args.useBody === "boolean" ? args.useBody : args.method !== "GET" && args.method !== "TRACE"
|
||||
|
||||
|
||||
if (typeof args.serialize !== "function") args.serialize = JSON.stringify
|
||||
if (typeof args.deserialize !== "function") args.deserialize = deserialize
|
||||
if (typeof args.extract !== "function") args.extract = extract
|
||||
|
||||
|
||||
args.url = interpolate(args.url, args.data)
|
||||
if (useBody) args.data = args.serialize(args.data)
|
||||
else args.url = assemble(args.url, args.data)
|
||||
|
||||
|
||||
var xhr = new $window.XMLHttpRequest()
|
||||
xhr.open(args.method, args.url, typeof args.async === "boolean" ? args.async : true, typeof args.user === "string" ? args.user : undefined, typeof args.password === "string" ? args.password : undefined)
|
||||
|
||||
|
||||
if (args.serialize === JSON.stringify && useBody) {
|
||||
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8")
|
||||
}
|
||||
if (args.deserialize === deserialize) {
|
||||
xhr.setRequestHeader("Accept", "application/json, text/*")
|
||||
}
|
||||
|
||||
|
||||
if (typeof args.config === "function") xhr = args.config(xhr, args) || xhr
|
||||
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
try {
|
||||
|
|
@ -42,7 +42,7 @@ module.exports = function($window, Promise) {
|
|||
}
|
||||
else response = new args.type(response)
|
||||
}
|
||||
|
||||
|
||||
resolve(response)
|
||||
}
|
||||
else reject(new Error(xhr.responseText))
|
||||
|
|
@ -52,7 +52,7 @@ module.exports = function($window, Promise) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (useBody) xhr.send(args.data)
|
||||
else xhr.send()
|
||||
})
|
||||
|
|
@ -82,7 +82,7 @@ module.exports = function($window, Promise) {
|
|||
|
||||
function interpolate(url, data) {
|
||||
if (data == null) return url
|
||||
|
||||
|
||||
var tokens = url.match(/:[^\/]+/gi) || []
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
var key = tokens[i].slice(1)
|
||||
|
|
@ -109,6 +109,6 @@ module.exports = function($window, Promise) {
|
|||
}
|
||||
|
||||
function extract(xhr) {return xhr.responseText}
|
||||
|
||||
|
||||
return {xhr: xhr, jsonp: jsonp}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<script src="../../request/request.js"></script>
|
||||
<script src="test-xhr.js"></script>
|
||||
<script src="test-jsonp.js"></script>
|
||||
|
||||
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ o.spec("jsonp", function() {
|
|||
mock = xhrMock()
|
||||
jsonp = new Request(mock, Promise).jsonp
|
||||
})
|
||||
|
||||
|
||||
o("works", function(done) {
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
|
|
@ -52,4 +52,4 @@ o.spec("jsonp", function() {
|
|||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ o.spec("xhr", function() {
|
|||
mock = xhrMock()
|
||||
xhr = new Request(mock, Promise).xhr
|
||||
})
|
||||
|
||||
|
||||
o.spec("success", function() {
|
||||
o("works via GET", function(done) {
|
||||
var s = new Date
|
||||
|
|
@ -119,7 +119,7 @@ o.spec("xhr", function() {
|
|||
var Entity = function(args) {
|
||||
return {_id: args.id}
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify([{id: 1}, {id: 2}, {id: 3}])}
|
||||
|
|
@ -133,7 +133,7 @@ o.spec("xhr", function() {
|
|||
var Entity = function(args) {
|
||||
return {_id: args.id}
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify({id: 1})}
|
||||
|
|
@ -147,7 +147,7 @@ o.spec("xhr", function() {
|
|||
var serialize = function(data) {
|
||||
return "id=" + data.id
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify({body: request.query})}
|
||||
|
|
@ -161,7 +161,7 @@ o.spec("xhr", function() {
|
|||
var serialize = function(data) {
|
||||
return "id=" + data.id
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"POST /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify({body: request.body})}
|
||||
|
|
@ -175,7 +175,7 @@ o.spec("xhr", function() {
|
|||
var deserialize = function(data) {
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify({test: 123})}
|
||||
|
|
@ -189,7 +189,7 @@ o.spec("xhr", function() {
|
|||
var deserialize = function(data) {
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"POST /item": function(request) {
|
||||
return {status: 200, responseText: JSON.stringify({test: 123})}
|
||||
|
|
@ -203,7 +203,7 @@ o.spec("xhr", function() {
|
|||
var extract = function(data) {
|
||||
return JSON.stringify({test: 123})
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"GET /item": function(request) {
|
||||
return {status: 200, responseText: ""}
|
||||
|
|
@ -217,7 +217,7 @@ o.spec("xhr", function() {
|
|||
var extract = function(data) {
|
||||
return JSON.stringify({test: 123})
|
||||
}
|
||||
|
||||
|
||||
mock.$defineRoutes({
|
||||
"POST /item": function(request) {
|
||||
return {status: 200, responseText: ""}
|
||||
|
|
@ -234,7 +234,7 @@ o.spec("xhr", function() {
|
|||
}
|
||||
})
|
||||
xhr({method: "POST", url: "/item", config: config}).then(done)
|
||||
|
||||
|
||||
function config(xhr) {
|
||||
o(typeof xhr.setRequestHeader).equals("function")
|
||||
o(typeof xhr.open).equals("function")
|
||||
|
|
@ -264,4 +264,4 @@ o.spec("xhr", function() {
|
|||
}).then(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue