Skip to content

Commit

Permalink
Add Store.hasChanges
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultz committed Sep 8, 2011
1 parent f9ea5d4 commit eaf4148
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/mesh/model/store/Commits.as
Expand Up @@ -68,9 +68,11 @@ package mesh.model.store
*/
public function commit(entities:Array = null):void
{
entities = (entities == null || entities.length == 0) ? _changes.toArray() : intersection(entities, _changes.toArray());
_changes.removeAll(entities);
queue( new Commit(_store, snapshot(entities)) );
if (_store.hasChanges) {
entities = (entities == null || entities.length == 0) ? _changes.toArray() : intersection(entities, _changes.toArray());
_changes.removeAll(entities);
queue( new Commit(_store, snapshot(entities)) );
}
}

private function commitFailed(commit:Commit):void
Expand Down
15 changes: 15 additions & 0 deletions src/mesh/model/store/Store.as
Expand Up @@ -8,6 +8,8 @@ package mesh.model.store
import mesh.model.Entity;
import mesh.model.source.Source;

import mx.events.PropertyChangeEvent;

/**
* The store represents a repository for all <code>Entity</code>s in your application. The store
* is assigned a data source, which is responsible for persisting the changes to each entity.
Expand Down Expand Up @@ -113,12 +115,16 @@ package mesh.model.store

private function handleEntityStatusStateChange(event:StateEvent):void
{
var oldHasChanges:Boolean = hasChanges;

var entity:Entity = Entity( event.target );
if (entity.status.isDirty) {
_changes.add(entity);
} else if (entity.status.isSynced) {
_changes.remove(entity);
}

dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "hasChanges", oldHasChanges, hasChanges));
}

private function register(entity:Entity):void
Expand Down Expand Up @@ -176,6 +182,15 @@ package mesh.model.store
return _dataSource;
}

[Bindable(event="propertyChange")]
/**
* <code>true</code> if the store has uncommitted changes.
*/
public function get hasChanges():Boolean
{
return _changes.length > 0;
}

private var _index:EntityIndex;
/**
* The internal index of <code>Entity</code>s used by the store.
Expand Down

0 comments on commit eaf4148

Please sign in to comment.