mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-12 11:51:10 +08:00
Merge branch 'EnableSoftware-offline-js'
This commit is contained in:
40
offline-js/offline-js-tests.ts
Normal file
40
offline-js/offline-js-tests.ts
Normal 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
64
offline-js/offline-js.d.ts
vendored
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user