Skip to content

Commit 7c16dee

Browse files
committed
Add revert() instance method to ParseObject
1 parent 33bebc3 commit 7c16dee

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/ParseObject.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,14 @@ export default class ParseObject {
847847
return this.set('ACL', acl, options);
848848
}
849849

850+
/**
851+
* Clears any changes to this object made since the last call to save()
852+
* @method revert
853+
*/
854+
revert(): void {
855+
this._clearPendingOps();
856+
}
857+
850858
/**
851859
* Clears all attributes on a model
852860
* @method clear

src/__tests__/ParseObject-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,23 @@ describe('ParseObject', () => {
767767
expect(o.existed()).toBe(true);
768768
});
769769

770+
it('can revert unsaved ops', () => {
771+
var o = ParseObject.fromJSON({
772+
className: 'Item',
773+
objectId: 'canrevert',
774+
count: 5
775+
});
776+
o.set({ cool: true });
777+
o.increment('count');
778+
expect(o.get('cool')).toBe(true);
779+
expect(o.get('count')).toBe(6);
780+
o.revert();
781+
expect(o.get('cool')).toBe(undefined);
782+
expect(o.op('cool')).toBe(undefined);
783+
expect(o.get('count')).toBe(5);
784+
expect(o.op('count')).toBe(undefined);
785+
});
786+
770787
it('can save the object', asyncHelper((done) => {
771788
CoreManager.getRESTController()._setXHR(
772789
mockXHR([{

0 commit comments

Comments
 (0)