Skip to content

Commit dc26b15

Browse files
authored
Generate _localId as UUID (#956)
1 parent 8ee9c14 commit dc26b15

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

src/ParseObject.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* @flow
1010
*/
11+
const uuidv4 = require('uuid/v4');
1112

1213
import CoreManager from './CoreManager';
1314
import canBeSerialized from './canBeSerialized';
@@ -64,8 +65,6 @@ const DEFAULT_BATCH_SIZE = 20;
6465
// server with appropriate subclasses of ParseObject
6566
const classMap = {};
6667

67-
// Global counter for generating unique local Ids
68-
let localCount = 0;
6968
// Global counter for generating unique Ids for non-single-instance objects
7069
let objectCount = 0;
7170
// On web clients, objects are single-instance: any two objects with the same Id
@@ -188,7 +187,7 @@ class ParseObject {
188187
if (typeof this._localId === 'string') {
189188
return this._localId;
190189
}
191-
const localId = 'local' + String(localCount++);
190+
const localId = 'local' + uuidv4();
192191
this._localId = localId;
193192
return localId;
194193
}

src/__tests__/ParseObject-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ jest.dontMock('../unsavedChildren');
3232
jest.dontMock('../ParseACL');
3333
jest.dontMock('../LocalDatastore');
3434

35+
jest.mock('uuid/v4', () => {
36+
let value = 0;
37+
return () => value++;
38+
});
3539
jest.dontMock('./test_helpers/mockXHR');
3640

3741
jest.useFakeTimers();

src/__tests__/ParseQuery-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jest.dontMock('../LocalDatastore');
2121
jest.dontMock('../OfflineQuery');
2222
jest.dontMock('../LiveQuerySubscription');
2323

24+
jest.mock('uuid/v4', () => {
25+
let value = 0;
26+
return () => value++;
27+
});
2428
const mockObject = function(className) {
2529
this.className = className;
2630
this.attributes = {};

src/__tests__/ParseUser-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jest.dontMock('../TaskQueue');
2727
jest.dontMock('../unique');
2828
jest.dontMock('../UniqueInstanceStateController');
2929

30+
jest.mock('uuid/v4', () => {
31+
let value = 0;
32+
return () => value++;
33+
});
3034
jest.dontMock('./test_helpers/mockXHR');
3135

3236
const CoreManager = require('../CoreManager');

0 commit comments

Comments
 (0)