Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A library inspired by the C# Rx framework.
ActionScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
lib
src/com/aemon/observer
MIT-LICENSE
README
Rakefile

README

An AS3 library inspired by the C# Rx framework. Just a proof of concept so far.





Here's how you might synthesize a mouseDrag event:


var circle:Sprite = new Sprite();

var mouseDown:IObservable = Obs.es(circle, "onMouseDown");
var mouseMove:IObservable = Obs.es(circle, "onMouseMove");
var mouseUp:IObservable = Obs.es(circle, "onMouseUp");

var mouseDrag:IObservable = mouseDown.selectMany(function(ea:Event):IObservable{
		return mouseMove.until(mouseUp).select(function(ea:Event):Event{ return new Event("onMouseDrag"); });
	});

mouseDrag.attach(Obs.f(function(ea:String):void{
			trace("Just got a drag event!");
		}));





Here's a 3 key sequence, automatically cancelled if the wrong key is pressed.


// Helper for making an IObservable of key events of a specific type
function keyStream(key:int):IObservable{
	 return Obs.es(stage, "onKeyDown").select(function(e:KeyboardEvent):Boolean{ return e.keyCode == key; })
}

// Helper for making an IObservable of key events that are NOT a specific type
function notKeyStream(key:int):IObservable{
	 return Obs.es(stage, "onKeyDown").select(function(e:KeyboardEvent):Boolean{ return e.keyCode != key; })
}

// Wait for an 'a'
var abcPressed:IObservable = keyStream(Keyboard.A).selectMany(function(ea:Event):IObservable{
                // then wait for a 'b', but cancel if something else is pressed 
		return keyStream(Keyboard.B).until(notKeyStream(Keyboard.B)).selectMany(function(ea:Event):IObservable{
                  // then wait for a 'c', but cancel if something else is pressed 
		  return keyStream(Keyboard.C).until(notKeyStream(Keyboard.C)).select(function(ea:Event):Event{ 
		    // dispatch the our new event
		    return new Event("onABC"); 
		  });
	       });
	});

abcPressed.attach(Obs.f(function(ea:Event):void{
			trace("a,b,c has been pressed!");
		}));
Something went wrong with that request. Please try again.