diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-03-12 07:16:23 +0200 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-03-12 07:16:23 +0200 |
| commit | 7076343338ae3439f3c86f01144818abe8c31978 (patch) | |
| tree | 794abb1e6b8f821091fd095341885496b6dad51d /html/content/lib/emitter/dist/emitter.js | |
| parent | 47cbb529f5723b246125ae083a193e11481b89ef (diff) | |
| download | classroom-7076343338ae3439f3c86f01144818abe8c31978.tar.gz classroom-7076343338ae3439f3c86f01144818abe8c31978.tar.bz2 classroom-7076343338ae3439f3c86f01144818abe8c31978.zip | |
add container helpers; constuct public directory-tree
Diffstat (limited to 'html/content/lib/emitter/dist/emitter.js')
| -rw-r--r-- | html/content/lib/emitter/dist/emitter.js | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/html/content/lib/emitter/dist/emitter.js b/html/content/lib/emitter/dist/emitter.js new file mode 100644 index 0000000..6b2a6fa --- /dev/null +++ b/html/content/lib/emitter/dist/emitter.js @@ -0,0 +1,88 @@ +(function (global, factory) {
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
+ typeof define === 'function' && define.amd ? define(factory) :
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.emitter = factory());
+}(this, (function () { 'use strict';
+
+ function emitter(context, options) {
+ var _events = {}, o = options || {}, _constantEvents = {}, noop = function(){};
+
+ function invoke(handler, args){
+ window.setTimeout(function () {
+ handler.apply(context, args);
+ });
+ }
+
+ function emit(event) {
+ var handlers = (_events[event] || (_events[event] = []));
+ if (!handlers){
+ return;
+ }
+ var args = Array.prototype.slice.call(arguments, 1);
+ if (o.emitting) {
+ o.emitting({ event: event, data: args, context: context });
+ }
+ for (var i = 0, l = handlers.length; i < l; i++) {
+ invoke(handlers[i], args);
+ }
+ }
+
+ function replay (event) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ _constantEvents[event] = args;
+ emit.apply(null, arguments);
+ }
+
+ function on(event, fn) {
+ if (_constantEvents[event]){
+ invoke(fn, _constantEvents[event]);
+ return noop;
+ }
+ var handlers = (_events[event] || (_events[event] = []));
+ handlers.push(fn);
+ return function () {
+ off(event, fn);
+ };
+ }
+
+ function off(event, fn) {
+ var handlers = _events[event], i, h;
+ if (!handlers) {
+ return;
+ }
+ if (Array.isArray(event)) {
+ for (i = 0, l = event.length; i < l; i++) {
+ off(event[i], fn);
+ }
+ return;
+ }
+ i = handlers.length;
+ while(i--) {
+ h = handlers[i];
+ if (fn === h){
+ handlers.splice(i, 1);
+ break;
+ }
+ }
+ }
+
+ function once(event, fn) {
+ var unsub = on(event, function () {
+ fn.apply(context, arguments);
+ unsub();
+ });
+ return unsub;
+ }
+
+ return {
+ on: on,
+ off: off,
+ emit: emit,
+ once: once,
+ replay: replay
+ };
+ }
+
+ return emitter;
+
+})));
|
