mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-25 01:53:44 +03:00
refactor: rename isBrowser to IS_BROWSER + use only it for detection
This commit is contained in:
parent
040bc239a2
commit
33eaf77dc5
|
@ -6,9 +6,10 @@ import { RedocNormalizedOptions, RedocRawOptions } from '../../services/RedocNor
|
|||
import styled, { media, withProps } from '../../styled-components';
|
||||
import { OptionsContext } from '../OptionsProvider';
|
||||
import { AnimatedChevronButton } from './ChevronSvg';
|
||||
import { IS_BROWSER } from '../../utils/index';
|
||||
|
||||
let Stickyfill;
|
||||
if (typeof window !== 'undefined') {
|
||||
if (IS_BROWSER) {
|
||||
Stickyfill = require('stickyfill').default;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { bind, debounce } from 'decko';
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import { isBrowser } from '../utils/';
|
||||
import { IS_BROWSER } from '../utils/';
|
||||
|
||||
const EVENT = 'hashchange';
|
||||
|
||||
|
@ -18,7 +18,7 @@ class IntHistoryService {
|
|||
}
|
||||
|
||||
get hash(): string {
|
||||
return isBrowser ? window.location.hash : '';
|
||||
return IS_BROWSER ? window.location.hash : '';
|
||||
}
|
||||
|
||||
subscribe(cb): () => void {
|
||||
|
@ -35,13 +35,13 @@ class IntHistoryService {
|
|||
};
|
||||
|
||||
bind() {
|
||||
if (isBrowser) {
|
||||
if (IS_BROWSER) {
|
||||
window.addEventListener('hashchange', this.emit, false);
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
if (isBrowser) {
|
||||
if (IS_BROWSER) {
|
||||
window.removeEventListener('hashchange', this.emit);
|
||||
}
|
||||
this.causedHashChange = false;
|
||||
|
@ -54,13 +54,13 @@ class IntHistoryService {
|
|||
return;
|
||||
}
|
||||
if (rewriteHistory) {
|
||||
if (isBrowser) {
|
||||
if (IS_BROWSER) {
|
||||
window.history.replaceState(null, '', window.location.href.split('#')[0] + '#' + hash);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.causedHashChange = true;
|
||||
if (isBrowser) {
|
||||
if (IS_BROWSER) {
|
||||
window.location.hash = hash;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { resolve as urlResolve } from 'url';
|
|||
|
||||
import { OpenAPIRef, OpenAPISchema, OpenAPISpec, Referenced } from '../types';
|
||||
|
||||
import { appendToMdHeading, isBrowser } from '../utils/';
|
||||
import { appendToMdHeading, IS_BROWSER } from '../utils/';
|
||||
import { JsonPointer } from '../utils/JsonPointer';
|
||||
import { isNamedDefinition } from '../utils/openapi';
|
||||
import { buildComponentComment, COMPONENT_REGEXP } from './MarkdownRenderer';
|
||||
|
@ -54,7 +54,7 @@ export class OpenAPIParser {
|
|||
|
||||
this.spec = spec;
|
||||
|
||||
const href = isBrowser ? window.location.href : '';
|
||||
const href = IS_BROWSER ? window.location.href : '';
|
||||
if (typeof specUrl === 'string') {
|
||||
this.specUrl = urlResolve(href, specUrl);
|
||||
} else {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { bind } from 'decko';
|
||||
import * as EventEmitter from 'eventemitter3';
|
||||
|
||||
import { isBrowser, querySelector, Throttle } from '../utils';
|
||||
import { IS_BROWSER, querySelector, Throttle } from '../utils';
|
||||
import { RedocNormalizedOptions } from './RedocNormalizedOptions';
|
||||
|
||||
const EVENT = 'scroll';
|
||||
|
@ -11,7 +11,7 @@ export class ScrollService {
|
|||
private _emiter: EventEmitter;
|
||||
private _prevOffsetY: number = 0;
|
||||
constructor(private options: RedocNormalizedOptions) {
|
||||
this._scrollParent = isBrowser ? window : undefined;
|
||||
this._scrollParent = IS_BROWSER ? window : undefined;
|
||||
this._emiter = new EventEmitter();
|
||||
this.bind();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { IMenuItem } from './MenuStore';
|
||||
import { OperationModel } from './models';
|
||||
import { IS_BROWSER } from '../utils/';
|
||||
|
||||
let worker;
|
||||
|
||||
if (typeof URL !== 'undefined') {
|
||||
if (IS_BROWSER) {
|
||||
try {
|
||||
// tslint:disable-next-line
|
||||
worker = require('workerize-loader?inline&fallback=false!./SearchWorker.worker');
|
||||
} catch (e) {
|
||||
worker = require('./SearchWorker.worker').default;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { OpenAPIContact, OpenAPIInfo, OpenAPILicense } from '../../types';
|
||||
import { isBrowser } from '../../utils/';
|
||||
import { IS_BROWSER } from '../../utils/';
|
||||
import { OpenAPIParser } from '../OpenAPIParser';
|
||||
import { RedocNormalizedOptions } from '../RedocNormalizedOptions';
|
||||
|
||||
|
@ -25,12 +25,12 @@ export class ApiInfoModel implements OpenAPIInfo {
|
|||
return this.parser.specUrl;
|
||||
}
|
||||
|
||||
if (isBrowser && window.Blob && window.URL) {
|
||||
if (IS_BROWSER && window.Blob && window.URL) {
|
||||
const blob = new Blob([JSON.stringify(this.parser.spec, null, 2)], {
|
||||
type: 'application/json',
|
||||
});
|
||||
return window.URL.createObjectURL(blob);
|
||||
} else if (!isBrowser) {
|
||||
} else if (!IS_BROWSER) {
|
||||
return (
|
||||
'data:application/octet-stream;base64,' +
|
||||
new Buffer(JSON.stringify(this.parser.spec, null, 2)).toString('base64')
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
|
||||
export const IS_BROWSER = typeof window !== 'undefined' && 'HTMLElement' in window;
|
||||
|
||||
export function querySelector(selector: string): Element | null {
|
||||
if (typeof document !== 'undefined') {
|
||||
|
|
Loading…
Reference in New Issue
Block a user