Archived
1
0

First commit

This commit is contained in:
Sean Edmunds
2021-12-13 17:00:40 -06:00
commit 0584430b5c
36617 changed files with 4676695 additions and 0 deletions

3
node_modules/microevent.ts/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,3 @@
language: node_js
node_js:
- node

21
node_modules/microevent.ts/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Christian Speckner <cnspeckn@googlemail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

96
node_modules/microevent.ts/README.md generated vendored Normal file
View File

@@ -0,0 +1,96 @@
[![Build Status](https://travis-ci.org/DirtyHairy/microevent.svg?branch=master)](https://travis-ci.org/DirtyHairy/microevent)
[![npm version](https://badge.fury.io/js/microevent.ts.svg)](https://badge.fury.io/js/microevent.ts)
# What is it?
This package implements an event system with minimal dispatch overhead. Instead
of recording handlers bound to an event in dynamic data structures, this library
binds the handlers to autogenerated code. This enables the VM to inline the
handler invocation and generate code that is just as fast as invoking the handlers
directly.
In a (completely unscientific) benchmark, this library performs bettern than
NodeJS events in terms of event dispatch calls per second by about two orders
of magnitude.
# How to use it?
## Installation
You can install the library into your project via npm
npm install microevent.ts
The library is written in Typescript and will work in any environment that
supports ES5. No external typings are required for using this library with
Typescript (version >= 2).
## Importing
ES5 / CommonJS
var Event = require('microevent.ts').Event;
ES6
import {Event} from 'microevent.ts';
Typescript
import {Event, EventInterface} from 'microevent.ts';
The `EventInterface` covers only the client side of an event, that is adding
and removing handlers.
## API
### Creating
ES5/ES6
const event = new Event();
Typescript
const event = new Event<PayloadT>();
Create a new event that will dispatch a payload of type `PayloadT`.
### Dispatching
event.dispatch(payload);
This will call all handlers in the order they were registered, passing `payload`
as first argument.
**IMPORTANT** `dispatch` is a property that refers to dynamically generated code.
**DO NOT KEEP ANY REFERENCES** to `dispatch` as adding and removing handlers
will invalidate them.
### Registering handlers
event.addHandler(handler, context);
`context` is an optional parameter that will be passed to the handler on
each invocation.
### Removing handlers
event.removeHandler(handler, context);
Both `handler` and `context` must be identical to the values used when registering
the handler in the first place.
### Checking for handlers
event.isHandlerAttached(handler, context)
This will check whether a handler was attached in a given context.
event.hasHandlers
`true` if the event has any handlers attached, false otherwise.
# License
Feel free to use this library under the conditions of the MIT license.

15
node_modules/microevent.ts/lib/Event.d.ts generated vendored Normal file
View File

@@ -0,0 +1,15 @@
import EventInterface from './EventInterface';
declare class Event<EventPayload> implements EventInterface<EventPayload> {
constructor();
addHandler<T>(handler: EventInterface.HandlerInterface<EventPayload, T>, context?: T): Event<EventPayload>;
removeHandler<T>(handler: EventInterface.HandlerInterface<EventPayload, T>, context?: T): Event<EventPayload>;
isHandlerAttached<T>(handler: EventInterface.HandlerInterface<EventPayload, T>, context?: T): boolean;
dispatch: (payload: EventPayload) => void;
hasHandlers: boolean;
private _updateHasHandlers;
private _getHandlerIndex;
private _createDispatcher;
private _handlers;
private _contexts;
}
export default Event;

76
node_modules/microevent.ts/lib/Event.js generated vendored Normal file
View File

@@ -0,0 +1,76 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var factories = [];
factories[0] = function () {
return function dispatcher0() { };
};
factories[1] = function (callback, context) {
if (typeof (context) === 'undefined')
return callback;
return function dispatcher1(payload) {
callback(payload, context);
};
};
function getFactory(handlerCount) {
if (!factories[handlerCount])
factories[handlerCount] = compileFactory(handlerCount);
return factories[handlerCount];
}
function compileFactory(handlerCount) {
var src = 'return function dispatcher' + handlerCount + '(payload) {\n';
var argsHandlers = [], argsContexts = [];
for (var i = 0; i < handlerCount; i++) {
argsHandlers.push('cb' + i);
argsContexts.push('ctx' + i);
src += ' cb' + i + '(payload, ctx' + i + ');\n';
}
src += '};';
return new (Function.bind.apply(Function, [void 0].concat(argsHandlers.concat(argsContexts), [src])))();
}
var Event = /** @class */ (function () {
function Event() {
this.hasHandlers = false;
this._handlers = [];
this._contexts = [];
this._createDispatcher();
}
Event.prototype.addHandler = function (handler, context) {
if (!this.isHandlerAttached(handler, context)) {
this._handlers.push(handler);
this._contexts.push(context);
this._createDispatcher();
this._updateHasHandlers();
}
return this;
};
Event.prototype.removeHandler = function (handler, context) {
var idx = this._getHandlerIndex(handler, context);
if (typeof (idx) !== 'undefined') {
this._handlers.splice(idx, 1);
this._contexts.splice(idx, 1);
this._createDispatcher();
this._updateHasHandlers();
}
return this;
};
Event.prototype.isHandlerAttached = function (handler, context) {
return typeof (this._getHandlerIndex(handler, context)) !== 'undefined';
};
Event.prototype._updateHasHandlers = function () {
this.hasHandlers = !!this._handlers.length;
};
Event.prototype._getHandlerIndex = function (handler, context) {
var handlerCount = this._handlers.length;
var idx;
for (idx = 0; idx < handlerCount; idx++) {
if (this._handlers[idx] === handler && this._contexts[idx] === context)
break;
}
return idx < handlerCount ? idx : undefined;
};
Event.prototype._createDispatcher = function () {
this.dispatch = getFactory(this._handlers.length).apply(this, this._handlers.concat(this._contexts));
};
return Event;
}());
exports.default = Event;

10
node_modules/microevent.ts/lib/EventInterface.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
interface EventInterface<EventPayload> {
addHandler<T>(handler: EventInterface.HandlerInterface<EventPayload, T>, context?: T): EventInterface<EventPayload>;
removeHandler<T>(handler: EventInterface.HandlerInterface<EventPayload, T>, context?: T): EventInterface<EventPayload>;
}
declare module EventInterface {
interface HandlerInterface<EventPayload, T> {
(payload: EventPayload, context: T): void;
}
}
export default EventInterface;

2
node_modules/microevent.ts/lib/EventInterface.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

2
node_modules/microevent.ts/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export { default as Event } from './Event';
export { default as EventInterface } from './EventInterface';

4
node_modules/microevent.ts/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Event_1 = require("./Event");
exports.Event = Event_1.default;

27
node_modules/microevent.ts/package.json generated vendored Normal file
View File

@@ -0,0 +1,27 @@
{
"name": "microevent.ts",
"version": "0.1.1",
"description": "Zero cost events",
"scripts": {
"prepublish": "tsc",
"pretest": "typings install && tsc -p tsconfig.test.json",
"test": "mocha -R spec -u tdd test"
},
"author": "Christian Speckner <cnspeckn@googlemail.com> (https://github.com/DirtyHairy/)",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/DirtyHairy/microevent.git"
},
"keywords": [
"events",
"performance"
],
"devDependencies": {
"mocha": "~6.1.4",
"typescript": "~3.4.5",
"typings": "^2.1.1"
},
"main": "lib/index.js",
"types": "lib/index.d.ts"
}

103
node_modules/microevent.ts/src/Event.ts generated vendored Normal file
View File

@@ -0,0 +1,103 @@
import EventInterface from './EventInterface';
const factories: Array<Function> = [];
factories[0] = function(): Function {
return function dispatcher0() {};
};
factories[1] = function(callback: Function, context?: any): Function {
if (typeof(context) === 'undefined') return callback;
return function dispatcher1(payload: any) {
callback(payload, context);
};
};
function getFactory(handlerCount: number) {
if (!factories[handlerCount]) factories[handlerCount] = compileFactory(handlerCount);
return factories[handlerCount];
}
function compileFactory(handlerCount: number): Function {
let src: string = 'return function dispatcher' + handlerCount + '(payload) {\n';
const argsHandlers: Array<string> = [],
argsContexts: Array<string> = [];
for (let i = 0; i < handlerCount; i++) {
argsHandlers.push('cb' + i);
argsContexts.push('ctx' + i);
src += ' cb' + i + '(payload, ctx' + i + ');\n';
}
src += '};';
return new Function(...argsHandlers.concat(argsContexts), src);
}
class Event<EventPayload> implements EventInterface<EventPayload> {
constructor() {
this._createDispatcher();
}
addHandler<T>(handler: EventInterface.HandlerInterface<EventPayload, T>, context?: T): Event<EventPayload> {
if (!this.isHandlerAttached(handler, context)) {
this._handlers.push(handler);
this._contexts.push(context);
this._createDispatcher();
this._updateHasHandlers();
}
return this;
}
removeHandler<T>(handler: EventInterface.HandlerInterface<EventPayload, T>, context?: T): Event<EventPayload> {
const idx = this._getHandlerIndex(handler, context);
if (typeof(idx) !== 'undefined') {
this._handlers.splice(idx, 1);
this._contexts.splice(idx, 1);
this._createDispatcher();
this._updateHasHandlers();
}
return this;
}
isHandlerAttached<T>(handler: EventInterface.HandlerInterface<EventPayload, T>, context?: T) {
return typeof(this._getHandlerIndex(handler, context)) !== 'undefined';
}
dispatch: (payload: EventPayload) => void;
hasHandlers = false;
private _updateHasHandlers() {
this.hasHandlers = !!this._handlers.length;
}
private _getHandlerIndex<T>(handler: EventInterface.HandlerInterface<EventPayload, T>, context?: T): number {
const handlerCount = this._handlers.length;
let idx: number;
for (idx = 0; idx < handlerCount; idx++) {
if (this._handlers[idx] === handler && this._contexts[idx] === context) break;
}
return idx < handlerCount ? idx : undefined;
}
private _createDispatcher() {
this.dispatch = getFactory(this._handlers.length).apply(this, this._handlers.concat(this._contexts));
}
private _handlers: Array<(payload: EventPayload, context: any) => void> = [];
private _contexts: Array<any> = [];
}
export default Event;

16
node_modules/microevent.ts/src/EventInterface.ts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
interface EventInterface <EventPayload> {
addHandler<T>(handler: EventInterface.HandlerInterface<EventPayload, T>, context?: T): EventInterface<EventPayload>;
removeHandler<T>(handler: EventInterface.HandlerInterface<EventPayload, T>, context?: T): EventInterface<EventPayload>;
}
module EventInterface {
export interface HandlerInterface<EventPayload, T> {
(payload: EventPayload, context: T): void;
}
}
export default EventInterface;

2
node_modules/microevent.ts/src/index.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export {default as Event} from './Event';
export {default as EventInterface} from './EventInterface';

170
node_modules/microevent.ts/test/event.ts generated vendored Normal file
View File

@@ -0,0 +1,170 @@
/// <reference path="../typings/index.d.ts"/>
import Event from '../lib/Event';
import * as assert from 'assert';
suite('Event handling', function() {
let event: Event<string>;
setup(function() {
event = new Event();
});
test('no handlers', function() {
assert(!event.hasHandlers, 'event should report any registered handlers');
assert.doesNotThrow(function() {
event.dispatch('');
}, 'dispatch should not throw');
});
suite('one handler', function() {
test('no context', function() {
let called = false;
event.addHandler(function(payload: string) {
assert.equal(payload, 'foo');
called = true;
});
assert(event.hasHandlers, 'event should report registered handlers');
event.dispatch('foo');
assert(called, 'the handler should have been called');
});
test('with context', function() {
let foo = 0;
function handler(payload: string, context: number) {
assert.equal(payload, 'foo');
foo = context;
};
event.addHandler(handler, 5).dispatch('foo');
assert.equal(foo, 5, 'context was not transferred correctly');
assert(event.removeHandler(handler).hasHandlers, 'handler should only be remvoved if contet matches');
assert(!event.removeHandler(handler, 5).hasHandlers, 'handler should be remvoved if contet matches');
});
test('one handler, no context, multiple attachments', function() {
let i = 0;
function handler(): void {
i++;
}
event.addHandler(handler).addHandler(handler).dispatch('foo');
assert.equal(i, 1, 'handler should have been called once');
assert(event.isHandlerAttached(handler), 'handler should be reported as attached');
event.removeHandler(handler);
assert(!event.isHandlerAttached(handler), 'handler should be reported as not attached after removal');
});
test('one handler, different contexts, multiple attachments', function() {
let i = 0;
function handler(): void {
i++;
}
event.addHandler(handler, 1).addHandler(handler, 2).dispatch('foo');
assert.equal(i, 2, 'handler should have been called twice');
assert(!event.isHandlerAttached(handler), 'handler should be reported as not attached w/o context');
assert(event.isHandlerAttached(handler, 1), 'handler should be reported as attached with proper context');
});
});
suite('two handlers', function() {
let called1: boolean, called2: boolean,
contexts: Array<number>;
function handler1(payload: string) {
assert.equal(payload, 'foo');
called1 = true;
};
function handler2(payload: string) {
assert.equal(payload, 'foo');
called2 = true;
};
function ctxHandler(payload: string, context: any) {
contexts[context] = context;
assert.equal(payload, 'foo');
}
setup(function() {
called1 = called2 = false;
contexts = [0, 0, 0];
event
.addHandler(handler1)
.addHandler(handler2);
});
test('both attached', function() {
event.dispatch('foo');
assert(called1, 'handler 1 should have been called');
assert(called2, 'handler 2 should have been called');
});
test('handler 1 detached', function() {
event.removeHandler(handler1);
event.dispatch('foo');
assert(!called1, 'handler 1 should not have been called');
assert(called2, 'handler 2 should have been called');
});
test('handler 2 detached', function() {
event.removeHandler(handler2);
event.dispatch('foo');
assert(called1, 'handler 1 should have been called');
assert(!called2, 'handler 2 should not have been called');
});
test('context, both attached', function() {
event
.addHandler(ctxHandler, 1)
.addHandler(ctxHandler, 2)
.dispatch('foo');
assert.equal(contexts[1], 1, 'context 1 was not transferred correctly');
assert.equal(contexts[2], 2, 'context 2 was not transferred correctly');
});
test('context, handler 1 detached', function() {
event
.addHandler(ctxHandler, 1)
.addHandler(ctxHandler, 2)
.removeHandler(ctxHandler, 1)
.dispatch('foo');
assert.equal(contexts[1], 0, 'handler was not detached');
assert.equal(contexts[2], 2, 'context 2 was not transferred correctly');
});
test('context, handler 2 detached', function() {
event
.addHandler(ctxHandler, 1)
.addHandler(ctxHandler, 2)
.removeHandler(ctxHandler, 2)
.dispatch('foo');
assert.equal(contexts[1], 1, 'context 1 was not transferred correctly');
assert.equal(contexts[2], 0, 'handler was not detached');
});
});
});

14
node_modules/microevent.ts/tsconfig.json generated vendored Normal file
View File

@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": false,
"noImplicitAny": true,
"noImplicitThis": true,
"declaration": true,
"outDir": "lib",
"esModuleInterop": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}

11
node_modules/microevent.ts/tsconfig.test.json generated vendored Normal file
View File

@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": false,
"noImplicitAny": true,
"noImplicitThis": true
},
"include": ["test/**/*.ts"],
"exclude": ["node_modules"]
}

6
node_modules/microevent.ts/typings.json generated vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"globalDependencies": {
"mocha": "registry:dt/mocha#2.2.5+20160720003353",
"node": "registry:dt/node#6.0.0+20160928143418"
}
}

1784
node_modules/microevent.ts/yarn.lock generated vendored Normal file

File diff suppressed because it is too large Load Diff