Snip2Code is shutting down.
It has been quite a ride, since 2013 when we launched our first prototype: thanks to the effort of you guys we collected more than 3 million snippets!
We are very proud to help all our users to be more efficient in their jobs, and to be the central point to share programming knowledge for everyone.
Our basic service is free, so we always survived on our own resources to give you Snip2Code.
Unfortunately, we are no more in the financial position to sustain this effort, and therefore we are announcing here our permanent shut down,
which will take place on August 1st, 2020.
Please save your private snippets using our backup function in the settings, here.
IF YOU WANT TO SAVE SNIP2CODE, PLEASE CONSIDER DOING A DONATION!
This will allow us to pay for the servers and the infrastructure. If you want to donate, Contact Us!
by
24
7
445k
3
Top 1% !
Pearl of Wisdom
Nice
Useful
Easy-to-find
Specified
MultiPlatform
Popularity: 1680th place
LanguageJavaScript
LicenseMIT_X11
SourceGitHub
SourceMyGists

Signals.js...           A fast and efficient event system in javascript.

Signals.js...           A fast and efficient event system in javascript.: 
Signals.js
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/231230/Signals-js--------------A-fast-and-effic?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Signalz.js var Signals = (function () { 'use strict'; var sigCache = {}, addReceiver = function(eventName, func) { return wen(eventName, function(evnt){ return func(evnt); }); }, signalReceived = function(eventName, func) { return wen(eventName, function(evnt){ return func(evnt); }); }, dropReceivers = function (eventName) { if (!eventName) { sigCache = {}; return this; } if (sigCache && sigCache[eventName]) { sigCache[eventName] = null; } return this; }, signalOnce = function (eventName, func) { var slf = this; setSingleRV(true); function onit () { dropReceiver(eventName, wen); func.apply(this, arguments); }; wen.receiver = onit; return this; }, dropReceiver = function (eventName, func) { if (sigCache && sigCache[eventName]) { var sigLst = sigCache[eventName]; if (isAry(sigLst)) { var idx = -1; for (var i = 0, l = sigLst.length; i < l; i++) { if (sigLst[i] === func || (sigLst[i].receiver && sigLst[i].receiver === func)) { idx = i; break; } } if (idx < 0) { return this; } sigLst.splice(idx, 1); if (!sigLst.length) { delete sigCache[eventName]; } } else if (sigLst === func || (sigLst.receiver && sigLst.receiver === func)) { delete sigCache[eventName]; } } return this; }, setSingleRV = function (val) { singleRtnVal = val; return this; }, getSingleRV = function() { if (receivers.hasOwnProperty('singleRtnVal')) { return singleRtnVal; } else { return true; } }, castSignal = function(eventName, args) { var recvrLst = receiverObjects(eventName), k, recvr, i, rspns; for (k in recvrLst ) { if (recvrLst.hasOwnProperty(k)) { i = recvrLst[k].length; while (i--) { recvr = recvrLst[k][i]; if (recvr.signalOnce === true) { dropReceiver(eventName, recvr); } rspns = recvr.call(this, args || []); if (rspns === getSingleRV()) { dropReceiver(eventName, recvr); } } } } return this; }; function isAry(obj) { return (obj.constructor === Array); }; function receiverObjects(eventName) { var recvrLst = receivers(eventName), rspns; if (isAry(recvrLst)) { rspns = {}; rspns[eventName] = recvrLst; } return rspns || recvrLst; }; function receivers(eventName) { if (!sigCache) { sigCache = {}; } if (!sigCache[eventName]) { sigCache[eventName] = []; } if (!isAry(sigCache[eventName])) { sigCache[eventName] = [sigCache[eventName]]; } return sigCache[eventName]; }; function wen(eventName, func) { if (!sigCache) { sigCache = {}; } if (!sigCache[eventName]) { sigCache[eventName] = func; } else if (isArry(sigCache[eventName])) { sigCache[eventName].push(func); } else { sigCache[eventName] = [sigCache[eventName], func]; } return; }; return { signal: castSignal, signaled: signalReceived, receive: addReceiver, receiveOnce: signalOnce, signaledOnce: signalOnce, dropReceiver: dropReceiver, assignReceiver: addReceiver, receivers: receivers, dropReceivers: dropReceivers }; }()); exports.Signals = Signals;
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus