HSL: bind a signal once (destroyed after the first dispatch)

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

HSL: bind a signal once (destroyed after the first dispatch)

Dion Whitehead Amago
I have a patch for HSL, where you can bind a signal listener that is
unbound after the first call.  I find this functionality very useful.

public function bind(listener:Datatype -> Dynamic, ?callOnceOnly :Bool
= false):Bond;

This is backwards compatible with existing code.

Thoughts?  Reasons to not apply the patch?

Dion

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

Pimm Hogeling
Thought: an alternative would be adding a method to the bond:
someObject.somethingHappenedSignaler.bind(someMethod).destroyAfterUse();

On 28 February 2011 19:23, Dion Amago <[hidden email]> wrote:
I have a patch for HSL, where you can bind a signal listener that is
unbound after the first call.  I find this functionality very useful.

public function bind(listener:Datatype -> Dynamic, ?callOnceOnly :Bool
= false):Bond;

This is backwards compatible with existing code.

Thoughts?  Reasons to not apply the patch?

Dion

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

Dion Whitehead Amago
I like your syntax better.

Although it means adding a field to every bond object, rather than
using a different bond class this particular case.  I suppose that's
no much of a penalty.

Dion

On Mon, Feb 28, 2011 at 12:32 PM, Pimm Hogeling <[hidden email]> wrote:

> Thought: an alternative would be adding a method to the bond:
> someObject.somethingHappenedSignaler.bind(someMethod).destroyAfterUse();
>
> On 28 February 2011 19:23, Dion Amago <[hidden email]> wrote:
>>
>> I have a patch for HSL, where you can bind a signal listener that is
>> unbound after the first call.  I find this functionality very useful.
>>
>> public function bind(listener:Datatype -> Dynamic, ?callOnceOnly :Bool
>> = false):Bond;
>>
>> This is backwards compatible with existing code.
>>
>> Thoughts?  Reasons to not apply the patch?
>>
>> Dion
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

Pimm Hogeling
How about destroyOnUse which returns the bond itself, so you could still do this:
var bond:Bond = someObject.somethingHappenedSignaler.bind(someMethod).destroyOnUse();

What do you think? Is such method chaining common in other haXe libraries?

On 28 February 2011 19:51, Dion Amago <[hidden email]> wrote:
I like your syntax better.

Although it means adding a field to every bond object, rather than
using a different bond class this particular case.  I suppose that's
no much of a penalty.

Dion

On Mon, Feb 28, 2011 at 12:32 PM, Pimm Hogeling <[hidden email]> wrote:
> Thought: an alternative would be adding a method to the bond:
> someObject.somethingHappenedSignaler.bind(someMethod).destroyAfterUse();
>
> On 28 February 2011 19:23, Dion Amago <[hidden email]> wrote:
>>
>> I have a patch for HSL, where you can bind a signal listener that is
>> unbound after the first call.  I find this functionality very useful.
>>
>> public function bind(listener:Datatype -> Dynamic, ?callOnceOnly :Bool
>> = false):Bond;
>>
>> This is backwards compatible with existing code.
>>
>> Thoughts?  Reasons to not apply the patch?
>>
>> Dion
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

David Peek
What about just:
signaler.bindOnce(someMethod)?

Robert Penners AS3 Signals uses:
signal.addOnce(listener)

On 01/03/2011, at 9:49 AM, Pimm Hogeling wrote:

How about destroyOnUse which returns the bond itself, so you could still do this:
var bond:Bond = someObject.somethingHappenedSignaler.bind(someMethod).destroyOnUse();

What do you think? Is such method chaining common in other haXe libraries?

On 28 February 2011 19:51, Dion Amago <[hidden email]> wrote:
I like your syntax better.

Although it means adding a field to every bond object, rather than
using a different bond class this particular case.  I suppose that's
no much of a penalty.

Dion

On Mon, Feb 28, 2011 at 12:32 PM, Pimm Hogeling <[hidden email]> wrote:
> Thought: an alternative would be adding a method to the bond:
> someObject.somethingHappenedSignaler.bind(someMethod).destroyAfterUse();
>
> On 28 February 2011 19:23, Dion Amago <[hidden email]> wrote:
>>
>> I have a patch for HSL, where you can bind a signal listener that is
>> unbound after the first call.  I find this functionality very useful.
>>
>> public function bind(listener:Datatype -> Dynamic, ?callOnceOnly :Bool
>> = false):Bond;
>>
>> This is backwards compatible with existing code.
>>
>> Thoughts?  Reasons to not apply the patch?
>>
>> Dion
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

jlm@justinfront.net
+1

On 1 Mar 2011, at 00:44, David Peek wrote:

> What about just:
> signaler.bindOnce(someMethod)?
>
> Robert Penners AS3 Signals uses:
> signal.addOnce(listener)


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

Tarwin Stroh-Spijer
In reply to this post by David Peek
Yeah, we use .addOnce in hxs and it makes sense when you write it.


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________


On Tue, Mar 1, 2011 at 10:44 AM, David Peek <[hidden email]> wrote:
What about just:
signaler.bindOnce(someMethod)?

Robert Penners AS3 Signals uses:
signal.addOnce(listener)

On 01/03/2011, at 9:49 AM, Pimm Hogeling wrote:

How about destroyOnUse which returns the bond itself, so you could still do this:
var bond:Bond = someObject.somethingHappenedSignaler.bind(someMethod).destroyOnUse();

What do you think? Is such method chaining common in other haXe libraries?

On 28 February 2011 19:51, Dion Amago <[hidden email]> wrote:
I like your syntax better.

Although it means adding a field to every bond object, rather than
using a different bond class this particular case.  I suppose that's
no much of a penalty.

Dion

On Mon, Feb 28, 2011 at 12:32 PM, Pimm Hogeling <[hidden email]> wrote:
> Thought: an alternative would be adding a method to the bond:
> someObject.somethingHappenedSignaler.bind(someMethod).destroyAfterUse();
>
> On 28 February 2011 19:23, Dion Amago <[hidden email]> wrote:
>>
>> I have a patch for HSL, where you can bind a signal listener that is
>> unbound after the first call.  I find this functionality very useful.
>>
>> public function bind(listener:Datatype -> Dynamic, ?callOnceOnly :Bool
>> = false):Bond;
>>
>> This is backwards compatible with existing code.
>>
>> Thoughts?  Reasons to not apply the patch?
>>
>> Dion
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

Pimm Hogeling
In reply to this post by David Peek
That's another alternative. The penalty there is that it adds three extra methods to the signalers.

On 1 March 2011 00:44, David Peek <[hidden email]> wrote:
What about just:
signaler.bindOnce(someMethod)?

Robert Penners AS3 Signals uses:
signal.addOnce(listener)

On 01/03/2011, at 9:49 AM, Pimm Hogeling wrote:

How about destroyOnUse which returns the bond itself, so you could still do this:
var bond:Bond = someObject.somethingHappenedSignaler.bind(someMethod).destroyOnUse();

What do you think? Is such method chaining common in other haXe libraries?

On 28 February 2011 19:51, Dion Amago <[hidden email]> wrote:
I like your syntax better.

Although it means adding a field to every bond object, rather than
using a different bond class this particular case.  I suppose that's
no much of a penalty.

Dion

On Mon, Feb 28, 2011 at 12:32 PM, Pimm Hogeling <[hidden email]> wrote:
> Thought: an alternative would be adding a method to the bond:
> someObject.somethingHappenedSignaler.bind(someMethod).destroyAfterUse();
>
> On 28 February 2011 19:23, Dion Amago <[hidden email]> wrote:
>>
>> I have a patch for HSL, where you can bind a signal listener that is
>> unbound after the first call.  I find this functionality very useful.
>>
>> public function bind(listener:Datatype -> Dynamic, ?callOnceOnly :Bool
>> = false):Bond;
>>
>> This is backwards compatible with existing code.
>>
>> Thoughts?  Reasons to not apply the patch?
>>
>> Dion
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

Pimm Hogeling
In reply to this post by Tarwin Stroh-Spijer
It seems that that library has a addOnce method, which is similar to the add method, but there are no addOnceAdvanced and addOnceVoid methods. Is there a particular reason why you've chosen not to include these methods?

On 1 March 2011 00:51, Tarwin Stroh-Spijer <[hidden email]> wrote:
Yeah, we use .addOnce in hxs and it makes sense when you write it.


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________



On Tue, Mar 1, 2011 at 10:44 AM, David Peek <[hidden email]> wrote:
What about just:
signaler.bindOnce(someMethod)?

Robert Penners AS3 Signals uses:
signal.addOnce(listener)

On 01/03/2011, at 9:49 AM, Pimm Hogeling wrote:

How about destroyOnUse which returns the bond itself, so you could still do this:
var bond:Bond = someObject.somethingHappenedSignaler.bind(someMethod).destroyOnUse();

What do you think? Is such method chaining common in other haXe libraries?

On 28 February 2011 19:51, Dion Amago <[hidden email]> wrote:
I like your syntax better.

Although it means adding a field to every bond object, rather than
using a different bond class this particular case.  I suppose that's
no much of a penalty.

Dion

On Mon, Feb 28, 2011 at 12:32 PM, Pimm Hogeling <[hidden email]> wrote:
> Thought: an alternative would be adding a method to the bond:
> someObject.somethingHappenedSignaler.bind(someMethod).destroyAfterUse();
>
> On 28 February 2011 19:23, Dion Amago <[hidden email]> wrote:
>>
>> I have a patch for HSL, where you can bind a signal listener that is
>> unbound after the first call.  I find this functionality very useful.
>>
>> public function bind(listener:Datatype -> Dynamic, ?callOnceOnly :Bool
>> = false):Bond;
>>
>> This is backwards compatible with existing code.
>>
>> Thoughts?  Reasons to not apply the patch?
>>
>> Dion
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

jlm@justinfront.net
In reply to this post by Pimm Hogeling
I think it's worthwhile keeping the Signals similarity if you are  
going with a second parameter then it should be an Int.
>
> public function bind(listener:Datatype -> Dynamic, ?live :Int =  
> false):Bond;

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

jlm@justinfront.net
oops

you may need a using trick to allow the second parameter to be  
infinite?   Not sure but obviously can't be what I posted
On 1 Mar 2011, at 01:00, [hidden email] wrote:

> I think it's worthwhile keeping the Signals similarity if you are  
> going with a second parameter then it should be an Int.
>>
>> public function bind(listener:Datatype -> Dynamic, ?live :Int =  
>> false):Bond;
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

justin_mills
In reply to this post by Pimm Hogeling
Does someone have a modified DirectSignaler with bindVoidOnce or simlar
to hand it would be useful.

If not I was wondering if I can swap out HSL for for HXS it would be
ideal for my code to be agnostic since I mainly use a very limited
subset between classes, along the same idea of swapping between tween
engines like I believe openpyro allows, I think it should work to modify
to use HSL and even maybe work towards using a compiler switch, but was
unsure what implications it may have.

// this is what I have at mo

package zpartan.generic.signal;


     import hsl.haxe.direct.DirectSignaler;
     import hsl.haxe.Bond;
     import hsl.haxe.Subject;

     // Used to make HSL more like flash Signals, but also to limit
signals to not passing information.
     class Signal<Datatype> extends DirectSignaler<Datatype>
     {


         public function new( subject:Subject ):Void
         {

             super( subject, false );

         }

        public function addOnce( listener: Void -> Void ): Bond
        {

         /// ??

        }

         public function add( listener:Void -> Void ):Bond
         {

             return bindVoid( listener );

         }


         public function remove( listener:Void -> Void):Void
         {

             unbindVoid( listener );

         }

     }

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

Tarwin Stroh-Spijer
It could work but be warned, hxs has only really been used with Flash (and some CPP output), and doesn't have the idea of externalizing the kind of signaler (ie they have translators between JS / Flash etc keyboard events).

(that is all we've used it for - no idea if anyone else has actually used it ...)

Regards,


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________


On Wed, Mar 2, 2011 at 8:20 PM, justin_mills <[hidden email]> wrote:
Does someone have a modified DirectSignaler with bindVoidOnce or simlar to hand it would be useful.

If not I was wondering if I can swap out HSL for for HXS it would be ideal for my code to be agnostic since I mainly use a very limited subset between classes, along the same idea of swapping between tween engines like I believe openpyro allows, I think it should work to modify to use HSL and even maybe work towards using a compiler switch, but was unsure what implications it may have.

// this is what I have at mo

package zpartan.generic.signal;


   import hsl.haxe.direct.DirectSignaler;
   import hsl.haxe.Bond;
   import hsl.haxe.Subject;

   // Used to make HSL more like flash Signals, but also to limit signals to not passing information.
   class Signal<Datatype> extends DirectSignaler<Datatype>
   {


       public function new( subject:Subject ):Void
       {

           super( subject, false );

       }

      public function addOnce( listener: Void -> Void ): Bond
      {

       /// ??

      }

       public function add( listener:Void -> Void ):Bond
       {

           return bindVoid( listener );

       }


       public function remove( listener:Void -> Void):Void
       {

           unbindVoid( listener );

       }

   }

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

justin_mills
Tarwin

Thanks for getting back to me it's flash project but the switching thing is useful since different projects have different needs... amazingly I slipped your library into a complex system and it works fine not tried the addOnce yet, I think I can simplify my class by removing the Signal<Void> from following your code, which makes thing even simpler, but I have one aspect that troubles me... I can't overwrite your 'add' since mine has a different format so I had to comment out 2 lines of SignalBase, as I did not want to change the code throughout my project, any ideas on alternatives?  I guess I need to also supress methods that my approach does not intend to support, but maybe not vital today, the add thing is important as I do use DirectSignaller directly in one class may end up with two signal libraries used!  So ideas welcome.



    /*
    public function add(listener:T, ?priority:Int=0, ?runCount:Int=-1):Void
    {
        remove(listener);
       
        slots.add(new Slot(listener, SignalType.NORMAL, runCount), priority);
        return new Slot();
       
    }
   
    public function addOnce(listener:T, ?priority:Int = 0):Void
    {
        add(listener, priority, 1);
    }
    */




Have you an idea how I can avoid commenting code out in your library? Here is my wrapper.
 


package zpartan.generic.signal;
   
#if hsl

    import hsl.haxe.direct.DirectSignaler;
    import hsl.haxe.Bond;
    import hsl.haxe.Subject;
   
    // Used to make HSL more like flash Signals, but also to limit signals to not passing information.
    class Signal<Datatype> extends DirectSignaler<Datatype>
    {
       
       
        public function new( subject:Subject ):Void
        {
           
            super( subject, false );
           
        }
       
       
        public function add( listener:Void -> Void ):Bond
        {
           
            return bindVoid( listener );
           
        }
       
       
        public function remove( listener:Void -> Void):Void
        {
           
            unbindVoid( listener );
           
        }
       
    }
 
#else

    import hxs.core.SignalBase;
    import hxs.extras.Trigger;
    import hxs.extras.Trigger;
    import hxs.core.Slot;

    class Signal<DataType> extends SignalBase <Void->Void, Void->Void>
    {

        public function new(?caller:Dynamic)
        {
           
            super( caller );
           
        }
   
        public function dispatch()
        {
            for (slot in slots)
            {
                if (isMuted) return;
                if (slot.isMuted) continue;
                slot.listener();
                onFireSlot(slot);
            }
        }
       
       
        public function add( listener: Void -> Void ):Slot
        {
          
            remove( listener);
           
            var aSlot = new Slot( listener, SignalType.VOID, -1 );
           
            slots.add( aSlot, 0 );
            return aSlot;
           
        }
       
       
        public function addOne( listener: Void -> Void ):Slot
        {
           
            remove( listener );
           
            var aSlot = new Slot( listener, SignalType.VOID, -1 );
           
            slots.add( aSlot, 0 );
            return aSlot;
           
        }
       
        /*
        public function getTrigger():Trigger
        {
            var _this = this;
            return new Trigger( function() _this.dispatch() );
        }
        */
       
    }

#end




--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

justin_mills
Just a note - seems to work fine with static Signals as well :)

Le 02/03/2011 11:40, justin_mills a écrit :
Tarwin

Thanks for getting back to me it's flash project but the switching thing is useful since different projects have different needs... amazingly I slipped your library into a complex system and it works fine not tried the addOnce yet, I think I can simplify my class by removing the Signal<Void> from following your code, which makes thing even simpler, but I have one aspect that troubles me... I can't overwrite your 'add' since mine has a different format so I had to comment out 2 lines of SignalBase, as I did not want to change the code throughout my project, any ideas on alternatives?  I guess I need to also supress methods that my approach does not intend to support, but maybe not vital today, the add thing is important as I do use DirectSignaller directly in one class may end up with two signal libraries used!  So ideas welcome.



    /*
    public function add(listener:T, ?priority:Int=0, ?runCount:Int=-1):Void
    {
        remove(listener);
       
        slots.add(new Slot(listener, SignalType.NORMAL, runCount), priority);
        return new Slot();
       
    }
   
    public function addOnce(listener:T, ?priority:Int = 0):Void
    {
        add(listener, priority, 1);
    }
    */




Have you an idea how I can avoid commenting code out in your library? Here is my wrapper.
 


package zpartan.generic.signal;
   
#if hsl

    import hsl.haxe.direct.DirectSignaler;
    import hsl.haxe.Bond;
    import hsl.haxe.Subject;
   
    // Used to make HSL more like flash Signals, but also to limit signals to not passing information.
    class Signal<Datatype> extends DirectSignaler<Datatype>
    {
       
       
        public function new( subject:Subject ):Void
        {
           
            super( subject, false );
           
        }
       
       
        public function add( listener:Void -> Void ):Bond
        {
           
            return bindVoid( listener );
           
        }
       
       
        public function remove( listener:Void -> Void):Void
        {
           
            unbindVoid( listener );
           
        }
       
    }
 
#else

    import hxs.core.SignalBase;
    import hxs.extras.Trigger;
    import hxs.extras.Trigger;
    import hxs.core.Slot;

    class Signal<DataType> extends SignalBase <Void->Void, Void->Void>
    {

        public function new(?caller:Dynamic)
        {
           
            super( caller );
           
        }
   
        public function dispatch()
        {
            for (slot in slots)
            {
                if (isMuted) return;
                if (slot.isMuted) continue;
                slot.listener();
                onFireSlot(slot);
            }
        }
       
       
        public function add( listener: Void -> Void ):Slot
        {
          
            remove( listener);
           
            var aSlot = new Slot( listener, SignalType.VOID, -1 );
           
            slots.add( aSlot, 0 );
            return aSlot;
           
        }
       
       
        public function addOne( listener: Void -> Void ):Slot
        {
           
            remove( listener );
           
            var aSlot = new Slot( listener, SignalType.VOID, -1 );
           
            slots.add( aSlot, 0 );
            return aSlot;
           
        }
       
        /*
        public function getTrigger():Trigger
        {
            var _this = this;
            return new Trigger( function() _this.dispatch() );
        }
        */
       
    }

#end





--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

Pimm Hogeling
In reply to this post by Tarwin Stroh-Spijer
I would like to point out that I would very much prefer having just one library over being able to switch between the libraries.

Now that HXS also has add, addAdvanced and addVoid, the library is extremely similar to HSL-pico. I guess the main difference between HXS and HSL now is the intentional lack of features (the cross-target keyboard stuff for instance) in HXS for the sake of being smaller and simpler.

Tarwin, I would like to ask you: how often do you use the addOnce method, and how often do miss the addOnceAdvanced and addOnceVoid methods in your projects?

On 2 March 2011 10:33, Tarwin Stroh-Spijer <[hidden email]> wrote:
It could work but be warned, hxs has only really been used with Flash (and some CPP output), and doesn't have the idea of externalizing the kind of signaler (ie they have translators between JS / Flash etc keyboard events).

(that is all we've used it for - no idea if anyone else has actually used it ...)

Regards,



Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________


On Wed, Mar 2, 2011 at 8:20 PM, justin_mills <[hidden email]> wrote:
Does someone have a modified DirectSignaler with bindVoidOnce or simlar to hand it would be useful.

If not I was wondering if I can swap out HSL for for HXS it would be ideal for my code to be agnostic since I mainly use a very limited subset between classes, along the same idea of swapping between tween engines like I believe openpyro allows, I think it should work to modify to use HSL and even maybe work towards using a compiler switch, but was unsure what implications it may have.

// this is what I have at mo

package zpartan.generic.signal;


   import hsl.haxe.direct.DirectSignaler;
   import hsl.haxe.Bond;
   import hsl.haxe.Subject;

   // Used to make HSL more like flash Signals, but also to limit signals to not passing information.
   class Signal<Datatype> extends DirectSignaler<Datatype>
   {


       public function new( subject:Subject ):Void
       {

           super( subject, false );

       }

      public function addOnce( listener: Void -> Void ): Bond
      {

       /// ??

      }

       public function add( listener:Void -> Void ):Bond
       {

           return bindVoid( listener );

       }


       public function remove( listener:Void -> Void):Void
       {

           unbindVoid( listener );

       }

   }

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

Tarwin Stroh-Spijer
Truth to tell I haven't use pico, but from reviewing the source again
just them (albeit on a phone) I find it confusing. There doesn't seem
an easy way to have typed signallers, do you have to wrap it in a
Datatype or something?

Things like addOnce I use all the time. Saves you from having to clean
up your event (signal) once it's been called. Great for thing like
loaders.

On Wednesday, March 2, 2011, Pimm Hogeling <[hidden email]> wrote:

> I would like to point out that I would very much prefer having just one library over being able to switch between the libraries.
>
> Now that HXS also has add, addAdvanced and addVoid, the library is extremely similar to HSL-pico. I guess the main difference between HXS and HSL now is the intentional lack of features (the cross-target keyboard stuff for instance) in HXS for the sake of being smaller and simpler.
>
> Tarwin, I would like to ask you: how often do you use the addOnce method, and how often do miss the addOnceAdvanced and addOnceVoid methods in your projects?
>
> On 2 March 2011 10:33, Tarwin Stroh-Spijer <[hidden email]> wrote:
> It could work but be warned, hxs has only really been used with Flash (and some CPP output), and doesn't have the idea of externalizing the kind of signaler (ie they have translators between JS / Flash etc keyboard events).
>
>
>
>
> (that is all we've used it for - no idea if anyone else has actually used it ...)
> Regards,
>
> Tarwin Stroh-Spijer
> _______________________
>
> Touch My Pixel
> http://www.touchmypixel.com/
> phone: +61 3 8060 5321
> _______________________
>
>
> On Wed, Mar 2, 2011 at 8:20 PM, justin_mills <[hidden email]> wrote:
>
>
> Does someone have a modified DirectSignaler with bindVoidOnce or simlar to hand it would be useful.
>
> If not I was wondering if I can swap out HSL for for HXS it would be ideal for my code to be agnostic since I mainly use a very limited subset between classes, along the same idea of swapping between tween engines like I believe openpyro allows, I think it should work to modify to use HSL and even maybe work towards using a compiler switch, but was unsure what implications it may have.
>
> // this is what I have at mo
>
> package zpartan.generic.signal;
>
>
>     import hsl.haxe.direct.DirectSignaler;
>     import hsl.haxe.Bond;
>     import hsl.haxe.Subject;
>
>     // Used to make HSL more like flash Signals, but also to limit signals to not passing information.
>     class Signal<Datatype> extends DirectSignaler<Datatype>
>     {
>
>
>         public function new( subject:Subject ):Void
>         {
>
>             super( subject, false );
>
>         }
>
>        public function addOnce( listener: Void -> Void ): Bond
>        {
>
>         /// ??
>
>        }
>
>         public function add( listener:Void -> Void ):Bond
>         {
>
>             return bindVoid( listener );
>
>         }
>
>
>         public function remove( listener:Void -> Void):Void
>         {
>
>             unbindVoid( listener );
>
>         }
>
>     }
>
>
> --
>
> haXe - an open source web programming language
> http://haxe.org
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
>

--


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

Pimm Hogeling
On 2 March 2011 22:31, Tarwin Stroh-Spijer <[hidden email]> wrote:
Truth to tell I haven't use pico, but from reviewing the source again
just them (albeit on a phone) I find it confusing. There doesn't seem
an easy way to have typed signallers, do you have to wrap it in a
Datatype or something?
Nope, it works exactly the same as it does in HXS. Almost everything works exactly the same as it does in HXS. The one exception is the way dispatching multiple data objects works, which used to be the same as well but was changed due to requests from other developers (source, source). In fact, even things like HXS' mute test on Google Code can be rewritten to HSL syntax with only a few tweaks:
var s1 = new DirectSignaler<Int>(this);
var bond = s1.bindAdvanced(function(signal) {
    trace("test muting signal - step: " + signal.data);
   
    signal.currentBond.halt();
});

// first one will dispatch
s1.dispatch(1);

// bond is halted after accesing it via the Signal object - this dispatch will not occur
s1.dispatch(2);

// manually access the bond and tell it to be resumed
bond.resume();

// final dispatch will now occur
s1.dispatch(3);

The only real difference here is that in HSL you can halt a bond, while in HXS you can mute an entire signal.

Back on-topic.

On 2 March 2011 22:31, Tarwin Stroh-Spijer <[hidden email]> wrote:
Things like addOnce I use all the time. Saves you from having to clean
up your event (signal) once it's been called. Great for thing like
loaders.
I understand the advantage, yes. Several people now have mentioned wanting this feature, so it will be added. I'm simply looking for the best way to do it.

It seems that your implementation only supports once-listeners that are "regular" (as opposed to "advanced" or "void"). I was wondering whether the lack of addOnceAdvanced and addOnceVoid method is intentional. If so (and there's a good reason for it), we might take the same approach.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HSL: bind a signal once (destroyed after the first dispatch)

Pimm Hogeling
In reply to this post by Dion Whitehead Amago
I am very pleased to announce that Dion's idea has been implemented, committed to Google Code and submitted to haxelib.

The official support for HSL has been extended to one year from this day (5th of March).

On 28 February 2011 19:23, Dion Amago <[hidden email]> wrote:
I have a patch for HSL, where you can bind a signal listener that is
unbound after the first call.  I find this functionality very useful.

public function bind(listener:Datatype -> Dynamic, ?callOnceOnly :Bool
= false):Bond;

This is backwards compatible with existing code.

Thoughts?  Reasons to not apply the patch?

Dion

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org