mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-06 17:29:08 +00:00
Merge pull request #17670 from kbukum/master
* added new definiton type for 'framebus' library.
This commit is contained in:
15
types/framebus/framebus-tests.ts
Normal file
15
types/framebus/framebus-tests.ts
Normal 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
105
types/framebus/index.d.ts
vendored
Normal 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;
|
||||
23
types/framebus/tsconfig.json
Normal file
23
types/framebus/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/framebus/tslint.json
Normal file
1
types/framebus/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user