Skip to content

Commit

Permalink
Shorten store and source class names
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultz committed Jul 26, 2011
1 parent cb3c4e3 commit f712501
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/mesh/Mesh.as
@@ -1,6 +1,6 @@
package mesh
{
import mesh.model.EntityStore;
import mesh.model.Store;
import mesh.services.Service;
import mesh.services.Services;

Expand Down Expand Up @@ -30,6 +30,6 @@ package mesh
/**
* The repository of all <code>Entity</code>s in the application.
*/
public static var store:EntityStore;
public static var store:Store;
}
}
33 changes: 18 additions & 15 deletions src/mesh/model/EntityStore.as → src/mesh/model/Store.as
Expand Up @@ -6,18 +6,19 @@ package mesh.model
import flash.utils.Dictionary;

import mesh.core.reflection.newInstance;
import mesh.source.EntitySource;
import mesh.source.Source;

import mx.events.PropertyChangeEvent;

public class EntityStore extends EventDispatcher
public class Store extends EventDispatcher
{
private var _keyCounter:Number = 0;
private var _keyToEntity:Dictionary = new Dictionary();
private var _dataSource:EntitySource;
private var _changes:HashSet = new HashSet();

public function EntityStore(dataSource:EntitySource)
private var _dataSource:Source;

public function Store(dataSource:Source)
{
super();
_dataSource = dataSource;
Expand Down Expand Up @@ -47,15 +48,17 @@ package mesh.model

if (entity.isNew) {
entity.storeKey = ++_keyCounter;
store(entity);
register(entity);
}

return entity;
}

public function destroy(...args):void
public function destroy(...entities):void
{

for each (var entity:Entity in entities) {
entity.destroy();
}
}

public function find(...args):void
Expand All @@ -75,19 +78,19 @@ package mesh.model
}
}

private function purge(entity:Entity):void
private function register(entity:Entity):void
{
_keyToEntity[entity.storeKey] = entity;
entity.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, handleEntityPropertyChange);
}

private function unregister(entity:Entity):void
{
if (_keyToEntity[entity.storeKey] == null) {
throw new ArgumentError("Entity '" + entity + "' not found in store");
}
entity.removeEventListener(PropertyChangeEvent.PROPERTY_CHANGE, handleEntityPropertyChange);
delete _keyToEntity[entity.storeKey];
}

private function store(entity:Entity):void
{
_keyToEntity[entity.storeKey] = entity;
entity.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, handleEntityPropertyChange);
}
}
}
}
Expand Up @@ -5,9 +5,9 @@ package mesh.source

import mesh.core.object.merge;
import mesh.model.Entity;
import mesh.model.EntityStore;
import mesh.model.Store;

public class FixtureEntitySource extends EntitySource
public class FixtureSource extends Source
{
private var _fixtures:Dictionary = new Dictionary();
private var _idCounter:int;
Expand All @@ -18,7 +18,7 @@ package mesh.source
*
* @param options The options for this source.
*/
public function FixtureEntitySource(options:Object = null)
public function FixtureSource(options:Object = null)
{
super();
_options = merge({latency:250}, options);
Expand All @@ -27,7 +27,7 @@ package mesh.source
/**
* @inheritDoc
*/
override public function create(store:EntityStore, entity:Entity):void
override public function create(store:Store, entity:Entity):void
{
if (!entity.isNew) {
throw new ArgumentError("Attempted to create an non-new entity.");
Expand All @@ -39,7 +39,7 @@ package mesh.source
/**
* @inheritDoc
*/
override public function destroy(store:EntityStore, entity:Entity):void
override public function destroy(store:Store, entity:Entity):void
{
if (_fixtures[entity.id] == null) {
throw new IllegalOperationError("Attempted to destroy a non-existent entity.");
Expand All @@ -50,7 +50,7 @@ package mesh.source
/**
* @inheritDoc
*/
override public function update(store:EntityStore, entity:Entity):void
override public function update(store:Store, entity:Entity):void
{
if (entity.isNew) {
throw new IllegalOperationError("Attempted to update a new entity.");
Expand Down
12 changes: 0 additions & 12 deletions src/mesh/source/MultiEntitySource.as

This file was deleted.

12 changes: 12 additions & 0 deletions src/mesh/source/MultiSource.as
@@ -0,0 +1,12 @@
package mesh.source
{
import flash.utils.Dictionary;

public class MultiSource extends Source
{
public function MultiSource()
{
super();
}
}
}
24 changes: 12 additions & 12 deletions src/mesh/source/EntitySource.as → src/mesh/source/Source.as
Expand Up @@ -3,39 +3,39 @@ package mesh.source
import flash.errors.IllegalOperationError;

import mesh.model.Entity;
import mesh.model.EntityStore;
import mesh.model.Store;
import mesh.model.query.Query;

public class EntitySource
public class Source
{
public function EntitySource()
public function Source()
{

}

public function commit(store:EntityStore, entities:Array):void
public function commit(store:Store, entities:Array):void
{
throw new IllegalOperationError("EntitySource.commit() is not implemented.");
}

public function create(store:EntityStore, entity:Entity):void
public function create(store:Store, entity:Entity):void
{
throw new IllegalOperationError("EntitySource.createEntity() is not implemented.");
}

public function createEach(store:EntityStore, entities:Array):void
public function createEach(store:Store, entities:Array):void
{
for each (var entity:Entity in entities) {
create(store, entity);
}
}

public function destroy(store:EntityStore, entity:Entity):void
public function destroy(store:Store, entity:Entity):void
{
throw new IllegalOperationError("EntitySource.destroyEntity() is not implemented.");
}

public function destroyEach(store:EntityStore, entities:Array):void
public function destroyEach(store:Store, entities:Array):void
{
for each (var entity:Entity in entities) {
destroy(store, entity);
Expand All @@ -47,24 +47,24 @@ package mesh.source
throw new IllegalOperationError("EntitySource.fetch() is not implemented.");
}

public function retrieve(store:EntityStore, id:*):void
public function retrieve(store:Store, id:*):void
{
throw new IllegalOperationError("EntitySource.retrieveEntity() is not implemented.");
}

public function retrieveEach(store:EntityStore, ids:Array):void
public function retrieveEach(store:Store, ids:Array):void
{
for each (var id:* in ids) {
retrieve(store, id);
}
}

public function update(store:EntityStore, entity:Entity):void
public function update(store:Store, entity:Entity):void
{
throw new IllegalOperationError("EntitySource.updateEntity() is not implemented.");
}

public function updateEach(store:EntityStore, entities:Array):void
public function updateEach(store:Store, entities:Array):void
{
for each (var entity:Entity in entities) {
update(store, entity);
Expand Down
@@ -1,6 +1,6 @@
package mesh.model
{
public class EntityStoreTests
public class StoreTests
{
[Before]
public function setup():void
Expand Down

0 comments on commit f712501

Please sign in to comment.