A sort of freeze method in all classes would be a solution for this
matter yes.
It *could* make sense for most classes that such a variable would
exist is (most) classes.

My original question though was about a thumbs class I have that has a
setCurrent method as well executed on the click event which is
attached in that class.
And, since the class is quite abstract (all it does is storing a bunch
of elements as a list and it sets the current if a thumb is clicked)
it didn't make much sense to me to introduce a "busy" or "ongoing"
variable into the class - I mean, there is no real busy state
possible, it's only busy between the point you click and the check if
it's a "new" thumb that is clicked, so that is like 0.1ms and then
it's not busy anymore.

But in most real user cases you would do something extra after
clicking a thumb (load a page, load a large image, do some
slideshow, ...) and you do have some sort of delay (either from
loading or fx) and you do need a busy or frozen variable in your
original thumb-class... so you extend it (at least I did) and re-write
the click method so it checks the state first before calling
setCurrent.
After doing that I thought: OK, in practice I would probably need it
to function it this way always, so I could change the original class
instead of extending it, but then again, if this would be in the basic
version of the class, then it feels kinda wrong that it is in there..
since there is no real busy state....



On Aug 22, 7:00 am, אריה גלזר <arieh.gla...@gmail.com> wrote:
> i would return if ongoing was true.
> but this is quite slippery. another intersting concept can be to add a
> freeze method to all your classes, that is checked through all methods. if
> an object is frozen it won't react to it's events (probably require a
> this.frozen flag). then, the group could just start by freezing everything,
> than unfreezing.
>
> what's important here is that you don't break the Class's encapsulations. If
> 2 classes are using the same global variable, than something is off (i know
> it was my idea but now i see it was a bad one). there's a great difference
> between creating a private variable via a private scope that all instances
> of the same Class, and between few different Classes sharing a global var,
> even if it were created via a private scope.
>
> I think the freeze concept is much more solid.
>
>
>
> On Sat, Aug 21, 2010 at 10:28 PM, Rolf -nl <plentyofr...@gmail.com> wrote:
> > Thanks for the Group example, it's really rather simple :)
>
> > But it wouldn't really work in this case. I think I can ask it in a
> > more simple question, again using your ThumbsSlides class (as it is)..
>
> > If an global _ongoing is true, how would that prevent ThumbsSlides not
> > calling the setCurrent method called by the attached click event in
> > ThumbsSlides when someone clicks on a thumbnail?
>
> > On Aug 21, 4:35 pm, אריה גלזר <arieh.gla...@gmail.com> wrote:
> > > Well, i'm not sure i fully understood all of your scenario, but if what
> > you
> > > are looking for is a way with which you can see when all your animating
> > > classes are done, you can do something like:
>
> > > //the open thumb function, and also there will be a global thumbsildes,
> > and
> > > a global ongoing flag - _ongoing
> > > function openThumb(el){
> > > if (_ongoing) return;
> > > var myAnim1 =  new AnimStart1()
> > > , myAnim2 = new AnimStart2()
> > > , group = new Group(myAnim1,myAnim2,thumbslides);
>
> > > group.addEvent('complete',function(){_ongoing=false;});
>
> > > _ongoing = true;
>
> > > myAnim1.start();
> > > myAnim2.start();
>
> > > }
>
> > > this way, only when all classes fired their complete events will the
> > > _ongoing flag will be turned off.
>
> > > On Sat, Aug 21, 2010 at 4:37 PM, Rolf -nl <plentyofr...@gmail.com>
> > wrote:
> > > > Arieh, not sure if I follow you with the use of Group here.
>
> > > > Consider the following scenario with your ThumbsSlides class:
> > > > 1. I have a page with a list of images, they represent book covers.
> > > > 2. If you click the cover it will load an excerpt of the book via ajax
> > > > and places the result in some div container (e.g. via some tabs class
> > > > that uses the thumbs as tabs and loads content)
> > > > 3. Also, when clicked, some graphical elements on the page start to
> > > > move to do some fx chain (what kind depends on the image), in total
> > > > the animation is 6 seconds
>
> > > > The tabsClass fires an onComplete when it's done and the method called
> > > > in the onComplete sets "_tabIsLoading" to false in myApp.
> > > > The animation chain running in myApp sets "_isAnimating" to false when
> > > > it's done.
> > > > The click event attached to thumb checks of both are set to false, if
> > > > that's the case it'll start again with the procedure if someone clicks
> > > > a thumb. If not you can click all you want while the tabsClass is
> > > > loading content, or the animation is not finished yet.
>
> > > > Now this list turns out to be quite long and you see the ThumbsSlides
> > > > class which will turn the list into a scrollable one, with
> > > > controllers... quite useful!
> > > > So you implement it and now the list of 50 images has turned into a
> > > > scrollable list with only 10 images in the viewport.
> > > > Outside of ThumbsSlides (in myApp singleton) you also implement a zoom
> > > > class. If you now click a thumb next to the animation and content
> > > > loading it also shows a big image of the cover. Not in a modal, it'll
> > > > just shows up big in some container.
>
> > > > Rund down: if you click a thumb, the routine starts (loading content,
> > > > loading/showing big image, chain of fx for background eye candy) if
> > > > you click again there are some flags in myApp that prevent errors, but
> > > > in ThumbsSlides it'll call setCurrent on each click, the myApp busy-
> > > > flags don't apply in ThumbsSlides. So if you click a thumb every 2
> > > > seconds it'll set the current each time. In return the site is done
> > > > with the routine, but some other thumbnail in ThumbSlides is
> > > > this.current and this thumb will have the class "current" added to the
> > > > element.
>
> > > > How would you prevent this?
>
> > > > Extending your ThumbsClass to ThumbsClassSpecial and remove the click
> > > > event? for this special occasion..?
>
> > > > On Aug 20, 10:16 pm, אריה גלזר <arieh.gla...@gmail.com> wrote:
> > > > > there are a few good ways of doing this. My favorite- if you have a
> > lot
> > > > of
> > > > > classes working together, you can create a class
> > > > > group<http://mootools.net/docs/more/Utilities/Group>for all of them,
> > > > > and attach a complete event that will toggle a ongoing
> > > > > flag.
> > > > > Yet another good reason for using standard eventing for all your
> > classes
> > > > ;-)
>
> > > > > On Fri, Aug 20, 2010 at 10:37 PM, Rolf -nl <plentyofr...@gmail.com>
> > > > wrote:
> > > > > > Right, well, it's not just the slideshow. It's a bunch of
> > animations
> > > > > > running in a sequence (container divs with text or extra images)..
> > the
> > > > > > slideshow.show is executed somewhere in the middle of the chain.
>
> > > > > > However, the problem is more the thumbnail class. It attaches a
> > click
> > > > > > event to each thumbnail, which checks:
> > > > > > a) if clicked thumbnail == this.current, then do nothing, return,
> > > > > > don't fire anything.
> > > > > > b) else, set the new current to the clicked one (maybe add a class
> > to
> > > > > > the element) and fire an event (so the outside world knows it can
> > do
> > > > > > stuff, e.g. it triggers the SlideShow instance).
>
> > > > > > So when clicking the thumbnails I can prevent the slideshow from
> > doing
> > > > > > something and the main app too (both have a transitioning
> > true/false
> > > > > > flag), but it will still change the "current" var (this.current =
> > > > > > index), because the class just checks if the clicked one is the
> > same
> > > > > > or different than the current one. Even though some animations are
> > > > > > still running... you know, I started with thumbnail 3 and by the
> > time
> > > > > > the fx chain in the main app reaches the part where it does
> > > > > > slideshowShow I already changed the current thumbnail in the
> > thumbnail
> > > > > > class 4 times and current is now 7 for example.
>
> > > > > > When dealing only with SlideShow I could call the setCurrent method
> > > > > > only after showComplete, not directly when clicking a thumbnail.
> > But
> > > > > > in this case SlideShow is only a part in the sequence of
> > animations,
> > > > > > that are created outside of the thumbnail class and are site
> > specific
> > > > > > (so shouldn't be put in a class that re-writes the methods in the
> > > > > > thumbnail class or something).
>
> > > > > > Pfff... confusing
>
> > > > > > On Aug 20, 5:55 pm, Ryan Florence <rpflore...@gmail.com> wrote:
> > > > > > > slideshowInstance.transitioning // true | false
>
> > > > > > > If it's true, it's animating, you can call show() all you want
> > but
> > > > > > nothing will happen.  So if you want to wait for it to finish
> > before
> > > > doing
> > > > > > any of your other things after an event is fired (like a click),
> > just
> > > > do
>
> > > > > > >     if (!slideshow.transitioning) doStuff();
>
> > > > > > > On Aug 20, 2010, at 7:59 AM, Rolf -nl wrote:
>
> > > > > > > > I wonder how you approach the following issue:
>
> > > > > > > > I have a bunch of thumbnails that are turned into an "thumbnail
> > > > grid"
> > > > > > > > by a small class. It grabs the container, stores all thumbs in
> > a
> > > > list,
> > > > > > > > attaches events like a click that checks if the clicked on
> > thumb is
> > > > > > > > another one than the one set as current. If yes, it fires an
> > > > event...
> > > > > > > > can't get any easier.
> > > > > > > > (Similar like Arieh's earlier post here:
>
> > > >http://groups.google.com/group/mootools-users/browse_thread/thread/99..
> > > > > > .)
>
> > > > > > > > I've extended that class to add functionality so it works with
> > Ryan
> > > > > > > > Florence's SlideShow. The extended class also creates the basic
> > > > stuff
> > > > > > > > needed for SlideShow (a slide for each thumb) and does a little
> > > > more.
> > > > > > > > Now when you click a thumb, it tells me the slide is ready or
> > not &
> > > > > > > > waiting to be moved. Basically you have a gallery now. Can't
> > get
> > > > any
> > > > > > > > easier.
>
> > > > > > > > The app picks up the fired event and starts with a queue of
> > > > actions,
> > > > > > > > basically a chain of fx, including a call to the SlideShow to
> > slide
> > > > in
> > > > > > > > the clicked image.
>
> > > > > > > > The goal is to prevent thumb clicks (actions starting after the
> > > > click)
> > > > > > > > when the chain of fx is still running. When the slide is moving
> > and
> > > > > > > > other animation is still running I can keep clicking the thumbs
> > > > which
> > > > > > > > register as fresh clicks, since the thumbnail class attached a
> > > > click
> > > > > > > > event and the chain of fx run independant of this.
>
> > > > > > > > My current "solution" is also a cheap one: I place a div above
> > the
> > > > > > > > thumbnail grid with a transparent background so you can't click
> > the
> > > > > > > > thumbs below. When the chain is done I remove it and you can
> > click
> > > > the
> > > > > > > > thumbs again. So even though this works, it doesn't feel like a
> > > > proper
> > > > > > > > solution.
>
> > > > > > > > OK- before I broke it up in parts, I butchered this together
> > > > > > > > (deadlines!) in a big singleton class and I used a this._busy
> > > > variable
> > > > > > > > (set to true or false) and I
>
> ...
>
> read more »

Reply via email to