Comparing version 1.0.0 to 1.0.1
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var extend = require('js-extend').extend; | ||
var EventEmitter = require('wolfy87-eventemitter'); | ||
(function (global){ | ||
(function() { | ||
var extend = require('js-extend').extend; | ||
var EventEmitter = require('wolfy87-eventemitter'); | ||
var root = global || window; | ||
function TruthinessMonitor () { | ||
this.intervals = {}; | ||
} | ||
TruthinessMonitor.prototype.add = function (predicate, event, delay) { | ||
if (this.intervals[event]) { | ||
throw new Error('You have already registered to watch for a truth with that event'); | ||
function TruthinessMonitor() { | ||
this.intervals = {}; | ||
} | ||
if (predicate()) { | ||
this.trigger(event); | ||
return; | ||
} | ||
TruthinessMonitor.prototype.add = function(predicate, event, delay) { | ||
if (!event) { | ||
throw new Error('You must supply an event with your predicate'); | ||
} | ||
this.intervals[event] = setInterval(function () { | ||
if (this.intervals[event]) { | ||
throw new Error('You have already registered to watch for a truth with that event'); | ||
} | ||
if (predicate()) { | ||
this.trigger(event); | ||
clearTimeout(this.intervals[event]); | ||
delete this.intervals[event]; | ||
return; | ||
} | ||
}.bind(this), delay); | ||
}; | ||
extend(TruthinessMonitor.prototype, EventEmitter.prototype); | ||
this.intervals[event] = setInterval(function() { | ||
if (predicate()) { | ||
this.trigger(event); | ||
clearTimeout(this.intervals[event]); | ||
delete this.intervals[event]; | ||
} | ||
}.bind(this), delay); | ||
}; | ||
function create() { | ||
return new TruthinessMonitor(); | ||
} | ||
extend(TruthinessMonitor.prototype, EventEmitter.prototype); | ||
module.exports = create; | ||
function create() { | ||
return new TruthinessMonitor(); | ||
} | ||
module.exports = create; | ||
// Export the create function for **Node.js** or other | ||
// commonjs systems. Otherwise, add it as a global object to the root | ||
if (typeof exports !== 'undefined') { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
exports = module.exports = create; | ||
} | ||
exports.create = create; | ||
} | ||
if (typeof window !== 'undefined') { | ||
window.wen = create; | ||
} | ||
}).call(this); | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{"js-extend":2,"wolfy87-eventemitter":3}],2:[function(require,module,exports){ | ||
@@ -36,0 +57,0 @@ (function() { |
@@ -1,1 +0,1 @@ | ||
(function e(t,n,r){function o(a,f){if(!n[a]){if(!t[a]){var l=typeof require==i&&require;if(!f&&l)return l(a,!0);if(u)return u(a,!0);var p=new Error("Cannot find module '"+a+"'");throw p.code="MODULE_NOT_FOUND",p}var d=n[a]={exports:{}};t[a][0].call(d[s],function(e){var n=t[a][1][e];return o(n?n:e)},d,d[s],e,t,n,r)}return n[a][s]}var i="function",s="exports",u=typeof require==i&&require;for(var a=0;a<r.length;a++)o(r[a]);return o})({1:[function(e,t,n){function u(){this[r]={}}function a(){return new u}var r="intervals",i="prototype",s=e("js-extend").extend,o=e("wolfy87-eventemitter");u[i].add=function(e,t,n){if(this[r][t])throw new Error("You have already registered to watch for a truth with that event");if(e()){this.trigger(t);return}this[r][t]=setInterval(function(){e()&&(this.trigger(t),clearTimeout(this[r][t]),delete this[r][t])}.bind(this),n)},s(u[i],o[i]),t.exports=a},{"js-extend":2,"wolfy87-eventemitter":3}],2:[function(e,t,n){(function(){var e=Array.prototype.slice,t=Array.prototype.forEach,n=function(r){if(typeof r!="object")throw r+" is not an object";var i=e.call(arguments,1);return t.call(i,function(e){if(e)for(var t in e)typeof e[t]=="object"&&r[t]?n.call(r,r[t],e[t]):r[t]=e[t]}),r};this.extend=n}).call(this)},{}],3:[function(e,t,n){var r="call",i="EventEmitter",s="length",o="listener",u="getListeners",a="_getEvents",f="object",l="hasOwnProperty",c="getListenersAsObject",h="addListener",p="addOnceListener",d=!0,v="defineEvent",m="removeListener",g="addListeners",y="manipulateListeners",b="removeListeners",w="function",E="removeEvent",S="_events",x="emitEvent",T="_getOnceReturnValue",N="_onceReturnValue";((function(){"use strict";function e(){}function L(e,t){var n=e[s];while(n--)if(e[n][o]===t)return n;return-1}function A(e){return function(){return this[e].apply(this,arguments)}}var n=e.prototype,C=this,k=C[i];n[u]=function(t){var n=this[a](),r,i;if(typeof t===f){r={};for(i in n)n[l](i)&&t.test(i)&&(r[i]=n[i])}else r=n[t]||(n[t]=[]);return r},n.flattenListeners=function(t){var n=[],r;for(r=0;r<t[s];r+=1)n.push(t[r][o]);return n},n[c]=function(t){var n=this[u](t),r;return n instanceof Array&&(r={},r[t]=n),r||n},n[h]=function(t,n){var r=this[c](t),i=typeof n===f,s;for(s in r)r[l](s)&&L(r[s],n)===-1&&r[s].push(i?n:{listener:n,once:!1});return this},n.on=A(h),n[p]=function(t,n){return this[h](t,{listener:n,once:d})},n.once=A(p),n[v]=function(t){return this[u](t),this},n.defineEvents=function(t){for(var n=0;n<t[s];n+=1)this[v](t[n]);return this},n[m]=function(t,n){var r=this[c](t),i,s;for(s in r)r[l](s)&&(i=L(r[s],n),i!==-1&&r[s].splice(i,1));return this},n.off=A(m),n[g]=function(t,n){return this[y](!1,t,n)},n[b]=function(t,n){return this[y](d,t,n)},n[y]=function(t,n,i){var o,u,a=t?this[m]:this[h],c=t?this[b]:this[g];if(typeof n!==f||n instanceof RegExp){o=i[s];while(o--)a[r](this,n,i[o])}else for(o in n)n[l](o)&&(u=n[o])&&(typeof u===w?a[r](this,o,u):c[r](this,o,u));return this},n[E]=function(t){var n=typeof t,r=this[a](),i;if(n==="string")delete r[t];else if(n===f)for(i in r)r[l](i)&&t.test(i)&&delete r[i];else delete this[S];return this},n.removeAllListeners=A(E),n[x]=function(t,n){var r=this[c](t),i,u,a,f;for(a in r)if(r[l](a)){u=r[a][s];while(u--)i=r[a][u],i.once===d&&this[m](t,i[o]),f=i[o].apply(this,n||[]),f===this[T]()&&this[m](t,i[o])}return this},n.trigger=A(x),n.emit=function(t){var n=Array.prototype.slice[r](arguments,1);return this[x](t,n)},n.setOnceReturnValue=function(t){return this[N]=t,this},n[T]=function(){return this[l](N)?this[N]:d},n[a]=function(){return this[S]||(this[S]={})},e.noConflict=function(){return C[i]=k,e},typeof define===w&&define.amd?define(function(){return e}):typeof t===f&&t.exports?t.exports=e:this[i]=e}))[r](this)},{}]},{},[1]); | ||
(function e(t,n,r){function o(a,f){if(!n[a]){if(!t[a]){var l=typeof require==i&&require;if(!f&&l)return l(a,!0);if(u)return u(a,!0);var p=new Error("Cannot find module '"+a+"'");throw p.code="MODULE_NOT_FOUND",p}var d=n[a]={exports:{}};t[a][0].call(d[s],function(e){var n=t[a][1][e];return o(n?n:e)},d,d[s],e,t,n,r)}return n[a][s]}var i="function",s="exports",u=typeof require==i&&require;for(var a=0;a<r.length;a++)o(r[a]);return o})({1:[function(e,t,n){var r="intervals",i="prototype",s="exports",o="undefined";(function(u){(function(){function c(){this[r]={}}function h(){return new c}var a=e("js-extend").extend,f=e("wolfy87-eventemitter"),l=u||window;c[i].add=function(e,t,n){if(!t)throw new Error("You must supply an event with your predicate");if(this[r][t])throw new Error("You have already registered to watch for a truth with that event");if(e()){this.trigger(t);return}this[r][t]=setInterval(function(){e()&&(this.trigger(t),clearTimeout(this[r][t]),delete this[r][t])}.bind(this),n)},a(c[i],f[i]),t[s]=h,typeof n!==o&&(typeof t!==o&&t[s]&&(n=t[s]=h),n.create=h),typeof window!==o&&(window.wen=h)}).call(this)}).call(this,typeof global!==o?global:typeof self!==o?self:typeof window!==o?window:{})},{"js-extend":2,"wolfy87-eventemitter":3}],2:[function(e,t,n){(function(){var e=Array.prototype.slice,t=Array.prototype.forEach,n=function(r){if(typeof r!="object")throw r+" is not an object";var i=e.call(arguments,1);return t.call(i,function(e){if(e)for(var t in e)typeof e[t]=="object"&&r[t]?n.call(r,r[t],e[t]):r[t]=e[t]}),r};this.extend=n}).call(this)},{}],3:[function(e,t,n){var r="call",i="EventEmitter",s="length",o="listener",u="getListeners",a="_getEvents",f="object",l="hasOwnProperty",c="getListenersAsObject",h="addListener",p="addOnceListener",d=!0,v="defineEvent",m="removeListener",g="addListeners",y="manipulateListeners",b="removeListeners",w="function",E="removeEvent",S="_events",x="emitEvent",T="_getOnceReturnValue",N="_onceReturnValue";((function(){"use strict";function e(){}function L(e,t){var n=e[s];while(n--)if(e[n][o]===t)return n;return-1}function A(e){return function(){return this[e].apply(this,arguments)}}var n=e.prototype,C=this,k=C[i];n[u]=function(t){var n=this[a](),r,i;if(typeof t===f){r={};for(i in n)n[l](i)&&t.test(i)&&(r[i]=n[i])}else r=n[t]||(n[t]=[]);return r},n.flattenListeners=function(t){var n=[],r;for(r=0;r<t[s];r+=1)n.push(t[r][o]);return n},n[c]=function(t){var n=this[u](t),r;return n instanceof Array&&(r={},r[t]=n),r||n},n[h]=function(t,n){var r=this[c](t),i=typeof n===f,s;for(s in r)r[l](s)&&L(r[s],n)===-1&&r[s].push(i?n:{listener:n,once:!1});return this},n.on=A(h),n[p]=function(t,n){return this[h](t,{listener:n,once:d})},n.once=A(p),n[v]=function(t){return this[u](t),this},n.defineEvents=function(t){for(var n=0;n<t[s];n+=1)this[v](t[n]);return this},n[m]=function(t,n){var r=this[c](t),i,s;for(s in r)r[l](s)&&(i=L(r[s],n),i!==-1&&r[s].splice(i,1));return this},n.off=A(m),n[g]=function(t,n){return this[y](!1,t,n)},n[b]=function(t,n){return this[y](d,t,n)},n[y]=function(t,n,i){var o,u,a=t?this[m]:this[h],c=t?this[b]:this[g];if(typeof n!==f||n instanceof RegExp){o=i[s];while(o--)a[r](this,n,i[o])}else for(o in n)n[l](o)&&(u=n[o])&&(typeof u===w?a[r](this,o,u):c[r](this,o,u));return this},n[E]=function(t){var n=typeof t,r=this[a](),i;if(n==="string")delete r[t];else if(n===f)for(i in r)r[l](i)&&t.test(i)&&delete r[i];else delete this[S];return this},n.removeAllListeners=A(E),n[x]=function(t,n){var r=this[c](t),i,u,a,f;for(a in r)if(r[l](a)){u=r[a][s];while(u--)i=r[a][u],i.once===d&&this[m](t,i[o]),f=i[o].apply(this,n||[]),f===this[T]()&&this[m](t,i[o])}return this},n.trigger=A(x),n.emit=function(t){var n=Array.prototype.slice[r](arguments,1);return this[x](t,n)},n.setOnceReturnValue=function(t){return this[N]=t,this},n[T]=function(){return this[l](N)?this[N]:d},n[a]=function(){return this[S]||(this[S]={})},e.noConflict=function(){return C[i]=k,e},typeof define===w&&define.amd?define(function(){return e}):typeof t===f&&t.exports?t.exports=e:this[i]=e}))[r](this)},{}]},{},[1]); |
@@ -1,33 +0,52 @@ | ||
var extend = require('js-extend').extend; | ||
var EventEmitter = require('wolfy87-eventemitter'); | ||
(function() { | ||
var extend = require('js-extend').extend; | ||
var EventEmitter = require('wolfy87-eventemitter'); | ||
var root = global || window; | ||
function TruthinessMonitor () { | ||
this.intervals = {}; | ||
} | ||
TruthinessMonitor.prototype.add = function (predicate, event, delay) { | ||
if (this.intervals[event]) { | ||
throw new Error('You have already registered to watch for a truth with that event'); | ||
function TruthinessMonitor() { | ||
this.intervals = {}; | ||
} | ||
if (predicate()) { | ||
this.trigger(event); | ||
return; | ||
} | ||
TruthinessMonitor.prototype.add = function(predicate, event, delay) { | ||
if (!event) { | ||
throw new Error('You must supply an event with your predicate'); | ||
} | ||
this.intervals[event] = setInterval(function () { | ||
if (this.intervals[event]) { | ||
throw new Error('You have already registered to watch for a truth with that event'); | ||
} | ||
if (predicate()) { | ||
this.trigger(event); | ||
clearTimeout(this.intervals[event]); | ||
delete this.intervals[event]; | ||
return; | ||
} | ||
}.bind(this), delay); | ||
}; | ||
extend(TruthinessMonitor.prototype, EventEmitter.prototype); | ||
this.intervals[event] = setInterval(function() { | ||
if (predicate()) { | ||
this.trigger(event); | ||
clearTimeout(this.intervals[event]); | ||
delete this.intervals[event]; | ||
} | ||
}.bind(this), delay); | ||
}; | ||
function create() { | ||
return new TruthinessMonitor(); | ||
} | ||
extend(TruthinessMonitor.prototype, EventEmitter.prototype); | ||
module.exports = create; | ||
function create() { | ||
return new TruthinessMonitor(); | ||
} | ||
module.exports = create; | ||
// Export the create function for **Node.js** or other | ||
// commonjs systems. Otherwise, add it as a global object to the root | ||
if (typeof exports !== 'undefined') { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
exports = module.exports = create; | ||
} | ||
exports.create = create; | ||
} | ||
if (typeof window !== 'undefined') { | ||
window.wen = create; | ||
} | ||
}).call(this); |
{ | ||
"name": "wen", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Triggers events based on the truthiness of predicate methods", | ||
@@ -5,0 +5,0 @@ "main": "lib/wen.js", |
@@ -37,3 +37,3 @@ # wen | ||
``` | ||
<script src="https://raw.githubusercontent.com/basicallydan/wen/master/dist/wen.1.0.0.min.js"></script> | ||
<script src="https://raw.githubusercontent.com/basicallydan/wen/master/dist/wen.1.0.1.min.js"></script> | ||
<!-- If I want to do this properly I will download it and place it in my source code somewhere --> | ||
@@ -59,2 +59,7 @@ ``` | ||
## Changes | ||
* 1.0.1: I forgot to make it browser friendly and didn't account for a dev error which I should've done. Now I have. | ||
* 1.0.0: First. | ||
## "FAQ" | ||
@@ -61,0 +66,0 @@ |
@@ -78,3 +78,9 @@ var should = require('should'); | ||
}); | ||
it('should throw an error if you do not supply an event', function () { | ||
should(function () { | ||
truthy.add(function () {}); | ||
}).throw(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is too big to display
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
321908
18
10272
75