@@ -1887,7 +1887,7 @@ var Client = function Client(url, options) {
18871887 this . _messageCallbacks [ C . TOPIC . ERROR ] = this . _onErrorMessage . bind ( this ) ;
18881888} ;
18891889
1890- Emitter ( Client . prototype ) ;
1890+ Emitter ( Client . prototype ) ; // eslint-disable-line
18911891
18921892/**
18931893 * Send authentication parameters to the client to fully open
@@ -2244,14 +2244,6 @@ module.exports = {
22442244 */
22452245 heartbeatInterval : 30000 ,
22462246
2247- /**
2248- * @param {Boolean } recordPersistDefault Whether records should be
2249- * persisted by default. Can be overwritten
2250- * for individual records when calling
2251- * getRecord( name, persist );
2252- */
2253- recordPersistDefault : true ,
2254-
22552247 /**
22562248 * @param {Number } reconnectIntervalIncrement Specifies the number of milliseconds by
22572249 * which the time until the next reconnection
@@ -3544,6 +3536,7 @@ module.exports = PresenceHandler;
35443536
35453537} , { "../constants/constants" :11 , "../utils/resubscribe-notifier" :29 , "component-emitter2" :1 } ] , 19 :[ function ( _dereq_ , module , exports ) {
35463538'use strict' ;
3539+ /* eslint-disable prefer-rest-params, prefer-spread */
35473540
35483541var Record = _dereq_ ( './record' ) ;
35493542var EventEmitter = _dereq_ ( 'component-emitter2' ) ;
@@ -3574,7 +3567,7 @@ var AnonymousRecord = function AnonymousRecord(recordHandler) {
35743567 this . _proxyMethod ( 'discard' ) ;
35753568} ;
35763569
3577- EventEmitter ( AnonymousRecord . prototype ) ;
3570+ EventEmitter ( AnonymousRecord . prototype ) ; // eslint-disable-line
35783571
35793572/**
35803573 * Proxies the actual record's get method. It is valid
@@ -3660,6 +3653,10 @@ AnonymousRecord.prototype.unsubscribe = function () {
36603653 * @returns {void }
36613654 */
36623655AnonymousRecord . prototype . setName = function ( recordName ) {
3656+ if ( this . name === recordName ) {
3657+ return ;
3658+ }
3659+
36633660 this . name = recordName ;
36643661
36653662 var i = void 0 ;
@@ -3739,18 +3736,18 @@ var cache = Object.create(null);
37393736 */
37403737module . exports . get = function ( data , path , deepCopy ) {
37413738 var tokens = tokenize ( path ) ;
3742-
3739+ var value = data ;
37433740 for ( var i = 0 ; i < tokens . length ; i ++ ) {
3744- if ( data === undefined ) {
3741+ if ( value === undefined ) {
37453742 return undefined ;
37463743 }
3747- if ( ( typeof data === 'undefined' ? 'undefined' : _typeof ( data ) ) !== 'object' ) {
3744+ if ( ( typeof value === 'undefined' ? 'undefined' : _typeof ( value ) ) !== 'object' ) {
37483745 throw new Error ( 'invalid data or path' ) ;
37493746 }
3750- data = data [ tokens [ i ] ] ;
3747+ value = value [ tokens [ i ] ] ;
37513748 }
37523749
3753- return deepCopy !== false ? utils . deepCopy ( data ) : data ;
3750+ return deepCopy !== false ? utils . deepCopy ( value ) : value ;
37543751} ;
37553752
37563753/**
@@ -3873,6 +3870,7 @@ function tokenize(path) {
38733870
38743871} , { "../utils/utils" :31 } ] , 21 :[ function ( _dereq_ , module , exports ) {
38753872'use strict' ;
3873+ /* eslint-disable prefer-rest-params */
38763874
38773875var EventEmitter = _dereq_ ( 'component-emitter2' ) ;
38783876var Record = _dereq_ ( './record' ) ;
@@ -3919,7 +3917,7 @@ var List = function List(recordHandler, name, options) {
39193917 this . whenReady = this . _record . whenReady . bind ( this ) ;
39203918} ;
39213919
3922- EventEmitter ( List . prototype ) ;
3920+ EventEmitter ( List . prototype ) ; // eslint-disable-line
39233921
39243922/**
39253923 * Returns the array of list entries or an
@@ -4575,7 +4573,7 @@ RecordHandler.prototype._onRecordError = function (recordName, error) {
45754573 */
45764574RecordHandler . prototype . _onDestroyPending = function ( recordName ) {
45774575 if ( ! this . _records [ recordName ] ) {
4578- this . emit ( 'error' , 'Record \'' + recordName + '\' does not exists') ;
4576+ this . _client . _$onError ( C . TOPIC . RECORD , 'Record attempted to be destroyed but does not exists' , recordName ) ;
45794577 return ;
45804578 }
45814579 var onMessage = this . _records [ recordName ] . _$onMessage . bind ( this . _records [ recordName ] ) ;
@@ -4600,6 +4598,7 @@ module.exports = RecordHandler;
46004598
46014599} , { "../constants/constants" :11 , "../message/message-parser" :17 , "../utils/listener" :28 , "../utils/single-notifier" :30 , "./anonymous-record" :19 , "./list" :21 , "./record" :23 , "component-emitter2" :1 } ] , 23 :[ function ( _dereq_ , module , exports ) {
46024600'use strict' ;
4601+ /* eslint-disable prefer-spread, prefer-rest-params */
46034602
46044603var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ;
46054604
@@ -4669,7 +4668,7 @@ var Record = function Record(name, recordOptions, connection, options, client) {
46694668 this . _sendRead ( ) ;
46704669} ;
46714670
4672- EventEmitter ( Record . prototype ) ;
4671+ EventEmitter ( Record . prototype ) ; // eslint-disable-line
46734672
46744673/**
46754674 * Set a merge strategy to resolve any merge conflicts that may occur due
@@ -4726,9 +4725,8 @@ Record.prototype.get = function (path) {
47264725Record . prototype . set = function ( pathOrData , dataOrCallback , callback ) {
47274726 var path = void 0 ;
47284727 var data = void 0 ;
4729-
4730- // set( object )
47314728 if ( arguments . length === 1 ) {
4729+ // set( object )
47324730 if ( ( typeof pathOrData === 'undefined' ? 'undefined' : _typeof ( pathOrData ) ) !== 'object' ) {
47334731 throw new Error ( 'invalid argument data' ) ;
47344732 }
@@ -4741,7 +4739,7 @@ Record.prototype.set = function (pathOrData, dataOrCallback, callback) {
47414739 } else if ( ( typeof pathOrData === 'undefined' ? 'undefined' : _typeof ( pathOrData ) ) === 'object' && typeof dataOrCallback === 'function' ) {
47424740 // set( data, callback )
47434741 data = pathOrData ;
4744- callback = dataOrCallback ;
4742+ callback = dataOrCallback ; // eslint-disable-line
47454743 } else {
47464744 throw new Error ( 'invalid argument path' ) ;
47474745 }
@@ -4771,17 +4769,28 @@ Record.prototype.set = function (pathOrData, dataOrCallback, callback) {
47714769 var newValue = jsonPath . set ( oldValue , path , data , this . _options . recordDeepCopy ) ;
47724770
47734771 if ( oldValue === newValue ) {
4772+ if ( typeof callback === 'function' ) {
4773+ var errorMessage = null ;
4774+ if ( ! utils . isConnected ( this . _client ) ) {
4775+ errorMessage = 'Connection error: error updating record as connection was closed' ;
4776+ }
4777+ utils . requestIdleCallback ( function ( ) {
4778+ return callback ( errorMessage ) ;
4779+ } ) ;
4780+ }
47744781 return this ;
47754782 }
47764783
47774784 var config = void 0 ;
4778- if ( callback !== undefined ) {
4785+ if ( typeof callback === 'function' ) {
47794786 config = { } ;
47804787 config . writeSuccess = true ;
4781- this . _setUpCallback ( this . version , callback ) ;
4782- var connectionState = this . _client . getConnectionState ( ) ;
4783- if ( connectionState === C . CONNECTION_STATE . CLOSED || connectionState === C . CONNECTION_STATE . RECONNECTING ) {
4784- callback ( 'Connection error: error updating record as connection was closed' ) ;
4788+ if ( ! utils . isConnected ( this . _client ) ) {
4789+ utils . requestIdleCallback ( function ( ) {
4790+ return callback ( 'Connection error: error updating record as connection was closed' ) ;
4791+ } ) ;
4792+ } else {
4793+ this . _setUpCallback ( this . version , callback ) ;
47854794 }
47864795 }
47874796 this . _sendUpdate ( path , data , config ) ;
@@ -4808,6 +4817,7 @@ Record.prototype.set = function (pathOrData, dataOrCallback, callback) {
48084817 * @public
48094818 * @returns {void }
48104819 */
4820+ // eslint-disable-next-line
48114821Record . prototype . subscribe = function ( path , callback , triggerNow ) {
48124822 var _this = this ;
48134823
@@ -4852,6 +4862,7 @@ Record.prototype.subscribe = function (path, callback, triggerNow) {
48524862 * @public
48534863 * @returns {void }
48544864 */
4865+ // eslint-disable-next-line
48554866Record . prototype . unsubscribe = function ( pathOrCallback , callback ) {
48564867 var args = this . _normalizeArguments ( arguments ) ;
48574868
@@ -5775,7 +5786,7 @@ var AckTimeoutRegistry = function AckTimeoutRegistry(client, options) {
57755786 client . on ( 'connectionStateChanged' , this . _onConnectionStateChanged . bind ( this ) ) ;
57765787} ;
57775788
5778- EventEmitter ( AckTimeoutRegistry . prototype ) ;
5789+ EventEmitter ( AckTimeoutRegistry . prototype ) ; // eslint-disable-line
57795790
57805791/**
57815792 * Add an entry
@@ -6213,16 +6224,18 @@ module.exports = SingleNotifier;
62136224} , { "../constants/constants" :11 , "./resubscribe-notifier" :29 } ] , 31 :[ function ( _dereq_ , module , exports ) {
62146225( function ( process ) {
62156226'use strict' ;
6227+ /* eslint-disable valid-typeof */
6228+
6229+ var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ;
6230+
6231+ var C = _dereq_ ( '../constants/constants' ) ;
62166232
62176233/**
62186234 * A regular expression that matches whitespace on either side, but
62196235 * not in the center of a string
62206236 *
62216237 * @type {RegExp }
62226238 */
6223-
6224- var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ;
6225-
62266239var TRIM_REGULAR_EXPRESSION = / ^ [ \s \uFEFF \xA0 ] + | [ \s \uFEFF \xA0 ] + $ / g;
62276240
62286241/**
@@ -6388,6 +6401,32 @@ exports.setInterval = function (callback, intervalDuration) {
63886401 return - 1 ;
63896402} ;
63906403
6404+ /**
6405+ * This method is used to break up long running operations and run a callback function immediately
6406+ * after the browser has completed other operations such as events and display updates.
6407+ *
6408+ * @param {Function } callback the function that will be called after the given time
6409+ * @param {...* } param1, ..., paramN additional parameters which are passed through to the
6410+ * callback
6411+ *
6412+ * @public
6413+ */
6414+ exports . requestIdleCallback = ! exports . isNode && window . requestIdleCallback && window . requestIdleCallback . bind ( window ) || function ( cb ) {
6415+ var start = Date . now ( ) ;
6416+ return setTimeout ( function ( ) {
6417+ cb ( {
6418+ didTimeout : false ,
6419+ timeRemaining : function timeRemaining ( ) {
6420+ return Math . max ( 0 , 50 - ( Date . now ( ) - start ) ) ;
6421+ }
6422+ } ) ;
6423+ } , 1 ) ;
6424+ } ;
6425+
6426+ exports . cancelIdleCallback = ! exports . isNode && window . cancelIdleCallback && window . cancelIdleCallback . bind ( window ) || function ( id ) {
6427+ clearTimeout ( id ) ;
6428+ } ;
6429+
63916430/**
63926431 * Used to see if a protocol is specified within the url
63936432 * @type {RegExp }
@@ -6427,6 +6466,15 @@ exports.parseUrl = function (initialURl, defaultPath) {
64276466 return URL . format ( serverUrl ) ;
64286467} ;
64296468
6469+ /**
6470+ * Returns true is the connection state is OPEN
6471+ * @return {Boolean }
6472+ */
6473+ exports . isConnected = function ( client ) {
6474+ var connectionState = client . getConnectionState ( ) ;
6475+ return connectionState === C . CONNECTION_STATE . OPEN ;
6476+ } ;
6477+
64306478} ) . call ( this , _dereq_ ( '_process' ) )
6431- } , { "_process" :3 , "url" :8 } ] } , { } , [ 10 ] ) ( 10 )
6479+ } , { "../constants/constants" : 11 , " _process" :3 , "url" :8 } ] } , { } , [ 10 ] ) ( 10 )
64326480} ) ;
0 commit comments