Skip to content

Commit

Permalink
Clean up commit dependency code
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultz committed Sep 15, 2011
1 parent 712946a commit f2006e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
9 changes: 0 additions & 9 deletions src/mesh/model/associations/Association.as
Expand Up @@ -164,15 +164,6 @@ package mesh.model.associations
_entities.remove(entity);
}

/**
* The set of entities belonging to this association that are dependent on the owner being
* committed first.
*/
public function get dependents():Array
{
return isMaster && owner.status.isNew ? entities : [];
}

private var _entities:HashSet = new HashSet();
/**
* The set of entities belonging to this association.
Expand Down
48 changes: 24 additions & 24 deletions src/mesh/model/store/Commit.as
Expand Up @@ -35,7 +35,7 @@ package mesh.model.store
private var _entities:HashSet;

private var _committed:HashSet = new HashSet();
private var _dependencies:Dependencies = new Dependencies();
private var _dependencies:Dependencies;

/**
* Constructor.
Expand All @@ -48,7 +48,7 @@ package mesh.model.store
_store = store;
_entities = new HashSet(entities);
_snapshots = new Snapshots(entities);
createDependencies();
_dependencies = new Dependencies(this, entities);
}

/**
Expand Down Expand Up @@ -122,8 +122,8 @@ package mesh.model.store
for each (var entity:Entity in entities) {
entity.synced();

// Notify dependencies that their dependents have been committed, and any foreign keys
// should be synced now.
// Notify the owners of this entity that it's been committed and that the foreign keys
// are synced.
for each (var depenency:Entity in _dependencies.dependenciesFor(entity)) {
depenency.synced();
}
Expand All @@ -141,15 +141,6 @@ package mesh.model.store
commit(dependents.toArray());
}

private function createDependencies():void
{
for each (var entity:Entity in _entities) {
for each (var association:Association in entity.associations) {
_dependencies.addDependents(entity, association.dependents);
}
}
}

/**
* The data source calls this method when an entity failed during a commit to the
* backend.
Expand All @@ -172,14 +163,6 @@ package mesh.model.store
dispatchEvent(event.clone());
}

private function storeEntities(entities:Array):Array
{
return entities.map(function(entity:Entity, ...args):Entity
{
return _store.index.findByKey(entity.storeKey);
});
}

private var _operation:CommitOperation;
/**
* Adds the commit to a queue.
Expand Down Expand Up @@ -261,6 +244,7 @@ import collections.HashSet;
import flash.utils.Dictionary;

import mesh.model.Entity;
import mesh.model.associations.Association;
import mesh.model.source.SourceFault;
import mesh.model.store.Commit;
import mesh.operations.Operation;
Expand Down Expand Up @@ -342,12 +326,12 @@ class Dependencies
/**
* Constructor.
*/
public function Dependencies()
public function Dependencies(commit:Commit, entities:Array)
{

build(commit, entities);
}

public function addDependents(target:Entity, dependents:Array):void
private function addDependents(target:Entity, dependents:Array):void
{
if (_entityToDependents[target] == null) {
_entityToDependents[target] = new HashSet();
Expand All @@ -367,6 +351,22 @@ class Dependencies
_entityToDependencies[target].add(dependency);
}

private function build(commit:Commit, entities:Array):void
{
for each (var entity:Entity in entities) {
if (entity.status.isNew) {
for each (var association:Association in entity.associations) {
if (association.isMaster) {
addDependents(entity, association.entities.filter(function(entity:Entity, index:int, array:Array):Boolean
{
return commit.contains(entity);
}));
}
}
}
}
}

/**
* Returns the dependencies for an entity.
*
Expand Down

0 comments on commit f2006e0

Please sign in to comment.