Location: In person, Chicago jQCon
Attending: DaveMethvin, markelog, gibson042, m_gol
link Versioning
- If we are going npm we should obey semantic versioning
- The .then() change will be breaking
- Might as well remove other things like .andSelf()
- New versioning
- 1.x now jquery-legacy-3.x
- 2.x now jquery 3.x
link Deferred pull request for Promise/A compat on .then()
- Comments on the PR
- A branch with tests applied:
- https://github.com/jquery/jquery/tree/standard-then-tests (run
grunt promises-aplus-tests
)
- https://github.com/jquery/jquery/tree/standard-then-tests (run
link xhr
Design goal: allow standalone usage
Simple xhr module in a wrapper
12345678910jQuery.xhr = require("jquery-xhr");
jQuery.xhr.Promise = window.Promise || function( executor ) {
var dfd = jQuery.Deferred();
try {
executor( dfd.resolve, dfd.reject );
} catch ( ex ) {
dfd.reject( ex );
}
return dfd.promise();
};
Simple case:
jQuery.xhr( url, options ).then( handlerA ).then( handlerB )
beforeSend case:
1
2
3
4
5
|
|
- Super-advanced case:123456
xhr = jQuery.xhr( url, { autosend: false } );
xhr.then( handlerA );
if ( badFeeling(xhr.getNative()) ) { xhr.abort(); }
xhr.send( body ).then( handlerB );
Promise.resolve( xhr ).then( … )
jQuery.xhr( url ).send({ ... }), jQuery.xhr( url )
- Does an unsent Promise that has mutability violate the Promise/A+ spec? Or does the mutability only apply to the resolution? No. Does not appear to apply to the returned promise, which can be augmented, only to the resolved value of the promise
- options necessary to functionality: method, user, pass, body, query (RFC), beforeSend
- options nice to keep: cache, ifModified, headers
- jxrPromise: .abort(), .xhr property
- Rejects on: Exception, timeout, abort
- what about 4xx/5xx? or a 0 (network error)
- implied success:
jQuery.xhr( url ).then( jQuery.xhr.rejectHTTPError )
- implied failure:
jQuery.xhr( url ).catch( jQuery.xhr.ifResponse )
- implied success:
- Resolved value: raw native xhr
- Rejected value: Error object, potentially with .xhr property, .options object