@@ -359,7 +359,7 @@ if (global.localStorage) {
359359 if ( localStorage . getItem ( testKey ) != testKey ) {
360360 throw new Error ( ) ;
361361 }
362- localStorage . remove ( testKey ) ;
362+ localStorage . removeItem ( testKey ) ;
363363 } catch ( e ) {
364364 localStorage = require ( 'localstorage-memory' ) ;
365365 }
@@ -436,11 +436,9 @@ module.exports = function upload(file, AV, saveOptions) {
436436
437437 var xhr = new AV . XMLHttpRequest ( ) ;
438438
439- xhr . upload . addEventListener ( 'progress' , function ( e ) {
440- if ( e . lengthComputable ) {
441- saveOptions . onProgress && saveOptions . onProgress ( e ) ;
442- }
443- } , false ) ;
439+ if ( xhr . upload ) {
440+ xhr . upload . onprogress = saveOptions . onProgress ;
441+ }
444442
445443 xhr . onreadystatechange = function ( ) {
446444 if ( xhr . readyState === 4 ) {
@@ -4184,7 +4182,7 @@ _.extend(Promise, /** @lends AV.Promise */ {
41844182 */
41854183 as : function ( ) {
41864184 var promise = new Promise ( ) ;
4187- if ( _ . isFunction ( arguments [ 0 ] ) ) {
4185+ if ( arguments [ 0 ] && _ . isFunction ( arguments [ 0 ] . then ) ) {
41884186 arguments [ 0 ] . then ( function ( data ) {
41894187 promise . resolve . call ( promise , data ) ;
41904188 } , function ( err ) {
@@ -5860,12 +5858,14 @@ module.exports = function(AV) {
58605858 if ( acl === undefined ) {
58615859 var defaultAcl = new AV . ACL ( ) ;
58625860 defaultAcl . setPublicReadAccess ( true ) ;
5863- acl = defaultAcl ;
5864- }
5865- if ( ! ( acl instanceof AV . ACL ) ) {
5861+ if ( ! this . getACL ( ) ) {
5862+ this . setACL ( defaultAcl ) ;
5863+ }
5864+ } else if ( ! ( acl instanceof AV . ACL ) ) {
58665865 throw new TypeError ( 'acl must be an instance of AV.ACL' ) ;
5866+ } else {
5867+ this . setACL ( acl ) ;
58675868 }
5868- this . setACL ( acl ) ;
58695869 } ,
58705870
58715871 /**
@@ -6157,6 +6157,26 @@ module.exports = function(AV) {
61576157 return json ;
61586158 } ,
61596159
6160+ /**
6161+ * Returns true when there are more documents can be retrieved by this
6162+ * query instance, you can call find function to get more results.
6163+ * @see AV.SearchQuery#find
6164+ * @return {Boolean }
6165+ */
6166+ hasMore : function ( ) {
6167+ return ! this . _hitEnd ;
6168+ } ,
6169+
6170+ /**
6171+ * Reset current query instance state(such as sid, hits etc) except params
6172+ * for a new searching. After resetting, hasMore() will return true.
6173+ */
6174+ reset : function ( ) {
6175+ this . _hitEnd = false ;
6176+ this . _sid = null ;
6177+ this . _hits = 0 ;
6178+ } ,
6179+
61606180 /**
61616181 * Retrieves a list of AVObjects that satisfy this query.
61626182 * Either options.success or options.error is called when the find
@@ -6177,6 +6197,9 @@ module.exports = function(AV) {
61776197 if ( response . sid ) {
61786198 self . _oldSid = self . _sid ;
61796199 self . _sid = response . sid ;
6200+ } else {
6201+ self . _sid = null ;
6202+ self . _hitEnd = true ;
61806203 }
61816204 self . _hits = response . hits || 0 ;
61826205
@@ -6727,17 +6750,12 @@ module.exports = function(AV) {
67276750 var authData = this . get ( 'authData' ) || { } ;
67286751 authData [ authType ] = options . authData ;
67296752 this . set ( 'authData' , authData ) ;
6730-
6731- // Overridden so that the user can be made the current user.
6732- var newOptions = _ . clone ( options ) || { } ;
6733- newOptions . success = function ( model ) {
6734- model . _handleSaveResult ( true ) . then ( function ( ) {
6735- if ( options . success ) {
6736- options . success . apply ( this , arguments ) ;
6737- }
6738- } ) ;
6739- } ;
6740- return this . save ( { 'authData' : authData } , newOptions ) ;
6753+ return this . save ( { 'authData' : authData } , filterOutCallbacks ( options ) )
6754+ . then ( function ( model ) {
6755+ return model . _handleSaveResult ( true ) . then ( function ( ) {
6756+ return model ;
6757+ } ) ;
6758+ } ) . _thenRunCallbacks ( options ) ;
67416759 } else {
67426760 var self = this ;
67436761 var promise = new AV . Promise ( ) ;
@@ -6871,7 +6889,7 @@ module.exports = function(AV) {
68716889 return AV . Promise . error ( error ) ;
68726890 }
68736891
6874- return this . save ( attrs ) . then ( function ( model ) {
6892+ return this . save ( attrs , filterOutCallbacks ( options ) ) . then ( function ( model ) {
68756893 return model . _handleSaveResult ( true ) . then ( function ( ) {
68766894 return model ;
68776895 } ) ;
@@ -6925,21 +6943,17 @@ module.exports = function(AV) {
69256943 return AV . Promise . error ( error ) ;
69266944 }
69276945
6928- // Overridden so that the user can be made the current user.
6929- var newOptions = _ . clone ( options ) ;
6946+ var newOptions = filterOutCallbacks ( options ) ;
69306947 newOptions . _makeRequest = function ( route , className , id , method , json ) {
69316948 return AV . _request ( 'usersByMobilePhone' , null , null , "POST" , json ) ;
69326949 } ;
6933- newOptions . success = function ( model ) {
6934- model . _handleSaveResult ( true ) . then ( function ( ) {
6935- delete model . attributes . smsCode ;
6936- delete model . _serverData . smsCode ;
6937- if ( options . success ) {
6938- options . success . apply ( this , arguments ) ;
6939- }
6950+ return this . save ( attrs , newOptions ) . then ( function ( model ) {
6951+ delete model . attributes . smsCode ;
6952+ delete model . _serverData . smsCode ;
6953+ return model . _handleSaveResult ( true ) . then ( function ( ) {
6954+ return model ;
69406955 } ) ;
6941- } ;
6942- return this . save ( attrs , newOptions ) ;
6956+ } ) . _thenRunCallbacks ( options ) ;
69436957 } ,
69446958
69456959 /**
@@ -6985,15 +6999,13 @@ module.exports = function(AV) {
69856999 }
69867000 options = options || { } ;
69877001
6988- var newOptions = _ . clone ( options ) ;
6989- newOptions . success = function ( model ) {
6990- model . _handleSaveResult ( false ) . then ( function ( ) {
6991- if ( options . success ) {
6992- options . success . apply ( this , arguments ) ;
6993- }
6994- } ) ;
6995- } ;
6996- return AV . Object . prototype . save . call ( this , attrs , newOptions ) ;
7002+ return AV . Object . prototype . save
7003+ . call ( this , attrs , filterOutCallbacks ( options ) )
7004+ . then ( function ( model ) {
7005+ return model . _handleSaveResult ( false ) . then ( function ( ) {
7006+ return model ;
7007+ } ) ;
7008+ } ) . _thenRunCallbacks ( options ) ;
69977009 } ,
69987010
69997011 /**
@@ -7066,15 +7078,12 @@ module.exports = function(AV) {
70667078 * @see AV.Object#fetch
70677079 */
70687080 fetch : function ( options ) {
7069- var newOptions = options ? _ . clone ( options ) : { } ;
7070- newOptions . success = function ( model ) {
7071- model . _handleSaveResult ( false ) . then ( function ( ) {
7072- if ( options && options . success ) {
7073- options . success . apply ( this , arguments ) ;
7074- }
7075- } ) ;
7076- } ;
7077- return AV . Object . prototype . fetch . call ( this , newOptions ) ;
7081+ return AV . Object . prototype . fetch . call ( this , filterOutCallbacks ( options ) )
7082+ . then ( function ( model ) {
7083+ return model . _handleSaveResult ( false ) . then ( function ( ) {
7084+ return model ;
7085+ } ) ;
7086+ } ) . _thenRunCallbacks ( options ) ;
70787087 } ,
70797088
70807089 /**
@@ -7652,6 +7661,13 @@ module.exports = function(AV) {
76527661 } ) ;
76537662} ;
76547663
7664+ function filterOutCallbacks ( options ) {
7665+ var newOptions = _ . clone ( options ) || { } ;
7666+ delete newOptions . success ;
7667+ delete newOptions . error ;
7668+ return newOptions ;
7669+ }
7670+
76557671} , { "underscore" :30 } ] , 25 :[ function ( require , module , exports ) {
76567672( function ( process ) {
76577673'use strict' ;
@@ -8071,14 +8087,14 @@ module.exports = function(AV) {
80718087 dataObject . _MasterKey = AV . masterKey ;
80728088 dataObject . _ClientVersion = AV . VERSION ;
80738089 // Pass the session token on every request.
8074- var currentUser = AV . User . current ( ) ;
8075- if ( currentUser && currentUser . _sessionToken ) {
8076- dataObject . _SessionToken = currentUser . _sessionToken ;
8077- }
8078-
8079- return AV . _getInstallationId ( ) . then ( function ( _InstallationId ) {
8090+ return AV . User . currentAsync ( ) . then ( function ( currentUser ) {
8091+ if ( currentUser && currentUser . _sessionToken ) {
8092+ dataObject . _SessionToken = currentUser . _sessionToken ;
8093+ }
8094+ return AV . _getInstallationId ( ) ;
8095+ } ) . then ( function ( _InstallationId ) {
80808096 dataObject . _InstallationId = _InstallationId ;
8081- } ) . then ( function ( ) {
8097+
80828098 var data = JSON . stringify ( dataObject ) ;
80838099 return AV . _ajax ( method , url , data ) . then ( null , function ( response ) {
80848100 // Transform the error into an instance of AV.Error by trying to parse
@@ -8335,7 +8351,7 @@ module.exports = function(AV) {
83358351} , { "_process" :28 , "underscore" :30 } ] , 26 :[ function ( require , module , exports ) {
83368352'use strict' ;
83378353
8338- module . exports = "js1.0.0-rc2 " ;
8354+ module . exports = "js1.0.0-rc3 " ;
83398355
83408356} , { } ] , 27 :[ function ( require , module , exports ) {
83418357
0 commit comments