Every line of 'eventemitter2' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
3 function EventEmitter() { 4 if (!(this instanceof EventEmitter)) return new EventEmitter(); 5 6 this._events = null; 7 8 if (typeof(process) !== 'undefined' && typeof(process.nextTick) !== 'undefined') { 9 this._deferer = function(cb, topic, args) { 10 process.nextTick(function() { cb(topic, args); } ); 11 }; 12 } else { 13 this._deferer = function(cb, topic, args) { 14 setTimeout(function () {cb(topic, args); }, 0); 15 }; 16 } 17 };
1 export default function EventEmitter(Rx) { 2 return { 3 getSubject, 4 createSubject, 5 getObservable, 6 createObservable 7 }; 8 9 function getSubject() { 10 return Rx.Subject; 11 } 12 13 /** 14 * Returns a new instance of the event subject object. 15 * The objects needs to implement the following methods: 16 * - next() 17 * - dispose() 18 * - subscribe() 19 * - scan() 20 * 21 * @param args {Mixed=} 22 * @returns {Rx.Subject} 23 */ 24 function createSubject() { 25 return new Rx.Subject(); 26 } 27 28 function getObservable() { 29 return Rx.Observable; 30 } 31 32 /** 33 * Returns a new instance the event observable object. 34 * It defines an object which can be used for an observer 35 * @param args {Mixed=} 36 * @returns {Rx.Observable} 37 */ 38 function createObservable() { 39 return new Rx.Observable(); 40 } 41 }
4 function MyEventEmitter() { 5 EventEmitter.call(this); 6 7 doFirstJob(); 8 setImmediate(() => this.emit('myEvent')); 9 }
23 public emit(event: K, arg: T[K]) { 24 if (!this.listeners[event]) return 25 this.listeners[event].forEach(listener => listener(arg)) 26 }
13 public emit(event: string, ...args: any[]): void { 14 if (this.events[event]) this.events[event](...args) 15 }
24 function eventEmitter(){ 25 26 var noop = () => {}; 27 28 if(typeof window !== 'undefined'){ 29 function broadcast(eventName, eventObject){ 30 31 //Set a break point on the following line to monitor all events being broadcast 32 console.log('Event broadcast: '+ eventName); 33 events.emit(eventName, eventObject); 34 } 35 36 function on(eventName, cb){ 37 38 //Set a break point on the following line to monitor all events being listened to 39 events.on(eventName, cb); 40 } 41 42 function once(eventName, cb){ 43 44 //Set a break point on the following line to monitor all events being listened to just once 45 events.once(eventName, cb); 46 } 47 48 function off(eventName, listenerFunction){ 49 50 //Set a break point on the following line to monitor all events being unlistened to 51 events.off(eventName, listenerFunction); 52 } 53 54 return { 55 broadcast: broadcast, 56 on: on, 57 once: once, 58 off: off 59 } 60 }else{ 61 return { 62 broadcast: noop, 63 on: noop, 64 once: noop, 65 off: noop 66 } 67 } 68 69 }
19 public emit(event: EventType) { 20 this.subscribers.forEach(subscriber => subscriber.handleEvent(event)); 21 }
29 emit(event, ...args) { 30 if (typeof this.events[event] === 'object') { 31 this.events[event].forEach(listener => listener.apply(this, args)); 32 } 33 }
97 public emit(event: string, ...args: any[]): void { 98 if (typeof this.events[event] === 'object') { 99 ;[...this.events[event]].forEach(listener => listener.apply(this, args)) 100 } 101 102 ;[...this.events['*']].forEach(listener => 103 listener.apply(this, [event, ...args]) 104 ) 105 }
8 constructor() { 9 this.emitter = new EventEmitter() 10 11 return this.emitter 12 }