Update typings to use namespace

This commit is contained in:
David Broder-Rodgers
2017-12-18 13:55:46 +00:00
parent 034679e934
commit a7c9e3bb8a
2 changed files with 15 additions and 21 deletions

View File

@@ -1,16 +1,16 @@
const newsEventname = 'openNewsListPage';
universalLinks.subscribe(newsEventname, onNewsListPageRequested);
function onNewsListPageRequested(eventData: EventData) {
function onNewsListPageRequested(eventData: universalLinks.EventData) {
alert('Did launch application with news link: ' + eventData.url);
}
universalLinks.unsubscribe('openNewsListPage');
window.universalLinks.subscribe(null, onOtherLinkRequested);
universalLinks.subscribe(null, onOtherLinkRequested);
function onOtherLinkRequested(eventData: EventData) {
function onOtherLinkRequested(eventData: universalLinks.EventData) {
alert('Did launch application with other link: ' + eventData.url);
}
window.universalLinks.unsubscribe(null);
universalLinks.unsubscribe(null);

View File

@@ -3,22 +3,16 @@
// Definitions by: David Broder-Rodgers <https://github.com/broder>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface EventData {
url: string;
scheme: string;
host: string;
path: string;
params: { [key: string]: string };
hash: string;
}
declare namespace universalLinks {
function subscribe(eventName: string | null, callback: (data: EventData) => void): void;
function unsubscribe(eventName: string | null): void;
interface UniversalLinks {
subscribe(eventName: string | null, callback: (data: EventData) => void): void;
unsubscribe(eventName: string | null): void;
interface EventData {
url: string;
scheme: string;
host: string;
path: string;
params: { [key: string]: string };
hash: string;
}
}
interface Window {
universalLinks: UniversalLinks;
}
declare var universalLinks: UniversalLinks;