src/nopg.js
function create_tcn_listener(events, when) {

	debug.assert(events).is('object');
	debug.assert(when).is('object');

	// Normalize event object back to event name
	var when_str = NoPg.stringifyEventName(when);

	return function tcn_listener(payload) {
		payload = NoPg.parseTCNPayload(payload);
		var event = tcn_event_mapping[''+payload.table+','+payload.op];

		if(!event) {
			debug.warn('Could not find event name for payload: ', payload);
			return;
		}

		// Verify we don't emit, if matching id enabled and does not match
		if( when.hasOwnProperty('id') && (payload.keys.id !== when.id) ) {
			return;
		}

		// Verify we don't emit, if matching event name enabled and does not match
		if( when.hasOwnProperty('name') && (event !== when.name) ) {
			return;
		}

		events.emit(when_str, payload.keys.id, event, when.type);
	};
}
function create_tcn_listener(events, when) {

	debug.assert(events).is('object');
	debug.assert(when).is('object');

	// Normalize event object back to event name
	var when_str = NoPg.stringifyEventName(when);

	return function tcn_listener(payload) {
		payload = NoPg.parseTCNPayload(payload);
		var event = tcn_event_mapping[''+payload.table+','+payload.op];

		if(!event) {
			debug.warn('Could not find event name for payload: ', payload);
			return;
		}

		// Verify we don't emit, if matching id enabled and does not match
		if( when.hasOwnProperty('id') && (payload.keys.id !== when.id) ) {
			return;
		}

		// Verify we don't emit, if matching event name enabled and does not match
		if( when.hasOwnProperty('name') && (event !== when.name) ) {
			return;
		}

		events.emit(when_str, payload.keys.id, event, when.type);
	};
}
function create_tcn_listener ( events , when ) { debug . assert ( events ) . is ( 'object' ) ; debug . assert ( when ) . is ( 'object' ) ; // Normalize event object back to event name var when_str = NoPg . stringifyEventName ( when ) ; return function tcn_listener ( payload ) { payload = NoPg . parseTCNPayload ( payload ) ; var event = tcn_event_mapping [ '' + payload . table + ',' + payload . op ] ; if ( ! event ) { debug . warn ( 'Could not find event name for payload: ' , payload ) ; return ; } // Verify we don't emit, if matching id enabled and does not match if ( when . hasOwnProperty ( 'id' ) && ( payload . keys . id !== when . id ) ) { return ; } // Verify we don't emit, if matching event name enabled and does not match if ( when . hasOwnProperty ( 'name' ) && ( event !== when . name ) ) { return ; } events . emit ( when_str , payload . keys . id , event , when . type ) ; } ; }
Returns a listener for notifications from TCN extension
@param events {EventEmitter} The event emitter where we should trigger matching events.
@param when {object} We should only trigger events that match this specification. Object with optional properties
`type`, `id` and `name`.
Returns a listener for notifications from TCN extension