@ixfx/events 0.38.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +81 -0
- package/README.md +28 -0
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/src/race.d.ts +0 -23
- package/dist/src/race.d.ts.map +0 -1
- package/dist/src/race.js +0 -70
package/LICENSE
CHANGED
|
@@ -19,3 +19,84 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Mersenne Twister
|
|
26
|
+
https://github.com/jawj/mtwist
|
|
27
|
+
© Copyright 2014 – 2021 George MacKerron
|
|
28
|
+
MIT License
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
Ramer Douglas Peucker implementation
|
|
33
|
+
|
|
34
|
+
Marius Karthaus
|
|
35
|
+
http://www.LowVoice.nl
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
The MIT License (MIT)
|
|
40
|
+
|
|
41
|
+
Copyright © 2022 github.com/pushkine/
|
|
42
|
+
|
|
43
|
+
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:
|
|
44
|
+
|
|
45
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
46
|
+
|
|
47
|
+
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.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
collections/BinaryTreeNode
|
|
52
|
+
collections/BinarySearchTree
|
|
53
|
+
collections/TreeNode
|
|
54
|
+
https://github.com/amejiarosario/dsa.js-data-structures-algorithms-javascript
|
|
55
|
+
|
|
56
|
+
MIT License
|
|
57
|
+
|
|
58
|
+
Copyright (c) 2019 Adrian Mejia
|
|
59
|
+
|
|
60
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
61
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
62
|
+
in the Software without restriction, including without limitation the rights
|
|
63
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
64
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
65
|
+
furnished to do so, subject to the following conditions:
|
|
66
|
+
|
|
67
|
+
The above copyright notice and this permission notice shall be included in all
|
|
68
|
+
copies or substantial portions of the Software.
|
|
69
|
+
|
|
70
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
71
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
72
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
73
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
74
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
75
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
76
|
+
SOFTWARE.
|
|
77
|
+
|
|
78
|
+
----
|
|
79
|
+
|
|
80
|
+
Package: colorjs.io
|
|
81
|
+
|
|
82
|
+
MIT License
|
|
83
|
+
|
|
84
|
+
Copyright (c) 2021 Lea Verou, Chris Lilley
|
|
85
|
+
|
|
86
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
87
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
88
|
+
in the Software without restriction, including without limitation the rights
|
|
89
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
90
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
91
|
+
furnished to do so, subject to the following conditions:
|
|
92
|
+
|
|
93
|
+
The above copyright notice and this permission notice shall be included in all
|
|
94
|
+
copies or substantial portions of the Software.
|
|
95
|
+
|
|
96
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
97
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
98
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
99
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
100
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
101
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
102
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
A simple eventing implementation.
|
|
2
|
+
|
|
3
|
+
For a class, extend `SimpleEventEmitter`.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
export type MyClassEvents = {
|
|
7
|
+
// An event named `blah` that has one field, 'id'.
|
|
8
|
+
readonly blah: (id:string);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export class MyClass extends SimpleEventEmitter<MyClassEvents> {
|
|
12
|
+
|
|
13
|
+
test() {
|
|
14
|
+
// Eg: firing an event
|
|
15
|
+
this.fireEvent(`blah`, {
|
|
16
|
+
id: Math.random()
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
You can then un/subscribe as usual:
|
|
23
|
+
```js
|
|
24
|
+
const c = new MyClass();
|
|
25
|
+
c.addEventListener(`blah`, (id) => {
|
|
26
|
+
// Event!
|
|
27
|
+
});
|
|
28
|
+
```
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,cAAc,YAAY,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/index.ts","../src/map-of.ts","../src/
|
|
1
|
+
{"root":["../src/index.ts","../src/map-of.ts","../src/simple-event-emitter.ts","../src/types.ts","../__tests__/test.ts"],"version":"5.8.3"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ixfx/events",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"files": [
|
|
8
8
|
"dist/"
|
|
9
9
|
],
|
|
10
|
+
"dependencies": {},
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
12
13
|
"types": "./dist/src/index.d.ts",
|
|
13
14
|
"import": "./dist/src/index.js"
|
|
14
15
|
}
|
|
15
16
|
},
|
|
16
|
-
"dependencies": {},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build-test": "npx rimraf dist && tsc --build"
|
|
19
19
|
},
|
package/dist/src/race.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subscribes to events on `target`, returning the event data
|
|
3
|
-
* from the first event that fires.
|
|
4
|
-
*
|
|
5
|
-
* By default waits a maximum of 1 minute.
|
|
6
|
-
*
|
|
7
|
-
* Automatically unsubscribes on success or failure (ie. timeout)
|
|
8
|
-
*
|
|
9
|
-
* ```js
|
|
10
|
-
* // Event will be data from either event, whichever fires first
|
|
11
|
-
* // Exception is thrown if neither fires within 1 second
|
|
12
|
-
* const event = await eventRace(document.body, [`pointermove`, `pointerdown`], { timeout: 1000 });
|
|
13
|
-
* ```
|
|
14
|
-
* @param target Event source
|
|
15
|
-
* @param eventNames Event name(s)
|
|
16
|
-
* @param options Options
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
export declare const eventRace: (target: EventTarget, eventNames: Array<string>, options?: Partial<{
|
|
20
|
-
timeoutMs: number;
|
|
21
|
-
signal: AbortSignal;
|
|
22
|
-
}>) => Promise<Event>;
|
|
23
|
-
//# sourceMappingURL=race.d.ts.map
|
package/dist/src/race.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"race.d.ts","sourceRoot":"","sources":["../../src/race.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,WAAW,EAAE,YAAY,KAAK,CAAC,MAAM,CAAC,EAAE,UAAS,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAAM,mBAmD1I,CAAA"}
|
package/dist/src/race.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subscribes to events on `target`, returning the event data
|
|
3
|
-
* from the first event that fires.
|
|
4
|
-
*
|
|
5
|
-
* By default waits a maximum of 1 minute.
|
|
6
|
-
*
|
|
7
|
-
* Automatically unsubscribes on success or failure (ie. timeout)
|
|
8
|
-
*
|
|
9
|
-
* ```js
|
|
10
|
-
* // Event will be data from either event, whichever fires first
|
|
11
|
-
* // Exception is thrown if neither fires within 1 second
|
|
12
|
-
* const event = await eventRace(document.body, [`pointermove`, `pointerdown`], { timeout: 1000 });
|
|
13
|
-
* ```
|
|
14
|
-
* @param target Event source
|
|
15
|
-
* @param eventNames Event name(s)
|
|
16
|
-
* @param options Options
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
export const eventRace = (target, eventNames, options = {}) => {
|
|
20
|
-
const intervalMs = options.timeoutMs ?? 60_1000; //intervalToMs(options.timeout, 60 * 1000);
|
|
21
|
-
const signal = options.signal;
|
|
22
|
-
let triggered = false;
|
|
23
|
-
let disposed = false;
|
|
24
|
-
let timeout;
|
|
25
|
-
const promise = new Promise((resolve, reject) => {
|
|
26
|
-
const onEvent = (event) => {
|
|
27
|
-
if (`type` in event) {
|
|
28
|
-
if (eventNames.includes(event.type)) {
|
|
29
|
-
triggered = true;
|
|
30
|
-
resolve(event);
|
|
31
|
-
dispose();
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
console.warn(`eventRace: Got event '${event.type}' that is not in race list`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
console.warn(`eventRace: Event data does not have expected 'type' field`);
|
|
39
|
-
console.log(event);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
for (const name of eventNames) {
|
|
43
|
-
target.addEventListener(name, onEvent);
|
|
44
|
-
}
|
|
45
|
-
const dispose = () => {
|
|
46
|
-
if (disposed)
|
|
47
|
-
return;
|
|
48
|
-
if (timeout !== undefined)
|
|
49
|
-
clearTimeout(timeout);
|
|
50
|
-
timeout = undefined;
|
|
51
|
-
disposed = true;
|
|
52
|
-
for (const name of eventNames) {
|
|
53
|
-
target.removeEventListener(name, onEvent);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
timeout = setTimeout(() => {
|
|
57
|
-
if (triggered || disposed)
|
|
58
|
-
return;
|
|
59
|
-
dispose();
|
|
60
|
-
reject(new Error(`eventRace: Events not fired within interval. Events: ${JSON.stringify(eventNames)} Interval: ${intervalMs}`));
|
|
61
|
-
}, intervalMs);
|
|
62
|
-
signal?.addEventListener(`abort`, () => {
|
|
63
|
-
if (triggered || disposed)
|
|
64
|
-
return;
|
|
65
|
-
dispose();
|
|
66
|
-
reject(new Error(`Abort signal received ${signal.reason}`));
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
return promise;
|
|
70
|
-
};
|