@@ -15,7 +15,6 @@ import decode from './decode';
15
15
import encode from './encode' ;
16
16
import equals from './equals' ;
17
17
import escape from './escape' ;
18
- import * as ObjectState from './ObjectState' ;
19
18
import ParseACL from './ParseACL' ;
20
19
import parseDate from './parseDate' ;
21
20
import ParseError from './ParseError' ;
@@ -34,6 +33,7 @@ import {
34
33
import ParsePromise from './ParsePromise' ;
35
34
import ParseQuery from './ParseQuery' ;
36
35
import ParseRelation from './ParseRelation' ;
36
+ import * as SingleInstanceState from './SingleInstanceState' ;
37
37
import unique from './unique' ;
38
38
import unsavedChildren from './unsavedChildren' ;
39
39
@@ -131,9 +131,11 @@ export default class ParseObject {
131
131
/** Prototype getters / setters **/
132
132
133
133
get attributes ( ) : AttributeMap {
134
- return Object . freeze (
135
- ObjectState . estimateAttributes ( this . className , this . _getStateIdentifier ( ) )
136
- ) ;
134
+ let attributes = singleInstance ?
135
+ SingleInstanceState . estimateAttributes ( this . className , this . _getStateIdentifier ( ) ) :
136
+ null ;
137
+ // TODO: implement uniqueInstanceState
138
+ return Object . freeze ( attributes ) ;
137
139
}
138
140
139
141
/**
@@ -187,7 +189,11 @@ export default class ParseObject {
187
189
}
188
190
189
191
_getServerData ( ) : AttributeMap {
190
- return ObjectState . getServerData ( this . className , this . _getStateIdentifier ( ) ) ;
192
+ if ( singleInstance ) {
193
+ return SingleInstanceState . getServerData ( this . className , this . _getStateIdentifier ( ) ) ;
194
+ } else {
195
+ // TODO: implement uniqueInstanceState
196
+ }
191
197
}
192
198
193
199
_clearServerData ( ) {
@@ -196,11 +202,19 @@ export default class ParseObject {
196
202
for ( var attr in serverData ) {
197
203
unset [ attr ] = undefined ;
198
204
}
199
- ObjectState . setServerData ( this . className , this . _getStateIdentifier ( ) , unset ) ;
205
+ if ( singleInstance ) {
206
+ SingleInstanceState . setServerData ( this . className , this . _getStateIdentifier ( ) , unset ) ;
207
+ } else {
208
+ // TODO: implement uniqueInstanceState
209
+ }
200
210
}
201
211
202
212
_getPendingOps ( ) : Array < OpsMap > {
203
- return ObjectState . getPendingOps ( this . className , this . _getStateIdentifier ( ) ) ;
213
+ if ( singleInstance ) {
214
+ return SingleInstanceState . getPendingOps ( this . className , this . _getStateIdentifier ( ) ) ;
215
+ } else {
216
+ // TODO: implement uniqueInstanceState
217
+ }
204
218
}
205
219
206
220
_clearPendingOps ( ) {
@@ -214,7 +228,10 @@ export default class ParseObject {
214
228
215
229
_getDirtyObjectAttributes ( ) : AttributeMap {
216
230
var attributes = this . attributes ;
217
- var objectCache = ObjectState . getObjectCache ( this . className , this . _getStateIdentifier ( ) ) ;
231
+ var objectCache = singleInstance ?
232
+ SingleInstanceState . getObjectCache ( this . className , this . _getStateIdentifier ( ) ) :
233
+ { } ;
234
+ // TODO: implement uniqueInstanceState
218
235
var dirty = { } ;
219
236
for ( var attr in attributes ) {
220
237
var val = attributes [ attr ] ;
@@ -283,7 +300,11 @@ export default class ParseObject {
283
300
if ( ! this . id && serverData . objectId ) {
284
301
this . id = serverData . objectId ;
285
302
}
286
- ObjectState . initializeState ( this . className , this . _getStateIdentifier ( ) ) ;
303
+ if ( singleInstance ) {
304
+ SingleInstanceState . initializeState ( this . className , this . _getStateIdentifier ( ) ) ;
305
+ } else {
306
+ // TODO: implement uniqueInstanceState
307
+ }
287
308
var decoded = { } ;
288
309
for ( var attr in serverData ) {
289
310
if ( attr === 'ACL' ) {
@@ -304,31 +325,41 @@ export default class ParseObject {
304
325
if ( ! decoded . updatedAt && decoded . createdAt ) {
305
326
decoded . updatedAt = decoded . createdAt ;
306
327
}
307
- ObjectState . commitServerChanges ( this . className , this . _getStateIdentifier ( ) , decoded ) ;
328
+ if ( singleInstance ) {
329
+ SingleInstanceState . commitServerChanges ( this . className , this . _getStateIdentifier ( ) , decoded ) ;
330
+ } else {
331
+ // TODO: implement uniqueInstanceState
332
+ }
308
333
}
309
334
310
335
_setExisted ( existed : boolean ) {
311
- var state = ObjectState . getState ( this . className , this . _getStateIdentifier ( ) ) ;
336
+ let state = singleInstance ?
337
+ SingleInstanceState . getState ( this . className , this . _getStateIdentifier ( ) ) :
338
+ null ;
339
+ // TODO: implement uniqueInstanceState
312
340
if ( state ) {
313
341
state . existed = existed ;
314
342
}
315
343
}
316
344
317
345
_migrateId ( serverId : string ) {
318
346
if ( this . _localId && serverId ) {
319
- var oldState = ObjectState . removeState ( this . className , this . _getStateIdentifier ( ) ) ;
347
+ var oldState = SingleInstanceState . removeState ( this . className , this . _getStateIdentifier ( ) ) ;
320
348
this . id = serverId ;
321
349
delete this . _localId ;
322
350
if ( oldState ) {
323
- ObjectState . initializeState ( this . className , this . _getStateIdentifier ( ) , oldState ) ;
351
+ SingleInstanceState . initializeState ( this . className , this . _getStateIdentifier ( ) , oldState ) ;
324
352
}
325
353
}
326
354
}
327
355
328
356
_handleSaveResponse ( response , status : number ) {
329
357
var changes = { } ;
330
358
var attr ;
331
- var pending = ObjectState . popPendingState ( this . className , this . _getStateIdentifier ( ) ) ;
359
+ var pending = singleInstance ?
360
+ SingleInstanceState . popPendingState ( this . className , this . _getStateIdentifier ( ) ) :
361
+ null ;
362
+ // TODO: implement uniqueInstanceState
332
363
for ( attr in pending ) {
333
364
if ( pending [ attr ] instanceof RelationOp ) {
334
365
changes [ attr ] = pending [ attr ] . applyTo ( undefined , this , attr ) ;
@@ -357,12 +388,20 @@ export default class ParseObject {
357
388
this . _setExisted ( true ) ;
358
389
}
359
390
360
- ObjectState . commitServerChanges ( this . className , this . _getStateIdentifier ( ) , changes ) ;
391
+ if ( singleInstance ) {
392
+ SingleInstanceState . commitServerChanges ( this . className , this . _getStateIdentifier ( ) , changes ) ;
393
+ } else {
394
+ // TODO: implement uniqueInstanceState
395
+ }
361
396
}
362
397
363
398
_handleSaveError ( ) {
364
399
var pending = this . _getPendingOps ( ) ;
365
- ObjectState . mergeFirstPendingState ( this . className , this . _getStateIdentifier ( ) ) ;
400
+ if ( singleInstance ) {
401
+ SingleInstanceState . mergeFirstPendingState ( this . className , this . _getStateIdentifier ( ) ) ;
402
+ } else {
403
+ // TODO: implement uniqueInstanceState
404
+ }
366
405
}
367
406
368
407
/** Public methods **/
@@ -651,7 +690,11 @@ export default class ParseObject {
651
690
var last = pendingOps . length - 1 ;
652
691
for ( var attr in newOps ) {
653
692
var nextOp = newOps [ attr ] . mergeWith ( pendingOps [ last ] [ attr ] ) ;
654
- ObjectState . setPendingOp ( this . className , this . _getStateIdentifier ( ) , attr , nextOp ) ;
693
+ if ( singleInstance ) {
694
+ SingleInstanceState . setPendingOp ( this . className , this . _getStateIdentifier ( ) , attr , nextOp ) ;
695
+ } else {
696
+ // TODO: implement uniqueInstanceState
697
+ }
655
698
}
656
699
657
700
return this ;
@@ -778,7 +821,10 @@ export default class ParseObject {
778
821
if ( ! this . id ) {
779
822
return false ;
780
823
}
781
- var state = ObjectState . getState ( this . className , this . _getStateIdentifier ( ) ) ;
824
+ var state = singleInstance ?
825
+ SingleInstanceState . getState ( this . className , this . _getStateIdentifier ( ) ) :
826
+ null ;
827
+ // TODO: implement uniqueInstanceState
782
828
if ( state ) {
783
829
return state . existed ;
784
830
}
@@ -1046,7 +1092,11 @@ export default class ParseObject {
1046
1092
/** Static methods **/
1047
1093
1048
1094
static _clearAllState ( ) {
1049
- ObjectState . _clearAllState ( ) ;
1095
+ if ( singleInstance ) {
1096
+ SingleInstanceState . _clearAllState ( ) ;
1097
+ } else {
1098
+ // TODO: implement uniqueInstanceState
1099
+ }
1050
1100
}
1051
1101
1052
1102
/**
@@ -1699,8 +1749,12 @@ var DefaultController = {
1699
1749
}
1700
1750
} ) ;
1701
1751
} ;
1702
- ObjectState . pushPendingState ( obj . className , obj . _getStateIdentifier ( ) ) ;
1703
- batchTasks . push ( ObjectState . enqueueTask ( obj . className , obj . _getStateIdentifier ( ) , task ) ) ;
1752
+ if ( singleInstance ) {
1753
+ SingleInstanceState . pushPendingState ( obj . className , obj . _getStateIdentifier ( ) ) ;
1754
+ batchTasks . push ( SingleInstanceState . enqueueTask ( obj . className , obj . _getStateIdentifier ( ) , task ) ) ;
1755
+ } else {
1756
+ // TODO: implement uniqueInstanceState
1757
+ }
1704
1758
} ) ;
1705
1759
1706
1760
ParsePromise . when ( batchReady ) . then ( ( ) => {
@@ -1742,8 +1796,15 @@ var DefaultController = {
1742
1796
return ParsePromise . error ( error ) ;
1743
1797
} ) ;
1744
1798
}
1745
- ObjectState . pushPendingState ( target . className , target . _getStateIdentifier ( ) ) ;
1746
- return ObjectState . enqueueTask ( target . className , target . _getStateIdentifier ( ) , task ) . then ( ( ) => {
1799
+ let enqueueTask ;
1800
+ if ( singleInstance ) {
1801
+ SingleInstanceState . pushPendingState ( target . className , target . _getStateIdentifier ( ) ) ;
1802
+ enqueueTask = SingleInstanceState . enqueueTask ( target . className , target . _getStateIdentifier ( ) , task ) ;
1803
+ } else {
1804
+ // TODO: implement uniqueInstanceState
1805
+ }
1806
+
1807
+ return enqueueTask . then ( ( ) => {
1747
1808
return target ;
1748
1809
} , ( error ) => {
1749
1810
return ParsePromise . error ( error ) ;
0 commit comments