From 88cac1b55b32dc86630964a1ae91ed6e9996e00b Mon Sep 17 00:00:00 2001 From: borislavjivkov Date: Sun, 7 Feb 2016 23:03:19 +0200 Subject: [PATCH 1/3] Added definitions for pace(https://github.com/HubSpot/pace) --- pace/pace-tests.ts | 61 ++++++++++++++++++++++++ pace/pace.d.ts | 113 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 pace/pace-tests.ts create mode 100644 pace/pace.d.ts diff --git a/pace/pace-tests.ts b/pace/pace-tests.ts new file mode 100644 index 0000000000..c4a6f4cec5 --- /dev/null +++ b/pace/pace-tests.ts @@ -0,0 +1,61 @@ +/// + +pace.start({ + document: false +}); + +pace.start(); + +pace.restart(); + +pace.stop(); + +var paceOptions: PaceOptions; + +paceOptions = { + // Disable the 'elements' source + elements: false, + + // Only show the progress on regular and ajax-y page navigation, + // not every request + restartOnRequestAfter: false +} + +paceOptions = { + ajax: false, // disabled + document: false, // disabled + eventLag: false, // disabled + elements: { + selectors: ['.my-page'] + } +}; + +paceOptions = { + elements: { + selectors: ['.timeline,.timeline-error', '.user-profile,.profile-error'] + } +} + +paceOptions = { + restartOnPushState: false +} + +paceOptions = { + restartOnRequestAfter: false +} + +pace.options = { + restartOnRequestAfter: false +} + +pace.ignore(function(){ +}); + +pace.track(function(){ +}); + +pace.options = { + ajax: { + ignoreURLs: ['some-substring', /some-regexp/] + } +}; diff --git a/pace/pace.d.ts b/pace/pace.d.ts new file mode 100644 index 0000000000..8eaa8c5644 --- /dev/null +++ b/pace/pace.d.ts @@ -0,0 +1,113 @@ +// Type definitions for pace v0.7.5 +// Project: https://github.com/HubSpot/pace +// Definitions by: Borislav Zhivkov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface PaceOptions { + /** + * How long should it take for the bar to animate to a new point after receiving it + */ + catchupTime?: number; + /** + * How quickly should the bar be moving before it has any progress info from a new source in %/ms + */ + initialRate?: number; + /** + * What is the minimum amount of time the bar should be on the screen. Irrespective of this number, the bar will always be on screen for 33 * (100 / maxProgressPerFrame) + ghostTime ms. + */ + minTime?: number; + /** + * What is the minimum amount of time the bar should sit after the last update before disappearing + */ + ghostTime?: number; + /** + * Its easy for a bunch of the bar to be eaten in the first few frames before we know how much there is to load. This limits how much of the bar can be used per frame + */ + maxProgressPerFrame?: number; + /** + * This tweaks the animation easing + */ + easeFactor?: number; + /** + * Should pace automatically start when the page is loaded, or should it wait for `start` to be called? Always false if pace is loaded with AMD or CommonJS. + */ + startOnPageLoad?: boolean; + /** + * Should we restart the browser when pushState or replaceState is called? (Generally means ajax navigation has occured) + */ + restartOnPushState?: boolean; + /** + * Should we show the progress bar for every ajax request (not just regular or ajax-y page navigation)? Set to false to disable. If so, how many ms does the request have to be running for before we show the progress? + */ + restartOnRequestAfter?: boolean | number; + /** + * What element should the pace element be appended to on the page? + */ + target?: string; + document?: boolean | string; + elements?: boolean | PaceElementsOptions; + eventLag?: boolean | PaceEventLagOptions; + ajax?: boolean | PaceAjaxOptions; +} + +interface PaceElementsOptions { + /** + * How frequently in ms should we check for the elements being tested for using the element monitor? + */ + checkInterval?: number; + /** + * What elements should we wait for before deciding the page is fully loaded (not required) + */ + selectors?: string[]; +} + +interface PaceEventLagOptions { + /** + * When we first start measuring event lag, not much is going on in the browser yet, so it's not uncommon for the numbers to be abnormally low for the first few samples. This configures how many samples we need before we consider a low number to mean completion. + */ + minSamples?: number; + /** + * How many samples should we average to decide what the current lag is? + */ + sampleCount?: number; + /** + * Above how many ms of lag is the CPU considered busy? + */ + lagThreshold?: number; +} + +interface PaceAjaxOptions { + /** + * Which HTTP methods should we track? + */ + trackMethods?: string[]; + /** + * Should we track web socket connections? + */ + trackWebSockets?: boolean; + /** + * A list of regular expressions or substrings of URLS we should ignore (for both tracking and restarting) + */ + ignoreURLs?: (string | RegExp)[]; +} + +interface Pace { + options: PaceOptions; + + start(options?: PaceOptions): void; + restart(): void; + stop(): void; + track(fn: () => void, ...args: any[]): void; + ignore(fn: () => void, ...args: any[]): void; + + on(event: string, handler: (...args: any[]) => void, context?: any): void; + off(event: string, handler?: (...args: any[]) => void): void; + once(event: string, handler: (...args: any[]) => void, context?: any): void; +} + +declare enum PaceEvent { start, stop, restart, done, hide } + +declare var pace: Pace; +declare module "pace" { + export = pace; +} From f387303f41af1dfd6868ed0291f1522b264fa1f8 Mon Sep 17 00:00:00 2001 From: borislavjivkov Date: Thu, 11 Feb 2016 21:44:24 +0200 Subject: [PATCH 2/3] Moved pace interfaces to separate module --- pace/pace-tests.ts | 2 +- pace/pace.d.ts | 208 +++++++++++++++++++++++---------------------- 2 files changed, 106 insertions(+), 104 deletions(-) diff --git a/pace/pace-tests.ts b/pace/pace-tests.ts index c4a6f4cec5..cecb55ca26 100644 --- a/pace/pace-tests.ts +++ b/pace/pace-tests.ts @@ -10,7 +10,7 @@ pace.restart(); pace.stop(); -var paceOptions: PaceOptions; +var paceOptions: PaceInterfaces.PaceOptions; paceOptions = { // Disable the 'elements' source diff --git a/pace/pace.d.ts b/pace/pace.d.ts index 8eaa8c5644..3565ed6cd1 100644 --- a/pace/pace.d.ts +++ b/pace/pace.d.ts @@ -3,111 +3,113 @@ // Definitions by: Borislav Zhivkov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -interface PaceOptions { - /** - * How long should it take for the bar to animate to a new point after receiving it - */ - catchupTime?: number; - /** - * How quickly should the bar be moving before it has any progress info from a new source in %/ms - */ - initialRate?: number; - /** - * What is the minimum amount of time the bar should be on the screen. Irrespective of this number, the bar will always be on screen for 33 * (100 / maxProgressPerFrame) + ghostTime ms. - */ - minTime?: number; - /** - * What is the minimum amount of time the bar should sit after the last update before disappearing - */ - ghostTime?: number; - /** - * Its easy for a bunch of the bar to be eaten in the first few frames before we know how much there is to load. This limits how much of the bar can be used per frame - */ - maxProgressPerFrame?: number; - /** - * This tweaks the animation easing - */ - easeFactor?: number; - /** - * Should pace automatically start when the page is loaded, or should it wait for `start` to be called? Always false if pace is loaded with AMD or CommonJS. - */ - startOnPageLoad?: boolean; - /** - * Should we restart the browser when pushState or replaceState is called? (Generally means ajax navigation has occured) - */ - restartOnPushState?: boolean; - /** - * Should we show the progress bar for every ajax request (not just regular or ajax-y page navigation)? Set to false to disable. If so, how many ms does the request have to be running for before we show the progress? - */ - restartOnRequestAfter?: boolean | number; - /** - * What element should the pace element be appended to on the page? - */ - target?: string; - document?: boolean | string; - elements?: boolean | PaceElementsOptions; - eventLag?: boolean | PaceEventLagOptions; - ajax?: boolean | PaceAjaxOptions; +declare module PaceInterfaces { + interface PaceOptions { + /** + * How long should it take for the bar to animate to a new point after receiving it + */ + catchupTime?: number; + /** + * How quickly should the bar be moving before it has any progress info from a new source in %/ms + */ + initialRate?: number; + /** + * What is the minimum amount of time the bar should be on the screen. Irrespective of this number, the bar will always be on screen for 33 * (100 / maxProgressPerFrame) + ghostTime ms. + */ + minTime?: number; + /** + * What is the minimum amount of time the bar should sit after the last update before disappearing + */ + ghostTime?: number; + /** + * Its easy for a bunch of the bar to be eaten in the first few frames before we know how much there is to load. This limits how much of the bar can be used per frame + */ + maxProgressPerFrame?: number; + /** + * This tweaks the animation easing + */ + easeFactor?: number; + /** + * Should pace automatically start when the page is loaded, or should it wait for `start` to be called? Always false if pace is loaded with AMD or CommonJS. + */ + startOnPageLoad?: boolean; + /** + * Should we restart the browser when pushState or replaceState is called? (Generally means ajax navigation has occured) + */ + restartOnPushState?: boolean; + /** + * Should we show the progress bar for every ajax request (not just regular or ajax-y page navigation)? Set to false to disable. If so, how many ms does the request have to be running for before we show the progress? + */ + restartOnRequestAfter?: boolean | number; + /** + * What element should the pace element be appended to on the page? + */ + target?: string; + document?: boolean | string; + elements?: boolean | PaceElementsOptions; + eventLag?: boolean | PaceEventLagOptions; + ajax?: boolean | PaceAjaxOptions; + } + + interface PaceElementsOptions { + /** + * How frequently in ms should we check for the elements being tested for using the element monitor? + */ + checkInterval?: number; + /** + * What elements should we wait for before deciding the page is fully loaded (not required) + */ + selectors?: string[]; + } + + interface PaceEventLagOptions { + /** + * When we first start measuring event lag, not much is going on in the browser yet, so it's not uncommon for the numbers to be abnormally low for the first few samples. This configures how many samples we need before we consider a low number to mean completion. + */ + minSamples?: number; + /** + * How many samples should we average to decide what the current lag is? + */ + sampleCount?: number; + /** + * Above how many ms of lag is the CPU considered busy? + */ + lagThreshold?: number; + } + + interface PaceAjaxOptions { + /** + * Which HTTP methods should we track? + */ + trackMethods?: string[]; + /** + * Should we track web socket connections? + */ + trackWebSockets?: boolean; + /** + * A list of regular expressions or substrings of URLS we should ignore (for both tracking and restarting) + */ + ignoreURLs?: (string | RegExp)[]; + } + + interface Pace { + options: PaceOptions; + + start(options?: PaceOptions): void; + restart(): void; + stop(): void; + track(fn: () => void, ...args: any[]): void; + ignore(fn: () => void, ...args: any[]): void; + + on(event: string, handler: (...args: any[]) => void, context?: any): void; + off(event: string, handler?: (...args: any[]) => void): void; + once(event: string, handler: (...args: any[]) => void, context?: any): void; + } + + enum PaceEvent { start, stop, restart, done, hide } } -interface PaceElementsOptions { - /** - * How frequently in ms should we check for the elements being tested for using the element monitor? - */ - checkInterval?: number; - /** - * What elements should we wait for before deciding the page is fully loaded (not required) - */ - selectors?: string[]; -} - -interface PaceEventLagOptions { - /** - * When we first start measuring event lag, not much is going on in the browser yet, so it's not uncommon for the numbers to be abnormally low for the first few samples. This configures how many samples we need before we consider a low number to mean completion. - */ - minSamples?: number; - /** - * How many samples should we average to decide what the current lag is? - */ - sampleCount?: number; - /** - * Above how many ms of lag is the CPU considered busy? - */ - lagThreshold?: number; -} - -interface PaceAjaxOptions { - /** - * Which HTTP methods should we track? - */ - trackMethods?: string[]; - /** - * Should we track web socket connections? - */ - trackWebSockets?: boolean; - /** - * A list of regular expressions or substrings of URLS we should ignore (for both tracking and restarting) - */ - ignoreURLs?: (string | RegExp)[]; -} - -interface Pace { - options: PaceOptions; - - start(options?: PaceOptions): void; - restart(): void; - stop(): void; - track(fn: () => void, ...args: any[]): void; - ignore(fn: () => void, ...args: any[]): void; - - on(event: string, handler: (...args: any[]) => void, context?: any): void; - off(event: string, handler?: (...args: any[]) => void): void; - once(event: string, handler: (...args: any[]) => void, context?: any): void; -} - -declare enum PaceEvent { start, stop, restart, done, hide } - -declare var pace: Pace; +declare var pace: PaceInterfaces.Pace; declare module "pace" { export = pace; } From 182d6f969eccdc57d8e3942b20e9afd780996be1 Mon Sep 17 00:00:00 2001 From: borislavjivkov Date: Wed, 17 Feb 2016 21:35:50 +0200 Subject: [PATCH 3/3] Rename pace to HubSpot-pace --- pace/pace-tests.ts => HubSpot-pace/HubSpot-pace-tests.ts | 4 ++-- pace/pace.d.ts => HubSpot-pace/HubSpot-pace.d.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) rename pace/pace-tests.ts => HubSpot-pace/HubSpot-pace-tests.ts (90%) rename pace/pace.d.ts => HubSpot-pace/HubSpot-pace.d.ts (97%) diff --git a/pace/pace-tests.ts b/HubSpot-pace/HubSpot-pace-tests.ts similarity index 90% rename from pace/pace-tests.ts rename to HubSpot-pace/HubSpot-pace-tests.ts index cecb55ca26..1c1daa2a68 100644 --- a/pace/pace-tests.ts +++ b/HubSpot-pace/HubSpot-pace-tests.ts @@ -1,4 +1,4 @@ -/// +/// pace.start({ document: false @@ -10,7 +10,7 @@ pace.restart(); pace.stop(); -var paceOptions: PaceInterfaces.PaceOptions; +var paceOptions: HubSpotPaceInterfaces.PaceOptions; paceOptions = { // Disable the 'elements' source diff --git a/pace/pace.d.ts b/HubSpot-pace/HubSpot-pace.d.ts similarity index 97% rename from pace/pace.d.ts rename to HubSpot-pace/HubSpot-pace.d.ts index 3565ed6cd1..e10e0316ac 100644 --- a/pace/pace.d.ts +++ b/HubSpot-pace/HubSpot-pace.d.ts @@ -3,7 +3,7 @@ // Definitions by: Borislav Zhivkov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module PaceInterfaces { +declare module HubSpotPaceInterfaces { interface PaceOptions { /** * How long should it take for the bar to animate to a new point after receiving it @@ -109,7 +109,7 @@ declare module PaceInterfaces { enum PaceEvent { start, stop, restart, done, hide } } -declare var pace: PaceInterfaces.Pace; -declare module "pace" { +declare var pace: HubSpotPaceInterfaces.Pace; +declare module "HubSpot-pace" { export = pace; }