Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Refactor Saves to Use Closures

#10

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;
    }
}

Reported by Dan Schultz · January 17th, 2011 @ 12:18 AM

State: open
Milestone: 0.3.0
Assigned to: Dan Schultz Dan Schultz

Activity

  1. Dan Schultz
    Dan Schultz
    • Milestone changed from 0.1.0 to 0.2.0
    • Milestone order changed from 8 to 0

    January 20th, 2011 @ 02:02 AM

  2. Dan Schultz
    Dan Schultz
    • State changed from new to open

    March 17th, 2011 @ 08:08 AM

  3. Dan Schultz
    Dan Schultz
    • Milestone changed from 0.2.0 to 0.3.0
    • Milestone order changed from 4 to 0

    April 6th, 2011 @ 05:11 AM

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.