Comparing version 0.1.3 to 0.1.4
@@ -14,3 +14,3 @@ // eventSky.js - Event Aggregate utility/tool for front-end apps | ||
var GLOBAL = window || GLOBAL || {}; | ||
var GLOBAL_SCOPE = typeof(window)!=='undefined' ? 'window' : 'global'; | ||
@@ -100,3 +100,2 @@ var namespace = 'eventSky'; | ||
handlerMethod, | ||
ctx, | ||
eventListenerId = generateEventId(); | ||
@@ -106,8 +105,7 @@ | ||
optionsObj = (options && typeof options != 'function') ? options : null; | ||
handlerMethod = (!optionsObj) ? options : (handler && (typeof handler === 'function')) ? handler : null; | ||
ctx = (context) ? context : (handler) ? handler : null; | ||
handlerMethod = (optionsObj) ? optionsObj : (!handler) ? options : null; | ||
//check if context is specified and bind to handlerMethod | ||
if (ctx) { | ||
handlerMethod = handlerMethod.bind(ctx); | ||
if (context) { | ||
handlerMethod = handlerMethod.bind(context); | ||
} | ||
@@ -161,23 +159,15 @@ | ||
* @param {object} options [not used currently] | ||
* @return {string/array} Returns the event/eventId or array of events | ||
* removed | ||
*/ | ||
var off = function (eventOrId, options) { | ||
var returnValue;//string or array | ||
// if eventOrId is object/array | ||
if (typeof eventOrId === 'object') { | ||
returnValue = []; | ||
firehose('off invoked with object: ',eventOrId); | ||
Object.keys(eventOrId).forEach(function (key) { | ||
removeEvent(eventOrId[key]); | ||
returnValue.push(key); | ||
}); | ||
} | ||
else if (eventOrId instanceof Array) { | ||
returnValue = []; | ||
firehose('off invoked with array: ',eventOrId); | ||
eventOrId.forEach(function (i) { | ||
removeEvent(eventOrId[i]); | ||
returnValue.push(eventOrId[i]); | ||
}); | ||
@@ -187,7 +177,4 @@ } | ||
removeEvent(eventOrId); | ||
returnValue = eventOrId; | ||
} | ||
return returnValue; | ||
function removeEvent(e) { | ||
@@ -240,3 +227,3 @@ firehose('removeEvent: ', e); | ||
// Exposed methods | ||
GLOBAL[namespace] = { | ||
var API = { | ||
init : init, | ||
@@ -260,2 +247,5 @@ // subscribe to an event | ||
}; | ||
// expose to global scope | ||
GLOBAL_SCOPE === 'window' ? window[namespace] = API : global[namespace] = API; | ||
})(); |
74
mixin.js
@@ -1,27 +0,24 @@ | ||
/************************************************* | ||
* This is event-sky built as a React mixin * * * | ||
* * * | ||
* Description * * | ||
* We first check if the window object is * * | ||
* available and has our event module * * | ||
* iniitialized, if it's not then we * * | ||
* iniitializ or then check GLOBAL because * * | ||
* we might be on server/node or other env * * | ||
then we add mixin utility methods * | ||
for the react component using the mixin * | ||
*************************************************/ | ||
/********************************************** | ||
* This is event-sky built as a React mixin * * | ||
* * | ||
* Description * | ||
* We first check if the window object is * | ||
* available and has our event module * | ||
* iniitialized, if it's not then we * | ||
* iniitializ or then check GLOBAL because * | ||
* we might be on server/node or other env * | ||
* * | ||
***********************************************/ | ||
var _ = require('underscore'); | ||
var namespace; | ||
var eventSkyModule; | ||
// check if we're in a browser environment | ||
if (window) { | ||
if (typeof(window)!=='undefined') { | ||
if (!window.eventSky) { | ||
require('event-sky'); | ||
if (!window.eventSky) { | ||
new Error('eventSky is not initialized and cannot be found with "require(\'event-sky\')"'); | ||
throw new Error('eventSky is not initialized and cannot be found with "require(\'event-sky\')"'); | ||
} | ||
} | ||
eventSkyModule = window.eventSky; | ||
namespace = window.eventSky; | ||
} | ||
@@ -37,43 +34,8 @@ // assume we're serverSide, phonegap or other environment | ||
if (!GLOBAL.eventSky) { | ||
new Error('eventSky is not initialized and cannot be found with "require(\'event-sky\')"'); | ||
throw new Error('eventSky is not initialized and cannot be found with "require(\'event-sky\')"'); | ||
} | ||
} | ||
eventSkyModule = GLOBAL.eventSky; | ||
namespace = GLOBAL.eventSky; | ||
} | ||
// // turn off all listeners and remove the keys from eventSkyModule/this.listeners | ||
// // ** this.listeners must exist in the component.. | ||
// eventSkyModule.listenersOff = function() { | ||
// if (this.listeners) { | ||
// Object.keys(self.listeners).forEach(function (i) { | ||
// self.off(self.listeners[i]); | ||
// delete self.listeners[i]; | ||
// },this); | ||
// return true; | ||
// } | ||
// else { | ||
// console.warn('eventSky.js [mixin] could not completed "this.listeners.off() because this.listeners does not exists."'); | ||
// console.warn('this:',self); | ||
// } | ||
// }; | ||
// | ||
// // append functionality to eventSky.off method for the React eventSkyModule to | ||
// // remove the key from eventSkyModule/this.listeners when this.off is invoked | ||
// var nativeOff = eventSkyModule.off; | ||
// eventSkyModule.off = function(eventObjOrId) { | ||
// var self = this;// this being the component including the mixin | ||
// // invoke native off method | ||
// var events = nativeOff(eventObjOrId); | ||
// // remove events from component/this.listeners | ||
// if (events instanceof Array) { | ||
// events.forEach(function (i) { | ||
// delete self.listeners[events[i]]; | ||
// }); | ||
// } | ||
// // assume it's a string/single eventOrId | ||
// else { | ||
// delete self[events]; | ||
// } | ||
// }; | ||
module.exports = eventSkyModule; | ||
module.exports = namespace; |
{ | ||
"name": "event-sky", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "front-end event pub/sub utility", | ||
@@ -5,0 +5,0 @@ "main": "eventSky.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
13522
263