@@ -14,42 +14,42 @@ export function opFromJSON(json: { [key: string]: any }): ?Op {
1414 return null ;
1515 }
1616 switch ( json . __op ) {
17- case 'Delete' :
18- return new UnsetOp ( ) ;
19- case 'Increment' :
20- return new IncrementOp ( json . amount ) ;
21- case 'Add' :
22- return new AddOp ( decode ( json . objects ) ) ;
23- case 'AddUnique' :
24- return new AddUniqueOp ( decode ( json . objects ) ) ;
25- case 'Remove' :
26- return new RemoveOp ( decode ( json . objects ) ) ;
27- case 'AddRelation' : {
28- const toAdd = decode ( json . objects ) ;
29- if ( ! Array . isArray ( toAdd ) ) {
30- return new RelationOp ( [ ] , [ ] ) ;
31- }
32- return new RelationOp ( toAdd , [ ] ) ;
33- }
34- case 'RemoveRelation' : {
35- const toRemove = decode ( json . objects ) ;
36- if ( ! Array . isArray ( toRemove ) ) {
37- return new RelationOp ( [ ] , [ ] ) ;
17+ case 'Delete' :
18+ return new UnsetOp ( ) ;
19+ case 'Increment' :
20+ return new IncrementOp ( json . amount ) ;
21+ case 'Add' :
22+ return new AddOp ( decode ( json . objects ) ) ;
23+ case 'AddUnique' :
24+ return new AddUniqueOp ( decode ( json . objects ) ) ;
25+ case 'Remove' :
26+ return new RemoveOp ( decode ( json . objects ) ) ;
27+ case 'AddRelation' : {
28+ const toAdd = decode ( json . objects ) ;
29+ if ( ! Array . isArray ( toAdd ) ) {
30+ return new RelationOp ( [ ] , [ ] ) ;
31+ }
32+ return new RelationOp ( toAdd , [ ] ) ;
3833 }
39- return new RelationOp ( [ ] , toRemove ) ;
40- }
41- case 'Batch' : {
42- let toAdd = [ ] ;
43- let toRemove = [ ] ;
44- for ( let i = 0 ; i < json . ops . length ; i ++ ) {
45- if ( json . ops [ i ] . __op === 'AddRelation' ) {
46- toAdd = toAdd . concat ( decode ( json . ops [ i ] . objects ) ) ;
47- } else if ( json . ops [ i ] . __op === 'RemoveRelation' ) {
48- toRemove = toRemove . concat ( decode ( json . ops [ i ] . objects ) ) ;
34+ case 'RemoveRelation' : {
35+ const toRemove = decode ( json . objects ) ;
36+ if ( ! Array . isArray ( toRemove ) ) {
37+ return new RelationOp ( [ ] , [ ] ) ;
4938 }
39+ return new RelationOp ( [ ] , toRemove ) ;
40+ }
41+ case 'Batch' : {
42+ let toAdd = [ ] ;
43+ let toRemove = [ ] ;
44+ for ( let i = 0 ; i < json . ops . length ; i ++ ) {
45+ if ( json . ops [ i ] . __op === 'AddRelation' ) {
46+ toAdd = toAdd . concat ( decode ( json . ops [ i ] . objects ) ) ;
47+ } else if ( json . ops [ i ] . __op === 'RemoveRelation' ) {
48+ toRemove = toRemove . concat ( decode ( json . ops [ i ] . objects ) ) ;
49+ }
50+ }
51+ return new RelationOp ( toAdd , toRemove ) ;
5052 }
51- return new RelationOp ( toAdd , toRemove ) ;
52- }
5353 }
5454 return null ;
5555}
@@ -336,19 +336,13 @@ export class RelationOp extends Op {
336336 return obj.id;
337337 }
338338
339- applyTo ( value : mixed , object ?: { className : string , id : ? string } , key?: string): ?ParseRelation {
339+ applyTo ( value : mixed , parent : ParseObject , key ?: string ) : ?ParseRelation {
340340 if ( ! value ) {
341- if ( ! object || ! key ) {
341+ if ( ! parent || ! key ) {
342342 throw new Error (
343343 'Cannot apply a RelationOp without either a previous value, or an object and a key'
344344 ) ;
345345 }
346- const parent = new ParseObject(object.className);
347- if (object.id && object . id . indexOf ( 'local ') === 0 ) {
348- parent . _localId = object . id ;
349- } else if (object.id) {
350- parent . id = object . id ;
351- }
352346 const relation = new ParseRelation(parent, key);
353347 relation.targetClassName = this._targetClassName;
354348 return relation;
0 commit comments