forked from flow-typed/flow-typed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add library definition for component-emitter (flow-typed#1522)
- Loading branch information
1 parent
55bef7f
commit 021abc9
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
definitions/npm/component-emitter_v1.x.x/flow_v0.34.x-/component-emitter_v1.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
declare module "component-emitter" { | ||
declare type Callback = (...args: mixed[]) => void; | ||
|
||
declare class Emitter { | ||
static (base?: {}): this; | ||
on(event: string, cb: Callback): this; | ||
addEventListener(event: string, cb: Callback): this; | ||
|
||
once(event: string, cb: Callback): this; | ||
|
||
off(event: string, cb: Callback): this; | ||
removeListener(event: string, cb: Callback): this; | ||
removeAllListeners(event: string, cb: Callback): this; | ||
removeEventListener(event: string, cb: Callback): this; | ||
|
||
emit(event: string, payload: mixed): this; | ||
listeners(event: string): Callback[]; | ||
hasListeners(event: string): boolean; | ||
} | ||
|
||
declare export default typeof Emitter | ||
} |
23 changes: 23 additions & 0 deletions
23
definitions/npm/component-emitter_v1.x.x/test_component-emitter_v1.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Emitter from "component-emitter"; | ||
|
||
Emitter(); | ||
Emitter({}); | ||
Emitter({ foo: "bar" }); | ||
|
||
const e = Emitter(); | ||
e === | ||
e | ||
.on("on", ok => {}) | ||
.addEventListener("addEventListener", ok => {}) | ||
.once("once", ok => {}) | ||
.off("off", ok => {}) | ||
.removeListener("removeListener", ok => {}) | ||
.removeAllListeners("removeAllListeners", ok => {}) | ||
.removeEventListener("removeEventListener", ok => {}) | ||
.emit("foo", { bar: "baz" }); | ||
|
||
e.listeners("foo").length; | ||
e.hasListeners("foo"); | ||
|
||
// $ExpectError | ||
Emitter(5); |