-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
15 changed files
with
1,693 additions
and
70 deletions.
There are no files selected for viewing
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
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
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
8 changes: 4 additions & 4 deletions
8
definitions/npm/nanoevents_v1.0.x/flow_v0.50.x-/nanoevents_v1.0.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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
declare module "nanoevents" { | ||
declare export default class NanoEvents { | ||
constructor(): NanoEvents, | ||
declare export default class NanoEvents<T> { | ||
constructor(): NanoEvents<T>, | ||
|
||
on(event: string, cb: (any) => void): void, | ||
on<K: $Keys<T>>(event: K, cb: ($ElementType<T, K>) => void): void, | ||
|
||
emit(event: string, data?: any): void | ||
emit<K: $Keys<T>>(event: K, data?: $ElementType<T, K>): void | ||
} | ||
} |
77 changes: 57 additions & 20 deletions
77
definitions/npm/nanoevents_v1.0.x/test_nanoevents_v1.0.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 |
---|---|---|
@@ -1,31 +1,68 @@ | ||
import { describe, it } from "flow-typed-test"; | ||
import NanoEvents from "nanoevents"; | ||
|
||
// $ExpectError: call a constructor | ||
NanoEvents(); | ||
describe("default", () => { | ||
it("should create instance", () => { | ||
// $ExpectError: call a constructor | ||
NanoEvents(); | ||
|
||
// $ExpectError: not accept arguments | ||
new NanoEvents(1); | ||
// $ExpectError: not accept arguments | ||
new NanoEvents(1); | ||
|
||
const emitter = new NanoEvents(); | ||
const emitter = new NanoEvents(); | ||
|
||
emitter.emit("event"); | ||
emitter.emit("message"); | ||
|
||
// $ExpectError: allow only string as event name | ||
emitter.emit(1); | ||
// $ExpectError: allow only string as event name | ||
emitter.emit(1); | ||
|
||
emitter.emit("event", {}); | ||
emitter.emit("event", 1); | ||
emitter.emit("event", ""); | ||
emitter.emit("event", true); | ||
emitter.emit("event", {}); | ||
emitter.emit("event", 1); | ||
emitter.emit("event", ""); | ||
emitter.emit("event", true); | ||
|
||
emitter.on("event", () => {}); | ||
emitter.on("event", () => {}); | ||
|
||
emitter.on("event", arg => { | ||
console.log(arg); | ||
}); | ||
emitter.on("event", arg => { | ||
console.log(arg); | ||
}); | ||
|
||
// $ExpectError: allow only string as even name | ||
emitter.on(1, () => {}); | ||
|
||
// $ExpectError: allow only functions as callback | ||
emitter.on("event", 1); | ||
}); | ||
|
||
it('should throw error on emit wrong type', () => { | ||
const emitter = new NanoEvents<{ message: 'message-1' | 'message-2', error: Error }>(); | ||
|
||
// $ExpectError: allow only message-1 or message-2 strings | ||
emitter.emit('message', 1); | ||
emitter.emit('message', 'message-1'); | ||
emitter.emit('message', 'message-2'); | ||
|
||
// $ExpectError: allow only string as even name | ||
emitter.on(1, () => {}); | ||
// $ExpectError: allow only Error | ||
emitter.emit('error', 'error message'); | ||
emitter.emit('error', new Error('error message')); | ||
|
||
// $ExpectError: allow only functions as callback | ||
emitter.on("event", 1); | ||
// $ExpectError: allow only message or string events | ||
emitter.emit('wrong event'); | ||
}); | ||
|
||
it('should throw error on handle wrong event type or wrong handler type', () => { | ||
const emitter = new NanoEvents<{ message: 'message-1' | 'message-2', error: Error }>(); | ||
|
||
emitter.on('message', message => { | ||
// $ExpectError: allow only message-1 or message-2 strings | ||
(message: 'wrong message'); | ||
(message: 'message-1' | 'message-2'); | ||
}); | ||
|
||
emitter.on('error', error => { | ||
// $ExpectError: allow only Error instance | ||
(error: string); | ||
(error: Error); | ||
}) | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.