@stacksjs/events 0.47.1
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.md +21 -0
- package/README.md +76 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.mjs +9 -0
- package/package.json +54 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Open Web Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Stacks Events
|
|
2
|
+
|
|
3
|
+
Functional event emitting.
|
|
4
|
+
|
|
5
|
+
## โ๏ธ Features
|
|
6
|
+
|
|
7
|
+
- Functional event emitting
|
|
8
|
+
|
|
9
|
+
## ๐ค Usage
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm i -D @stacksjs/events
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Now, you can use it in your project:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { all, dispatch, listen, off } from '@stacksjs/events'
|
|
19
|
+
|
|
20
|
+
// listen to an event
|
|
21
|
+
listen('foo', e => console.log('foo', e))
|
|
22
|
+
|
|
23
|
+
// listen to all events
|
|
24
|
+
listen('*', (type, e) => console.log(type, e))
|
|
25
|
+
|
|
26
|
+
// fire an event
|
|
27
|
+
dispatch('foo', { a: 'b' })
|
|
28
|
+
|
|
29
|
+
// clearing all events
|
|
30
|
+
all.clear()
|
|
31
|
+
|
|
32
|
+
// working with handler references:
|
|
33
|
+
function onFoo() {}
|
|
34
|
+
listen('foo', onFoo) // listen
|
|
35
|
+
off('foo', onFoo) // unlisten
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For improved type inference, ensure to configure `./config/events.ts`. To view the full documentation, please visit [https://stacksjs.dev/events](https://stacksjs.dev/events).
|
|
39
|
+
|
|
40
|
+
## ๐งช Testing
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pnpm test
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## ๐ Changelog
|
|
47
|
+
|
|
48
|
+
Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
|
|
49
|
+
|
|
50
|
+
## ๐ช๐ผ Contributing
|
|
51
|
+
|
|
52
|
+
Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
|
|
53
|
+
|
|
54
|
+
## ๐ Community
|
|
55
|
+
|
|
56
|
+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
|
|
57
|
+
|
|
58
|
+
[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)
|
|
59
|
+
|
|
60
|
+
For casual chit-chat with others using this package:
|
|
61
|
+
|
|
62
|
+
[Join the Stacks Discord Server](https://discord.ow3.org)
|
|
63
|
+
|
|
64
|
+
## ๐๐ผ Credits
|
|
65
|
+
|
|
66
|
+
Many thanks to the following core technologies & people who have contributed to this package:
|
|
67
|
+
|
|
68
|
+
- [mitt](https://github.com/developit/mitt)
|
|
69
|
+
- [Chris Breuer](https://github.com/chrisbbreuer)
|
|
70
|
+
- [All Contributors](../../contributors)
|
|
71
|
+
|
|
72
|
+
## ๐ License
|
|
73
|
+
|
|
74
|
+
The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
|
|
75
|
+
|
|
76
|
+
Made with โค๏ธ
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import mitt from 'mitt';
|
|
2
|
+
import type { Events } from '@stacksjs/types';
|
|
3
|
+
/**
|
|
4
|
+
* This module provides a simple, yet powerful, event bus for the application.
|
|
5
|
+
*
|
|
6
|
+
* @example To fire an event, you may use any of the following approaches:
|
|
7
|
+
* ```ts
|
|
8
|
+
* useEvent('user:registered', { name: 'Chris'})
|
|
9
|
+
* dispatch('user:registered', { name: 'Chris'})
|
|
10
|
+
* ````
|
|
11
|
+
|
|
12
|
+
* @example To capture an event, you may use any of the following approaches:
|
|
13
|
+
* ```ts
|
|
14
|
+
* useListen('user:registered', (user) => console.log(user))
|
|
15
|
+
* listen('user:registered', (user) => console.log(user))
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare const events: typeof mitt;
|
|
19
|
+
declare const useEvent: {
|
|
20
|
+
<Key extends string | number | symbol>(type: Key, event: Events): void;
|
|
21
|
+
<Key_1 extends string | number | symbol>(type: Key_1): void;
|
|
22
|
+
};
|
|
23
|
+
declare const dispatch: {
|
|
24
|
+
<Key extends string | number | symbol>(type: Key, event: Events): void;
|
|
25
|
+
<Key_1 extends string | number | symbol>(type: Key_1): void;
|
|
26
|
+
};
|
|
27
|
+
declare const listen: {
|
|
28
|
+
<Key extends string | number | symbol>(type: Key, handler: import("mitt").Handler<Events>): void;
|
|
29
|
+
(type: "*", handler: import("mitt").WildcardHandler<Events>): void;
|
|
30
|
+
};
|
|
31
|
+
declare const off: {
|
|
32
|
+
<Key extends string | number | symbol>(type: Key, handler?: import("mitt").Handler<Events> | undefined): void;
|
|
33
|
+
(type: "*", handler: import("mitt").WildcardHandler<Events>): void;
|
|
34
|
+
};
|
|
35
|
+
declare const all: import("mitt").EventHandlerMap<Events>;
|
|
36
|
+
export { useEvent, dispatch, listen, all, off, events, mitt, Events };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import mitt from "mitt";
|
|
2
|
+
const events = mitt;
|
|
3
|
+
const emitter = events();
|
|
4
|
+
const useEvent = emitter.emit;
|
|
5
|
+
const dispatch = emitter.emit;
|
|
6
|
+
const listen = emitter.on;
|
|
7
|
+
const off = emitter.off;
|
|
8
|
+
const all = emitter.all;
|
|
9
|
+
export { useEvent, dispatch, listen, all, off, events, mitt };
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stacksjs/events",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.47.1",
|
|
5
|
+
"packageManager": "pnpm@7.21.0",
|
|
6
|
+
"description": "Functional event emitting.",
|
|
7
|
+
"author": "Chris Breuer",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"funding": "https://github.com/sponsors/chrisbbreuer",
|
|
10
|
+
"homepage": "https://github.com/stacksjs/stacks/tree/main/.stacks/core/events#readme",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
14
|
+
"directory": "./.stacks/core/events"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/stacksjs/stacks/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"events",
|
|
21
|
+
"functional",
|
|
22
|
+
"functions",
|
|
23
|
+
"mitt",
|
|
24
|
+
"stacks"
|
|
25
|
+
],
|
|
26
|
+
"main": "dist/index.mjs",
|
|
27
|
+
"module": "dist/index.mjs",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
29
|
+
"contributors": [
|
|
30
|
+
"Chris Breuer <chris@ow3.org>"
|
|
31
|
+
],
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=v18.12.1",
|
|
38
|
+
"pnpm": ">=7.21.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"mitt": "^3.0.0",
|
|
42
|
+
"@stacksjs/alias": "0.47.1"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"mkdist": "^1.0.0",
|
|
46
|
+
"typescript": "^4.9.4",
|
|
47
|
+
"@stacksjs/testing": "0.47.1"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "mkdist -d",
|
|
51
|
+
"dev": "mkdist -d",
|
|
52
|
+
"typecheck": "tsc --noEmit"
|
|
53
|
+
}
|
|
54
|
+
}
|