Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: E6 destructuring for resolving promise #39

Open
pYr0x opened this issue Jun 9, 2018 · 4 comments
Open

RFC: E6 destructuring for resolving promise #39

pYr0x opened this issue Jun 9, 2018 · 4 comments

Comments

@pYr0x
Copy link
Contributor

pYr0x commented Jun 9, 2018

i would like to unify the response of the XHR response.
the idea is to response a array while resolving or rejecting.
i came up with this:

xhr.onreadystatechange = function () {
		try {
			if (xhr.readyState === 4) {
				if (timer) {
					clearTimeout(timer);
				}
				if (xhr.status < 300) {
					if (o.success) {
						o.success(_xhrResp(xhr, o), xhr.statusText, xhr);
					}
				}
				else if (o.error) {
					o.error(_xhrResp(xhr, o), xhr.statusText, xhr);
				}
				if (o.complete) {
					o.complete(_xhrResp(xhr, o), xhr.statusText, xhr);
				}

				if (xhr.status >= 200 && xhr.status < 300) {
					deferred.resolve([_xhrResp(xhr, o), xhr.statusText, xhr]);
				} else {
					deferred.reject([_xhrResp(xhr, o), xhr.statusText, xhr]);
				}
			}
			else if (o.progress) {
				o.progress(++n);
			}
		} catch(e) {
			deferred.reject(e);
		}
	};

deferred.resolve([_xhrResp(xhr, o), xhr.statusText, xhr]); will return an array which can be
destructured

ajax({
			type: "get",
			url: __dirname+"/can-ajax-test-result.json"
		}).then(function([resp, textStatus, xhr]){
			assert.equal(textStatus, "OK");
			done();
		});

this change will break all tests and all implementations
this change will only work in Edge. Not on IE11

any thoughts?

@justinbmeyer
Copy link
Contributor

Could this be behind a flag so as not to break existing apps?

@justinbmeyer
Copy link
Contributor

Why wouldn’t this work in IE?

@pYr0x
Copy link
Contributor Author

pYr0x commented Jun 9, 2018

destructuring is not working on IE
https://kangax.github.io/compat-table/es6/

@justinbmeyer
Copy link
Contributor

justinbmeyer commented Jun 9, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants