mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-25 11:30:03 +00:00
Merge pull request #2988 from spencerwi/master
Add definitions for intercom.js
This commit is contained in:
@@ -144,6 +144,7 @@ All definitions files include a header with the author and editors, so at some p
|
||||
* [i18n-node](https://github.com/mashpie/i18n-node) (by [Maxime LUCE](https://github.com/SomaticIT))
|
||||
* [iCheck](http://damirfoy.com/iCheck/) (by [Dániel Tar](https://github.com/qcz))
|
||||
* [Impress.js](https://github.com/bartaz/impress.js) (by [Boris Yankov](https://github.com/borisyankov))
|
||||
* [Intercom.js](https://github.com/diy/intercom.js) (by [Spencer Williams](https://github.com/spencerwi))
|
||||
* [Imagemagick](http://github.com/rsms/node-imagemagick) (by [Carlos Ballesteros Velasco](https://github.com/soywiz))
|
||||
* [inflection](https://github.com/dreamerslab/node.inflection) (by [Shogo Iwano](https://github.com/shiwano))
|
||||
* [insight](https://github.com/yeoman/insight) (by [vvakame](https://github.com/vvakame))
|
||||
|
||||
20
intercomjs/intercom-tests.ts
Normal file
20
intercomjs/intercom-tests.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/// <reference path="intercom.d.ts" />
|
||||
|
||||
function test_intercom_static() {
|
||||
var instance: intercom.Intercom = Intercom.getInstance();
|
||||
|
||||
var capturedMessage: any;
|
||||
var detect: Function = (msg: any) => capturedMessage = msg;
|
||||
instance.on("test", detect);
|
||||
|
||||
var msgToSend: any = {one: 1, two: "2"};
|
||||
instance.emit("test", msgToSend);
|
||||
console.log(capturedMessage === msgToSend);
|
||||
|
||||
var onceListenerInvokedTimes = 0;
|
||||
instance.once("testOnce", ()=>onceListenerInvokedTimes+=1, 300);
|
||||
instance.once("testOnce", ()=>onceListenerInvokedTimes+=1, 300);
|
||||
console.log(onceListenerInvokedTimes === 1);
|
||||
|
||||
instance.emit("eventWithoutAMessage");
|
||||
}
|
||||
52
intercomjs/intercom.d.ts
vendored
Normal file
52
intercomjs/intercom.d.ts
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
// Type definitions for intercom.js
|
||||
// Project: https://github.com/diy/intercom.js
|
||||
// Definitions by: spencerwi <http://github.com/spencerwi>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module intercom {
|
||||
interface Intercom {
|
||||
/**
|
||||
* Broadcasts a message to all open windows (including the current window).
|
||||
* @param name The string event name
|
||||
* @param message The event data/message
|
||||
*/
|
||||
emit(name: string, message?: any): void;
|
||||
/**
|
||||
* Sets up a listener to be invoked when a message with the given name is received.
|
||||
* @param name The string event name to listen for.
|
||||
* @param fn The listener method to invoke.
|
||||
*/
|
||||
on(name: string, fn: Function): void;
|
||||
/**
|
||||
* Given a unique key to represent the function, fn will be invoked in only one window. The ttl argument represents the number of seconds before the function can be called again.
|
||||
* @param key The unique function identifier key
|
||||
* @param fn The function to be called once
|
||||
* @param ttl The amount of time in seconds to wait before allowing the function to be invoked again.
|
||||
*/
|
||||
once(key: string, fn: Function, ttl?: number): void;
|
||||
/**
|
||||
* Bind to a socket.io socket and forward all received messages to all windows and/or back to the socket.
|
||||
* @param socket A socket.io socket to bind to.
|
||||
* @param options Object with "send" and "receive" keys having values of Boolean or Boolean-producing function to determine whether message(s) should be forwarded to/from the socket.
|
||||
*/
|
||||
bind(socket: any, options?: intercom.SocketBindingOptions): void;
|
||||
}
|
||||
interface SocketBindingOptions {
|
||||
send?: any; /* boolean | (name: string, message: any)=>any */
|
||||
receive?: any; /* boolean | (name: string, message: any)=>any */
|
||||
}
|
||||
}
|
||||
|
||||
interface IntercomStatic {
|
||||
/**
|
||||
* Returns an instance of Intercom. If one doesn't exist, it will be instantiated.
|
||||
* @return an instance of Intercom.
|
||||
*/
|
||||
getInstance(): intercom.Intercom;
|
||||
/**
|
||||
* Removes all data associated with intercom from localStorage.
|
||||
*/
|
||||
destroy(): void;
|
||||
}
|
||||
|
||||
declare var Intercom: IntercomStatic
|
||||
Reference in New Issue
Block a user