@@ -5,29 +5,27 @@ function shareFirst(path) {
55 path . match ( / ^ \/ p u b l i c \/ .* [ ^ \/ ] $ / ) ) ;
66}
77
8- function maxAgeInvalid ( maxAge ) {
9- return maxAge !== false && typeof ( maxAge ) !== 'number' ;
8+ function defaultMaxAge ( context ) {
9+ if ( ( typeof context . remote === 'object' ) &&
10+ context . remote . connected && context . remote . online ) {
11+ return 2 * context . getSyncInterval ( ) ;
12+ } else {
13+ log ( 'Not setting default maxAge, because remote is offline or not connected' ) ;
14+ return false ;
15+ }
1016}
1117
1218var SyncedGetPutDelete = {
1319 get : function ( path , maxAge ) {
14- if ( this . local ) {
15- if ( maxAge === undefined ) {
16- if ( ( typeof this . remote === 'object' ) &&
17- this . remote . connected && this . remote . online ) {
18- maxAge = 2 * this . getSyncInterval ( ) ;
19- } else {
20- log ( 'Not setting default maxAge, because remote is offline or not connected' ) ;
21- maxAge = false ;
22- }
23- }
24-
25- if ( maxAgeInvalid ( maxAge ) ) {
26- return Promise . reject ( 'Argument \'maxAge\' must be false or a number' ) ;
20+ if ( ! this . local ) {
21+ return this . remote . get ( path ) ;
22+ } else {
23+ if ( typeof maxAge === 'undefined' ) {
24+ maxAge = defaultMaxAge ( this ) ;
25+ } else if ( typeof maxAge !== 'number' && maxAge !== false ) {
26+ return Promise . reject ( `Argument 'maxAge' must be 'false' or a number` ) ;
2727 }
2828 return this . local . get ( path , maxAge , this . sync . queueGetRequest . bind ( this . sync ) ) ;
29- } else {
30- return this . remote . get ( path ) ;
3129 }
3230 } ,
3331
0 commit comments