Merge remote-tracking branch 'origin/rewrite' into rewrite
This commit is contained in:
commit
11b11caf83
3 changed files with 12 additions and 12 deletions
|
|
@ -32,7 +32,7 @@ Argument | Type | Required | Descript
|
|||
`options.type` | `any = Function(any)` | No | A constructor to be applied to each object in the response. Defaults to the [identity function](https://en.wikipedia.org/wiki/Identity_function).
|
||||
`options.serialize` | `string = Function(any)` | No | A serialization method to be applied to `data`. Defaults to `JSON.stringify`, or if `options.data` is an instance of [`FormData`](https://developer.mozilla.org/en/docs/Web/API/FormData), defaults to the [identity function](https://en.wikipedia.org/wiki/Identity_function) (i.e. `function(value) {return value}`).
|
||||
`options.deserialize` | `any = Function(string)` | No | A deserialization method to be applied to the response. Defaults to a small wrapper around `JSON.parse` that returns `null` for empty responses.
|
||||
`options.extract` | `string = Function(xhr, options)` | No | A hook to specify how the XMLHttpRequest response should be read. Useful for reading response headers and cookies. Defaults to a function that returns `xhr.responseText`. If defined, the `xhr` parameter is the XMLHttpRequest instance used for the request, and `options` is the object that was passed to the `m.request` call. If a custom `extract` callback is set, `options.deserialize` is ignored.
|
||||
`options.extract` | `string = Function(xhr, options)` | No | A hook to specify how the XMLHttpRequest response should be read. Useful for reading response headers and cookies. Defaults to a function that returns `xhr.responseText`. If defined, the `xhr` parameter is the XMLHttpRequest instance used for the request, and `options` is the object that was passed to the `m.request` call. If a custom `extract` callback is set, `options.deserialize` is ignored and the string returned from the extract callback will not be parsed as JSON.
|
||||
`options.useBody` | `Boolean` | No | Force the use of the HTTP body section for `data` in `GET` requests when set to `true`, or the use of querystring for other HTTP methods when set to `false`. Defaults to `false` for `GET` requests and `true` for other methods.
|
||||
**returns** | `Promise` | | A promise that resolves to the response data, after it has been piped through the `extract`, `deserialize` and `type` methods
|
||||
|
||||
|
|
@ -186,7 +186,7 @@ Sometimes, it is desirable to abort a request. For example, in an autocompleter/
|
|||
var searchXHR = null
|
||||
function search() {
|
||||
abortPreviousSearch()
|
||||
|
||||
|
||||
m.request({
|
||||
method: "GET",
|
||||
url: "/api/v1/users",
|
||||
|
|
@ -223,7 +223,7 @@ Next, you need to create a [`FormData`](https://developer.mozilla.org/en/docs/We
|
|||
```javascript
|
||||
function upload(e) {
|
||||
var file = e.target.files[0]
|
||||
|
||||
|
||||
var data = new FormData()
|
||||
data.append("myfile", file)
|
||||
}
|
||||
|
|
@ -234,10 +234,10 @@ Next, you need to call `m.request` and set `options.method` to an HTTP method th
|
|||
```javascript
|
||||
function upload(e) {
|
||||
var file = e.target.files[0]
|
||||
|
||||
|
||||
var data = new FormData()
|
||||
data.append("myfile", file)
|
||||
|
||||
|
||||
m.request({
|
||||
method: "POST",
|
||||
url: "/api/v1/upload",
|
||||
|
|
@ -261,12 +261,12 @@ m.render(document.body, [
|
|||
|
||||
function upload(e) {
|
||||
var files = e.target.files
|
||||
|
||||
|
||||
var data = new FormData()
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
data.append("file" + i, file)
|
||||
}
|
||||
|
||||
|
||||
m.request({
|
||||
method: "POST",
|
||||
url: "/api/v1/upload",
|
||||
|
|
@ -297,10 +297,10 @@ m.mount(document.body, {
|
|||
|
||||
function upload(e) {
|
||||
var file = e.target.files[0]
|
||||
|
||||
|
||||
var data = new FormData()
|
||||
data.append("myfile", file)
|
||||
|
||||
|
||||
m.request({
|
||||
method: "POST",
|
||||
url: "/api/v1/upload",
|
||||
|
|
@ -308,7 +308,7 @@ function upload(e) {
|
|||
config: function(xhr) {
|
||||
xhr.addEventListener("progress", function(e) {
|
||||
progress = e.loaded / e.total
|
||||
|
||||
|
||||
m.redraw() // tell Mithril that data changed and a re-render is needed
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1120,7 +1120,7 @@ m.request = requestService.request
|
|||
m.jsonp = requestService.jsonp
|
||||
m.parseQueryString = parseQueryString
|
||||
m.buildQueryString = buildQueryString
|
||||
m.version = "1.0.0-rc.4"
|
||||
m.version = "1.0.0-rc.5"
|
||||
if (typeof module !== "undefined") module["exports"] = m
|
||||
else window.m = m
|
||||
}
|
||||
2
mithril.min.js
vendored
2
mithril.min.js
vendored
|
|
@ -37,4 +37,4 @@ b("hash");default:return b("pathname").slice(r.length)+b("search")+b("hash")}}fu
|
|||
t;return{setPrefix:function(a){r=a},getPath:l,setPath:h,defineRoutes:function(b,h,f){function n(){var a=l(),k={},m=d(a,k,k),n;for(n in b){var q=new RegExp("^"+n.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(q.test(m)){m.replace(q,function(){for(var d=n.match(/:[^\/]+/g)||[],f=[].slice.call(arguments,1,-2),l=0;l<d.length;l++)k[d[l].replace(/:|\./g,"")]=decodeURIComponent(f[l]);h(b[n],k,a,n)});return}}f(a,k)}m?a.onpopstate=k(n):"#"===r.charAt(0)&&(a.onhashchange=n);n();
|
||||
return n},link:function(a){a.dom.setAttribute("href",r+a.attrs.href);a.dom.onclick=function(a){a.ctrlKey||a.metaKey||a.shiftKey||2===a.which||(a.preventDefault(),a.redraw=!1,a=this.getAttribute("href"),0===a.indexOf(r)&&(a=a.slice(r.length)),h(a,void 0,void 0))}}}};t.route=function(a,b){function k(a){return a}var d=R(a),l,h,t,q,r,x={view:function(){return[t(m(h,null,q,void 0,void 0,void 0))]}},n=function(a,f,m){h="div";t=k;q=null;b(a,x);d.defineRoutes(m,function(b,d,f){var m="function"!==typeof b.view,
|
||||
n=k,p=l=function(k){p===l&&(l=null,h=null!=k?k:m?"div":b,t=n,q=d,r=f,a.redraw(!0))},u=function(){p()};m&&("function"===typeof b.render&&(n=b.render.bind(b)),"function"===typeof b.onmatch&&(u=b.onmatch));u.call(b,p,d,f)},function(){d.setPath(f,null,{replace:!0})})};n.link=d.link;n.prefix=d.setPrefix;n.set=d.setPath;n.get=function(){return r};return n}(window,t.mount);t.withAttr=function(a,b,k){return function(d){return b.call(k||this,a in d.currentTarget?d.currentTarget[a]:d.currentTarget.getAttribute(a))}};
|
||||
t.render=M.render;t.redraw=I.publish;t.request=H.request;t.jsonp=H.jsonp;t.parseQueryString=J;t.buildQueryString=C;t.version="1.0.0-rc.4";"undefined"!==typeof module?module.exports=t:window.m=t};
|
||||
t.render=M.render;t.redraw=I.publish;t.request=H.request;t.jsonp=H.jsonp;t.parseQueryString=J;t.buildQueryString=C;t.version="1.0.0-rc.5";"undefined"!==typeof module?module.exports=t:window.m=t};
|
||||
Loading…
Add table
Add a link
Reference in a new issue