#10 open
Dan Schultz

Refactor Saves to Use Closures

Reported by Dan Schultz | January 17th, 2011 @ 12:18 AM | in 0.3.0

Refactor save operations to not rely on the createSave() and createDelete() methods. All this logic should be contained within save() and delete(). In addition, this would allow us to remove the whole operations API, which is one less thing people have to worry about and learn.

We should be able to accomplish this by creating a object that executes a closure function.

public class Entity
{
    public function save(validate:Boolean):AsyncToken
    {
        var token:AsyncToken = new AsyncToken();
        var closure:Function = function():void
        {
            if (validate && isInvalid()) {
                token.fault();
            }
            
            var resultHandler:Function = function(result:ResultEvent):void
            {
                token.result(result);
            }
            var faultHandler:Function = function(fault:FaultEvent):void
            {
                token.fault(fault);
            }
            var adaptorToken:AsyncToken = isNew ? adaptor.create([this]) : adaptor.update([this]);
            
            adaptorToken.addResponder(new AsyncResponder(resultHandler, faultHandler));
        }
        return token;
    }
}

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Mesh is an open-source persistence framework for Adobe Flex. It is designed to make the persistence of your application's model easier. Mesh provides the mechanisms for defining the associations between your model's entities, tracking which objects need to be saved, and mapping your entities to backend services.

<p>
<strong>Wiki</strong>
The Mesh wiki is hosted on GitHub at <a href="https://github.com/danschultz/mesh/wiki">https://github.com/danschultz/mesh/wiki</a>.
</p>

<p>
<strong>Source Code</strong>
Mesh is hosted on GitHub at <a href="http://github.com/danschultz/mesh">http://github.com/danschultz/mesh</a>.
</p>

Shared Ticket Bins

People watching this ticket

Pages