jerolimov / EventEmitter

Node.js inspired EventEmitter for Objective C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Objective C EventEmitter

Node.js inspired EventEmitter for Objective C.

Build Status CocoaPods Compatible Supported Platforms

How to use it

Copy the EventEmitter class into your project or add this line to your Podfile:

pod 'EventEmitter', '~> 0.1.3'

Quick API overview

Register event listener on any object:

#import "EventEmitter.h"

NSObject* emitter = [[NSObject alloc] init];

__block BOOL ready = NO;

[emitter on:@"ready" notify:^() {
	NSLog(@"Yepp! The object is ready now!");
	ready = YES;
}];

[emitter on:@"event" callback:^(NSDictionary* data) {
	if (ready) {
		NSLog(@"Receive event with data: %@", data);
	}
}];

And later fire an event to the same object:

#import "EventEmitter.h"

NSObject* emitter = ...;

[emitter emit:@"ready"];

[emitter emit:@"event" data:@{
	@"type": @"somethinghappend",
	@"another key": @"another value",
}];

Implementation details

About

Node.js inspired EventEmitter for Objective C

License:Apache License 2.0


Languages

Language:Objective-C 96.0%Language:Ruby 4.0%