Merge pull request #17670 from kbukum/master

* added new definiton type for 'framebus' library.
This commit is contained in:
Ryan Cavanaugh
2017-07-11 23:48:25 -07:00
committed by GitHub
4 changed files with 144 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import * as framebus from "framebus";
let popup = window.open('https://example.com');
framebus.include(popup);
framebus.emit('hello popup and friends!');
framebus.target('https://example.com').on('my cool event', () => {});
let callback = (data: any) => {
console.log('Got back %s as a reply!', data);
};
framebus.publish('Marco!', callback, 'http://listener.example.com');
framebus.publish('Marco!', callback, 'http://listener.example.com');

105
types/framebus/index.d.ts vendored Normal file
View File

@@ -0,0 +1,105 @@
// Type definitions for framebus 2.0
// Project: https://github.com/braintree/framebus
// Definitions by: kbukum <https://github.com/kbukum>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/*~ If this module is a UMD module that exposes a global variable 'myLib' when
*~ loaded outside a module loader environment, declare that global here.
*~ Otherwise, delete this declaration.
*/
export as namespace framebus;
export interface FrameBus {
publish(event: string, ...args: any[]): boolean;
pub(event: string, ...args: any[]): boolean;
trigger(event: string, ...args: any[]): boolean;
emit(event: string, ...args: any[]): boolean;
subscribe(event: string, fn: (...args: any[]) => any): boolean;
sub(event: string, fn: (...args: any[]) => any): boolean;
on(event: string, fn: (...args: any[]) => any): boolean;
unsubscribe(event: string, fn: (...args: any[]) => any): boolean;
unsub(event: string, fn: (...args: any[]) => any): boolean;
off(event: string, fn: (...args: any[]) => any): boolean;
}
/*~ If this module has methods, declare them as functions like so.
*/
/**
* let popup = window.open('https://example.com');
* framebus.include(popup);
* framebus.emit('hello popup and friends!');
* @param popup
*/
export function include(popup: Window): boolean;
/**
* framebus.target('https://example.com').on('my cool event', function () {});
* // will ignore all incoming 'my cool event' NOT from 'https://example.com'
* @param origin {string}
*/
export function target(origin: string): FrameBus;
/**
* let callback = (data: any) => {
* console.log('Got back %s as a reply!', data)
* }
* framebus.publish('Marco!', callback, 'http://listener.example.com');
* @param event {string} The name of the event
* @param args {...any[]} The data to give to subscribers
* // @param last{callback(data)} Give subscribers a function for easy, direct replies
*/
export function publish(event: string, ...args: any[]/* fn: callback(data:)*/): boolean;
/**
* publish = pub = trigger = emit
* framebus.publish('Marco!', callback, 'http://listener.example.com');
* @param event {string} The name of the event
* @param args {...any[]} The data to give to subscribers
* // @param last{callback(data)} Give subscribers a function for easy, direct replies
*/
export function pub(event: string, ...args: any[]): boolean;
/**
* publish = pub = trigger = emit
* @param event {string} The name of the event
* @param args {...any[]} The data to give to subscribers
* // @param last{callback(data)} Give subscribers a function for easy, direct replies
*/
export function trigger(event: string, ...args: any[]): boolean;
/**
* publish = pub = trigger = emit
* @param event {string} The name of the event
* @param args {...any[]} The data to give to subscribers
* // @param last{callback(data)} Give subscribers a function for easy, direct replies
*/
export function emit(event: string, ...args: any[]): boolean;
/**
* **this** scope is the MessageEvent object from the underlying postMessage
* @param event {string} The name of the event
* @param fn {Callback} ([arg...] [, callback]) Event handler. Arguments are from the publish invocation
*/
export function subscribe(event: string, fn: (...args: any[]) => any): boolean;
/**
* **this** scope is the MessageEvent object from the underlying postMessage
* @param event {string} The name of the event
* @param fn {Callback} ([arg...] [, callback]) Event handler. Arguments are from the publish invocation
*/
export function sub(event: string, fn: (...args: any[]) => any): boolean;
/**
* **this** scope is the MessageEvent object from the underlying postMessage
* @param event {string} The name of the event
* @param fn {Callback} ([arg...] [, callback]) Event handler. Arguments are from the publish invocation
*/
export function on(event: string, fn: (...args: any[]) => any): boolean;
/**
* @param event {string} The name of the event
* @param fn {Callback} The function that was subscribed
*/
export function unsubscribe(event: string, fn: (...args: any[]) => any): boolean;
/**
* @param event {string} The name of the event
* @param fn {Callback} The function that was subscribed
*/
export function unsub(event: string, fn: (...args: any[]) => any): boolean;
/**
* @param event {string} The name of the event
* @param fn {Callback} The function that was subscribed
*/
export function off(event: string, fn: (...args: any[]) => any): boolean;

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"framebus-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }