File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ( [ {
You can’t perform that action at this time.
0 commit comments