Merge branch 'offline-js' of https://github.com/EnableSoftware/DefinitelyTyped into EnableSoftware-offline-js

This commit is contained in:
vvakame
2015-09-01 02:24:58 +09:00
2 changed files with 104 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
// Test file for offline-js.
/// <reference path="offline-js.d.ts" />
Offline.options = {
checkOnLoad: false,
interceptRequests: true,
checks: {
xhr: { url: '/connection-test' },
image: { url: 'my-image.gif' },
active: 'image'
},
reconnect: {
initialDelay: 3,
delay: 60
},
requests: true,
game: false
};
Offline.check();
Offline.state;
var handler = () => {},
context = {};
Offline.on("up", handler, context);
Offline.on("down", handler, context);
Offline.on("confirmed-up", handler, context);
Offline.on("confirmed-down", handler, context);
Offline.on("checking", handler, context);
Offline.on("reconnect:started", handler, context);
Offline.on("reconnect:stopped", handler, context);
Offline.on("reconnect:tick", handler, context);
Offline.on("reconnect:connecting", handler, context);
Offline.on("reconnect:failure", handler, context);
Offline.on("requests:flush", handler, context);
Offline.on("requests:hold", handler, context);
Offline.off("up", handler);

64
offline-js/offline-js.d.ts vendored Normal file
View File

@@ -0,0 +1,64 @@
// Type definitions for Offline 0.7.14
// Project: https://github.com/HubSpot/offline
// Definitions by: Chris Wrench <https://github.com/cgwrench>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare var Offline: {
options: OfflineOptions;
check: () => void;
state: string;
on(event: "up", handler: (e: Event) => any, context?: any): void;
on(event: "down", handler: (e: Event) => any, context?: any): void;
on(event: "confirmed-up", handler: (e: Event) => any, context?: any): void;
on(event: "confirmed-down", handler: (e: Event) => any, context?: any): void;
on(event: "checking", handler: (e: Event) => any, context?: any): void;
on(event: "reconnect:started", handler: (e: Event) => any, context?: any): void;
on(event: "reconnect:stopped", handler: (e: Event) => any, context?: any): void;
on(event: "reconnect:tick", handler: (e: Event) => any, context?: any): void;
on(event: "reconnect:connecting", handler: (e: Event) => any, context?: any): void;
on(event: "reconnect:failure", handler: (e: Event) => any, context?: any): void;
on(event: "requests:flush", handler: (e: Event) => any, context?: any): void;
on(event: "requests:hold", handler: (e: Event) => any, context?: any): void;
on(event: string, handler: (e: Event) => any, context?: any): void;
off(event: "up", handler?: (e: Event) => any): void;
off(event: "down", handler?: (e: Event) => any): void;
off(event: "confirmed-up", handler?: (e: Event) => any): void;
off(event: "confirmed-down", handler?: (e: Event) => any): void;
off(event: "checking", handler?: (e: Event) => any): void;
off(event: "reconnect:started", handler?: (e: Event) => any): void;
off(event: "reconnect:stopped", handler?: (e: Event) => any): void;
off(event: "reconnect:tick", handler?: (e: Event) => any): void;
off(event: "reconnect:connecting", handler?: (e: Event) => any): void;
off(event: "reconnect:failure", handler?: (e: Event) => any): void;
off(event: "requests:flush", handler?: (e: Event) => any): void;
off(event: "requests:hold", handler?: (e: Event) => any): void;
off(event: string, handler?: (e: Event) => any): void;
};
interface OfflineOptions {
// TODO Should these types be `boolean|Function`?
// The project documentation is not clear here.
checkOnLoad?: boolean;
interceptRequests?: boolean;
requests?: boolean;
game?: boolean;
checks?: OfflineChecks;
reconnect: {
initialDelay: number;
delay: number;
};
}
interface OfflineChecks {
// TODO "xhr" and "image" probably have different options.
// However, this is not stated in the project documentation.
xhr?: OfflineCheck;
image?: OfflineCheck;
active?: string;
}
interface OfflineCheck {
url: string;
}