mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
add type definition file for node-observer (#40450)
* add type definition file for node-observer * remove unnecessary comment in index.d.ts * fix test errors * fix test errors
This commit is contained in:
parent
5cc9d512c6
commit
f149f60a57
32
types/node-observer/index.d.ts
vendored
Normal file
32
types/node-observer/index.d.ts
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
// Type definitions for node-observer 0.4
|
||||
// Project: https://github.com/hormander/node-observer
|
||||
// Definitions by: wjchi <https://github.com/CwjXFH>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export = observer;
|
||||
|
||||
declare class Observer {
|
||||
private subscribers: object[];
|
||||
/**
|
||||
* subscirpt event
|
||||
* @param targetObj objects that subscribe to events
|
||||
* @param eventName the event name
|
||||
* @param callback callback function executed when an event is fired
|
||||
*/
|
||||
subscribe(targetObj: object, eventName: string, callback: any): void;
|
||||
/**
|
||||
* unsubscript event
|
||||
* @param targetObj objects that subscribe to events
|
||||
* @param eventName the event name
|
||||
*/
|
||||
unsubscribe(targetObj: object, eventName: string): void;
|
||||
/**
|
||||
* triggering event
|
||||
* @param targetObj objects that subscribe to events
|
||||
* @param eventName the event name
|
||||
* @param data passed to the callback function when the event is fired
|
||||
*/
|
||||
send(targetObj: object, eventName: string, data: any): void;
|
||||
}
|
||||
|
||||
declare let observer: Observer;
|
||||
16
types/node-observer/node-observer-tests.ts
Normal file
16
types/node-observer/node-observer-tests.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import observer = require("node-observer");
|
||||
|
||||
class Demo {
|
||||
sayHello(msg: string) {
|
||||
console.log(`hello ${msg}`);
|
||||
}
|
||||
}
|
||||
|
||||
const obj = new Demo();
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
observer.subscribe(obj, "hello", obj.sayHello);
|
||||
}
|
||||
observer.unsubscribe(obj, "hello");
|
||||
|
||||
observer.send(obj, "hello", "sent event");
|
||||
24
types/node-observer/tsconfig.json
Normal file
24
types/node-observer/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"node-observer-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/node-observer/tslint.json
Normal file
3
types/node-observer/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user