Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate _localId as UUID #956

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/ParseObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* @flow
*/
const uuidv4 = require('uuid/v4');

import CoreManager from './CoreManager';
import canBeSerialized from './canBeSerialized';
Expand Down Expand Up @@ -64,8 +65,6 @@ const DEFAULT_BATCH_SIZE = 20;
// server with appropriate subclasses of ParseObject
const classMap = {};

// Global counter for generating unique local Ids
let localCount = 0;
// Global counter for generating unique Ids for non-single-instance objects
let objectCount = 0;
// On web clients, objects are single-instance: any two objects with the same Id
Expand Down Expand Up @@ -188,7 +187,7 @@ class ParseObject {
if (typeof this._localId === 'string') {
return this._localId;
}
const localId = 'local' + String(localCount++);
const localId = 'local' + uuidv4();
this._localId = localId;
return localId;
}
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/ParseObject-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jest.dontMock('../unsavedChildren');
jest.dontMock('../ParseACL');
jest.dontMock('../LocalDatastore');

jest.mock('uuid/v4', () => {
let value = 0;
return () => value++;
});
jest.dontMock('./test_helpers/mockXHR');

jest.useFakeTimers();
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/ParseQuery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jest.dontMock('../LocalDatastore');
jest.dontMock('../OfflineQuery');
jest.dontMock('../LiveQuerySubscription');

jest.mock('uuid/v4', () => {
let value = 0;
return () => value++;
});
const mockObject = function(className) {
this.className = className;
this.attributes = {};
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/ParseUser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ jest.dontMock('../TaskQueue');
jest.dontMock('../unique');
jest.dontMock('../UniqueInstanceStateController');

jest.mock('uuid/v4', () => {
let value = 0;
return () => value++;
});
jest.dontMock('./test_helpers/mockXHR');

const CoreManager = require('../CoreManager');
Expand Down