@@ -35,6 +35,7 @@ import ParseQuery from './ParseQuery';
35
35
import ParseRelation from './ParseRelation' ;
36
36
import * as SingleInstanceState from './SingleInstanceState' ;
37
37
import unique from './unique' ;
38
+ import * as UniqueInstanceState from './UniqueInstanceState' ;
38
39
import unsavedChildren from './unsavedChildren' ;
39
40
40
41
import type { AttributeMap , OpsMap } from './ObjectState' ;
@@ -133,8 +134,7 @@ export default class ParseObject {
133
134
get attributes ( ) : AttributeMap {
134
135
let attributes = singleInstance ?
135
136
SingleInstanceState . estimateAttributes ( this . className , this . _getStateIdentifier ( ) ) :
136
- null ;
137
- // TODO: implement uniqueInstanceState
137
+ UniqueInstanceState . estimateAttributes ( this ) ;
138
138
return Object . freeze ( attributes ) ;
139
139
}
140
140
@@ -192,7 +192,7 @@ export default class ParseObject {
192
192
if ( singleInstance ) {
193
193
return SingleInstanceState . getServerData ( this . className , this . _getStateIdentifier ( ) ) ;
194
194
} else {
195
- // TODO: implement uniqueInstanceState
195
+ return UniqueInstanceState . getServerData ( this ) ;
196
196
}
197
197
}
198
198
@@ -205,15 +205,15 @@ export default class ParseObject {
205
205
if ( singleInstance ) {
206
206
SingleInstanceState . setServerData ( this . className , this . _getStateIdentifier ( ) , unset ) ;
207
207
} else {
208
- // TODO: implement uniqueInstanceState
208
+ UniqueInstanceState . setServerData ( this , unset ) ;
209
209
}
210
210
}
211
211
212
212
_getPendingOps ( ) : Array < OpsMap > {
213
213
if ( singleInstance ) {
214
214
return SingleInstanceState . getPendingOps ( this . className , this . _getStateIdentifier ( ) ) ;
215
215
} else {
216
- // TODO: implement uniqueInstanceState
216
+ return UniqueInstanceState . getPendingOps ( this ) ;
217
217
}
218
218
}
219
219
@@ -230,8 +230,7 @@ export default class ParseObject {
230
230
var attributes = this . attributes ;
231
231
var objectCache = singleInstance ?
232
232
SingleInstanceState . getObjectCache ( this . className , this . _getStateIdentifier ( ) ) :
233
- { } ;
234
- // TODO: implement uniqueInstanceState
233
+ UniqueInstanceState . getObjectCache ( this ) ;
235
234
var dirty = { } ;
236
235
for ( var attr in attributes ) {
237
236
var val = attributes [ attr ] ;
@@ -303,7 +302,7 @@ export default class ParseObject {
303
302
if ( singleInstance ) {
304
303
SingleInstanceState . initializeState ( this . className , this . _getStateIdentifier ( ) ) ;
305
304
} else {
306
- // TODO: implement uniqueInstanceState
305
+ UniqueInstanceState . initializeState ( this ) ;
307
306
}
308
307
var decoded = { } ;
309
308
for ( var attr in serverData ) {
@@ -328,27 +327,31 @@ export default class ParseObject {
328
327
if ( singleInstance ) {
329
328
SingleInstanceState . commitServerChanges ( this . className , this . _getStateIdentifier ( ) , decoded ) ;
330
329
} else {
331
- // TODO: implement uniqueInstanceState
330
+ UniqueInstanceState . commitServerChanges ( this , decoded ) ;
332
331
}
333
332
}
334
333
335
334
_setExisted ( existed : boolean ) {
336
335
let state = singleInstance ?
337
336
SingleInstanceState . getState ( this . className , this . _getStateIdentifier ( ) ) :
338
- null ;
339
- // TODO: implement uniqueInstanceState
337
+ UniqueInstanceState . getState ( this ) ;
340
338
if ( state ) {
341
339
state . existed = existed ;
342
340
}
343
341
}
344
342
345
343
_migrateId ( serverId : string ) {
346
344
if ( this . _localId && serverId ) {
347
- var oldState = SingleInstanceState . removeState ( this . className , this . _getStateIdentifier ( ) ) ;
348
- this . id = serverId ;
349
- delete this . _localId ;
350
- if ( oldState ) {
351
- SingleInstanceState . initializeState ( this . className , this . _getStateIdentifier ( ) , oldState ) ;
345
+ if ( singleInstance ) {
346
+ var oldState = SingleInstanceState . removeState ( this . className , this . _getStateIdentifier ( ) ) ;
347
+ this . id = serverId ;
348
+ delete this . _localId ;
349
+ if ( oldState ) {
350
+ SingleInstanceState . initializeState ( this . className , this . _getStateIdentifier ( ) , oldState ) ;
351
+ }
352
+ } else {
353
+ this . id = serverId ;
354
+ delete this . _localId ;
352
355
}
353
356
}
354
357
}
@@ -358,8 +361,7 @@ export default class ParseObject {
358
361
var attr ;
359
362
var pending = singleInstance ?
360
363
SingleInstanceState . popPendingState ( this . className , this . _getStateIdentifier ( ) ) :
361
- null ;
362
- // TODO: implement uniqueInstanceState
364
+ UniqueInstanceState . popPendingState ( this ) ;
363
365
for ( attr in pending ) {
364
366
if ( pending [ attr ] instanceof RelationOp ) {
365
367
changes [ attr ] = pending [ attr ] . applyTo ( undefined , this , attr ) ;
@@ -391,7 +393,7 @@ export default class ParseObject {
391
393
if ( singleInstance ) {
392
394
SingleInstanceState . commitServerChanges ( this . className , this . _getStateIdentifier ( ) , changes ) ;
393
395
} else {
394
- // TODO: implement uniqueInstanceState
396
+ UniqueInstanceState . commitServerChanges ( this , changes ) ;
395
397
}
396
398
}
397
399
@@ -400,7 +402,7 @@ export default class ParseObject {
400
402
if ( singleInstance ) {
401
403
SingleInstanceState . mergeFirstPendingState ( this . className , this . _getStateIdentifier ( ) ) ;
402
404
} else {
403
- // TODO: implement uniqueInstanceState
405
+ UniqueInstanceState . mergeFirstPendingState ( this ) ;
404
406
}
405
407
}
406
408
@@ -693,7 +695,7 @@ export default class ParseObject {
693
695
if ( singleInstance ) {
694
696
SingleInstanceState . setPendingOp ( this . className , this . _getStateIdentifier ( ) , attr , nextOp ) ;
695
697
} else {
696
- // TODO: implement uniqueInstanceState
698
+ UniqueInstanceState . setPendingOp ( this , attr , nextOp ) ;
697
699
}
698
700
}
699
701
@@ -823,8 +825,7 @@ export default class ParseObject {
823
825
}
824
826
var state = singleInstance ?
825
827
SingleInstanceState . getState ( this . className , this . _getStateIdentifier ( ) ) :
826
- null ;
827
- // TODO: implement uniqueInstanceState
828
+ UniqueInstanceState . getState ( this ) ;
828
829
if ( state ) {
829
830
return state . existed ;
830
831
}
@@ -1095,7 +1096,7 @@ export default class ParseObject {
1095
1096
if ( singleInstance ) {
1096
1097
SingleInstanceState . _clearAllState ( ) ;
1097
1098
} else {
1098
- // TODO: implement uniqueInstanceState
1099
+ UniqueInstanceState . _clearAllState ( ) ;
1099
1100
}
1100
1101
}
1101
1102
@@ -1514,6 +1515,15 @@ export default class ParseObject {
1514
1515
static disableSingleInstance ( ) {
1515
1516
singleInstance = false ;
1516
1517
}
1518
+
1519
+ /**
1520
+ * Returns a boolean marking whether single instance mode is enabled or not.
1521
+ * @method isSingleInstance
1522
+ * @return {Boolean } A boolean flag that is true if single instance is enabled.
1523
+ */
1524
+ static isSingleInstance ( ) : boolean {
1525
+ return singleInstance ;
1526
+ }
1517
1527
}
1518
1528
1519
1529
var DefaultController = {
@@ -1753,7 +1763,8 @@ var DefaultController = {
1753
1763
SingleInstanceState . pushPendingState ( obj . className , obj . _getStateIdentifier ( ) ) ;
1754
1764
batchTasks . push ( SingleInstanceState . enqueueTask ( obj . className , obj . _getStateIdentifier ( ) , task ) ) ;
1755
1765
} else {
1756
- // TODO: implement uniqueInstanceState
1766
+ UniqueInstanceState . pushPendingState ( obj ) ;
1767
+ batchTasks . push ( UniqueInstanceState . enqueueTask ( obj , task ) ) ;
1757
1768
}
1758
1769
} ) ;
1759
1770
@@ -1801,7 +1812,8 @@ var DefaultController = {
1801
1812
SingleInstanceState . pushPendingState ( target . className , target . _getStateIdentifier ( ) ) ;
1802
1813
enqueueTask = SingleInstanceState . enqueueTask ( target . className , target . _getStateIdentifier ( ) , task ) ;
1803
1814
} else {
1804
- // TODO: implement uniqueInstanceState
1815
+ UniqueInstanceState . pushPendingState ( target ) ;
1816
+ enqueueTask = UniqueInstanceState . enqueueTask ( target , task ) ;
1805
1817
}
1806
1818
1807
1819
return enqueueTask . then ( ( ) => {
0 commit comments