File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes best solution. 4 callbacks in a row, but based on where it started different last callback Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "best solution. 4 callbacks in a row, but based on where it started different last callback" Watch "best solution. 4 callbacks in a row, but based on where it started different last callback" New topic
Author

best solution. 4 callbacks in a row, but based on where it started different last callback

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Here is where I am still trying to grasp the best solutions to certain problems that only come about in depth asynchronous callbacks.

I have two screens. One for account one for event. In both there is a way to edit an item. If you edit it through the account page, I have to update a section. If I update it through event page, I don't have that. Also from the event page I am passing a boolean to close a window, where I don't have that parameter or need through the account page.

I want to reuse code I have to use in both screens. But here is the rub. The flow is through 4 different callbacks

the event or account page has a link, with the same class name that I attach the click event to. But only attach it when that screen is rendered by the templating engine.

Here is the flow from the account page


A) click on accounts page to bring up popup
B) calls showItemSignedUp which is setting up some vars and calling showItem
C) calls showItem which uses the vars to define the popup.
D) calls saveItemForEvent which is used to save the with a post.
COULD INJECT HERE
E) updateEventAfterItem with closeMe === true in the event page, in the account page no closeMe needed so shouldn't call updateEventAfterItem, but in account page call a different function.

so in A, I know where I am, which affects what E should be. But I don't want to store it in a global var. How do I pass the information that in E I was originally called from the account screen, or I am in E and I was originally called from the event screen.

Remember I put screens because they are not pages. I only have a single page app. The screens are just rendered templates I put into a div called content. So one screen html might be in there, or some other one.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Could you encapsulate the callback functions into an object. And then create another object that inherits from this object and adds the last callback function. This last object have two versions, one with the last callback function for the account page and one for the event page. Kind of like the Template Method pattern, where the steps are defined in the parent class, and all the same functions are also in the parent class and the child just has to implement the abstract methods that are specific to the subclass.

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Actually, it looks like that would be the best solution. Create one object with the template function and common functions. Then create a new object for the account screen with the first as its prototype, then add the last function. Then do the same for the event screen setting this new objects prototype to the same base function/class.

Thanks

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Like this???



Thanks

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

No feedback. Sick of me already. ;)

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: best solution. 4 callbacks in a row, but based on where it started different last callback