graph-database.js
/**
    Generate a deletion patch for the object and its reachable children
    @param {GraphObject} object
   */
Generate a deletion patch for the object and its reachable children
Generate a deletion patch for the object and its reachable children
delete(object) {
    var thisStore = this;
    var request = new DeleteRequest(this, thisStore.transaction);
    var p = new Promise(function(accept, reject) {
      var store = object._store;
      if (store == thisStore) { 
        var deleteObject = function(object) {
          object._state = object.stateDeleted;
          object.persistentValues().forEach(deleteChild);
        }
        var deleteChild = function(child) {
          if (child instanceof GraphObject) {
             thisStore.deleteObject(object);
          } else if (child instanceof Array) {
            child.forEach(deleteChild);
          }
        }
        deleteObject(object);
        request.patch = {};
      } else {
        object._state = object.stateDeleted;
        request.patch = object.asPatch();
      }
      request.result = object;
      thisStore.requests.push(request);
      accept(request);
    });
    p.then(function(requestIgnored) {
      for (request = thisStore.requests.shift();
           request;
           request = thisStore.requests.shift()) {
        thisStore.patches.push(request.patch);
        request.readyState = "complete";
        if (request.onsuccess) {
          request.onsuccess(new SuccessEvent("success", "delete", request.result));
        }
      }
      thisStore.transaction.commitIfComplete();
      return(request);
    }, null);
    return( request );
  }
delete ( object ) { var thisStore = this ; var request = new DeleteRequest ( this , thisStore . transaction ) ; var p = new Promise ( function ( accept , reject ) { var store = object . _store ; if ( store == thisStore ) { var deleteObject = function ( object ) { object . _state = object . stateDeleted ; object . persistentValues ( ) . forEach ( deleteChild ) ; } var deleteChild = function ( child ) { if ( child instanceof GraphObject ) { thisStore . deleteObject ( object ) ; } else if ( child instanceof Array ) { child . forEach ( deleteChild ) ; } } deleteObject ( object ) ; request . patch = { } ; } else { object . _state = object . stateDeleted ; request . patch = object . asPatch ( ) ; } request . result = object ; thisStore . requests . push ( request ) ; accept ( request ) ; } ) ; p . then ( function ( requestIgnored ) { for ( request = thisStore . requests . shift ( ) ; request ; request = thisStore . requests . shift ( ) ) { thisStore . patches . push ( request . patch ) ; request . readyState = "complete" ; if ( request . onsuccess ) { request . onsuccess ( new SuccessEvent ( "success" , "delete" , request . result ) ) ; } } thisStore . transaction . commitIfComplete ( ) ; return ( request ) ; } , null ) ; return ( request ) ; }
Generate a deletion patch for the object and its reachable children
Generate a deletion patch for the object and its reachable children
// just mark the closure // allow the onsuccess to push more requests