John Beppu
2006-Aug-27 06:07 UTC
actsAsDecorator( ) -- works great with Ajax.InPlaceEditor
Hi prototype and scriptaculous fans. I''ve come up with a clever bit of Javascript that allows one to add ''before'' and ''after'' hooks to any method of an object. I''ve named it actsAsDecorator in the spirit of all the acts_as_* plugins for ActiveRecord, and I''ve published it on my blog at: http://beppu.lbox.org/articles/2006/08/22/the-decorator-pattern-for-javascript . OO purists will note that''s it''s not a true implementation of the GoF Decorator pattern, but it has similar functionality (and I think it''s a lot more straight-forward to do in Javascript, because you can change things around at runtime instead of having to wrap everything in classes.) I also find that it works particularly well with Ajax.InPlaceEditor, because it lets me add hooks to various methods and lets me implement the functionality that I need without having to bug the script.aculo.us maintainers about adding yet another parameter to Ajax.InPlaceEditor''s options. I find it to be really useful, and I think some of you out there will like it, too, so check it out. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Colin Mollenhour
2006-Aug-28 04:32 UTC
Re: actsAsDecorator( ) -- works great with Ajax.InPlaceEditor
This is really cool, thanks for the post. I extended the InPlaceEditor before with a popup calendar but maybe this would have been easier. I extend other things occasionally as well and imagine this will come in handy because the onxxx options that most sau and prototype stuff has isn''t always flexible enough. And then there are non-prototypish things like calendars that have even less flexibility :) Colin John Beppu wrote:> Hi prototype and scriptaculous fans. > > I''ve come up with a clever bit of Javascript that allows one to add > ''before'' and ''after'' hooks to any method of an object. I''ve named it > actsAsDecorator in the spirit of all the acts_as_* plugins for > ActiveRecord, and I''ve published it on my blog at: > http://beppu.lbox.org/articles/2006/08/22/the-decorator-pattern-for-javascript > . > > OO purists will note that''s it''s not a true implementation of the GoF > Decorator pattern, but it has similar functionality (and I think it''s > a lot more straight-forward to do in Javascript, because you can > change things around at runtime instead of having to wrap everything > in classes.) > > I also find that it works particularly well with Ajax.InPlaceEditor, > because it lets me add hooks to various methods and lets me implement > the functionality that I need without having to bug the > script.aculo.us maintainers about adding yet another parameter to > Ajax.InPlaceEditor''s options. I find it to be really useful, and I > think some of you out there will like it, too, so check it out. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
John Beppu
2006-Aug-29 06:27 UTC
Re: actsAsDecorator( ) -- works great with Ajax.InPlaceEditor
On 8/27/06, Colin Mollenhour <eliteii92g-NPSFNn/7+NYVo650/ln6uw@public.gmane.org> wrote:> imagine this will come in > handy because the onxxx options that most sau and prototype stuff has > isn''t always flexible enough. And then there are non-prototypish things > like calendars that have even less flexibility :) > > ColinExactly. You can add flexibility where it did not exist before with actsAsDecorator. (...and I''m glad that prototype and scriptaculous provide as many hooks as they do, but there''s no way the maintainers could anticipate every possible hook someone will need. However, with actsAsDecorator(), they won''t have to anymore, because the power to add hooks is in your hands now.) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Ryan Gahl
2006-Aug-29 13:52 UTC
Re: actsAsDecorator( ) -- works great with Ajax.InPlaceEditor
Isn''t this kind of like aspect oriented programming? I definitely like the decorator stuff, John, keep up the good work. On 8/29/06, John Beppu <john.beppu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 8/27/06, Colin Mollenhour <eliteii92g-NPSFNn/7+NYVo650/ln6uw@public.gmane.org> wrote: > > imagine this will come in > > handy because the onxxx options that most sau and prototype stuff has > > isn''t always flexible enough. And then there are non-prototypish things > > like calendars that have even less flexibility :) > > > > Colin > > > Exactly. You can add flexibility where it did not exist before with > actsAsDecorator. > > (...and I''m glad that prototype and scriptaculous provide as many > hooks as they do, but there''s no way the maintainers could anticipate > every possible hook someone will need. However, with > actsAsDecorator(), they won''t have to anymore, because the power to > add hooks is in your hands now.) > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Matt Spendlove
2006-Aug-29 15:34 UTC
Re: actsAsDecorator( ) -- works great with Ajax.InPlaceEditor
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> </head> <body> <font face="Arial,sans-serif"><font size="2">Sure is.<br> <br> I''ve got an AOP library that I can I''ll try and publish for feedback when I get a minute !<br> <br> Basic idea is :<br> <br> Aspects.addAround(Logger.prototype.AOPLogger, this, /rating/);<br> <br> It''ll match all methods on the current object with named like "rating" and apply an around advice. In this case the advice simple entry / exit logs the method calls dumping args and returns etc...<br> <br> Matt<br> <br> <span type="cite">Ryan Gahl wrote:</span> </font></font> <p><font face="Arial,sans-serif" size="2"></font></p> <blockquote type="cite" style="border-left: thin solid blue; padding-left: 10px; margin-left: 0pt;"><font face="Arial,sans-serif" size="2">Isn''t this kind of like aspect oriented programming? I definitely like the decorator stuff, John, keep up the good work.<br> <br> </font> <div><font face="Arial,sans-serif" size="2"><span class="gmail_quote">On 8/29/06, <b class="gmail_sendername">John Beppu</b> <<a href="mailto:john.beppu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"> john.beppu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a>> wrote:</span></font> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><font face="Arial,sans-serif" size="2"><br> On 8/27/06, Colin Mollenhour <<a href="mailto:eliteii92g-NPSFNn/7+NYVo650/ln6uw@public.gmane.org"> eliteii92g-NPSFNn/7+NYVo650/ln6uw@public.gmane.org</a>> wrote:<br> > imagine this will come in<br> > handy because the onxxx options that most sau and prototype stuff has<br> > isn''t always flexible enough. And then there are non-prototypish things <br> > like calendars that have even less flexibility :)<br> ><br> > Colin<br> <br> <br> Exactly. You can add flexibility where it did not exist before with<br> actsAsDecorator.<br> <br> (...and I''m glad that prototype and scriptaculous provide as many <br> hooks as they do, but there''s no way the maintainers could anticipate<br> every possible hook someone will need. However, with<br> actsAsDecorator(), they won''t have to anymore, because the power to<br> add hooks is in your hands now.) <br> <br> <br> </font></blockquote> </div> <font face="Arial,sans-serif" size="2"><br> <br> <br> </font></blockquote> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. <br> To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>
John Beppu
2006-Aug-29 16:57 UTC
Re: actsAsDecorator( ) -- works great with Ajax.InPlaceEditor
On 8/29/06, Ryan Gahl <ryan.gahl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Isn''t this kind of like aspect oriented programming? I definitely like the > decorator stuff, John, keep up the good work. >Yeah, that''s what people are telling me. I wasn''t really familiar with AOP before this, and I''m still not that familiar with it now. Perhaps I''m looking at the wrong sites, but the literature for AOP that I''ve found is kinda heavy on theory and not that easy to understand. What''s funny is that I might have accidentally brought AOP to the masses. (...or at least a watered down version of AOP (that''s still useful)) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---