Skip to content

Commit

Permalink
Add helper methods for entity serialization/deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultz committed Aug 17, 2011
1 parent 74a59c1 commit c4eeeb8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/mesh/model/source/FixtureSource.as
@@ -1,6 +1,5 @@
package mesh.model.source
{
import flash.errors.IllegalOperationError;
import flash.utils.Dictionary;
import flash.utils.setTimeout;

Expand Down Expand Up @@ -49,7 +48,7 @@ package mesh.model.source
{
entity.busy();

var data:Object = entity.serialize();
var data:Object = serialize([entity])[0];
setTimeout(function():void
{
if (_fixtures[data.id] != null) {
Expand All @@ -68,11 +67,11 @@ package mesh.model.source
{
entity.busy();

var data:Object = entity.serialize();
var data:Object = serialize([entity])[0];
setTimeout(function():void
{
if (_fixtures[data.id] != null) {
entity.deserialize(_fixtures[data.id]);
//entity.deserialize(_fixtures[data.id]);
synced([entity]);
} else {
entity.errored();
Expand All @@ -87,7 +86,7 @@ package mesh.model.source
{
entity.busy();

var data:Object = entity.serialize();
var data:Object = serialize([entity])[0];
setTimeout(function():void
{
if (data.id != null && data.id > 0) {
Expand Down
26 changes: 25 additions & 1 deletion src/mesh/model/source/Source.as
Expand Up @@ -2,9 +2,10 @@ package mesh.model.source
{
import flash.errors.IllegalOperationError;

import mesh.core.reflection.reflect;
import mesh.model.Entity;
import mesh.model.store.Store;
import mesh.model.query.Query;
import mesh.model.store.Store;

/**
* The <code>Source</code> class is responsible for persisting an <code>Entity</code>.
Expand Down Expand Up @@ -138,5 +139,28 @@ package mesh.model.source
entity.errored();
}
}

/**
* Serializes the entities into a format that the server expects, such as XML, JSON or
* AMF.
*
* @param entities The entities to serialize.
* @return An array of serialized entities.
*/
protected function serialize(entities:Array):Array
{
throw new IllegalOperationError(reflect(this).name + ".serialize() is not implemented.");
}

/**
* Deserializes the data retrieved from the server into entities.
*
* @param data The data to deserialize.
* @return An array of deserialized entities.
*/
protected function deserialize(data:Array):Array
{
throw new IllegalOperationError(reflect(this).name + ".deserialize() is not implemented.");
}
}
}

0 comments on commit c4eeeb8

Please sign in to comment.