diff --git a/src/mesh/model/store/Commits.as b/src/mesh/model/store/Commits.as
index 9b78fe9..65ad33c 100644
--- a/src/mesh/model/store/Commits.as
+++ b/src/mesh/model/store/Commits.as
@@ -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
diff --git a/src/mesh/model/store/Store.as b/src/mesh/model/store/Store.as
index d423104..310b754 100644
--- a/src/mesh/model/store/Store.as
+++ b/src/mesh/model/store/Store.as
@@ -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 Entity
s in your application. The store
* is assigned a data source, which is responsible for persisting the changes to each entity.
@@ -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
@@ -176,6 +182,15 @@ package mesh.model.store
return _dataSource;
}
+ [Bindable(event="propertyChange")]
+ /**
+ * true
if the store has uncommitted changes.
+ */
+ public function get hasChanges():Boolean
+ {
+ return _changes.length > 0;
+ }
+
private var _index:EntityIndex;
/**
* The internal index of Entity
s used by the store.