mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-26 23:10:33 +03:00
more refactor
This commit is contained in:
parent
d2eca9fcde
commit
68e77f9350
|
@ -1,22 +1,22 @@
|
|||
'use strict';
|
||||
|
||||
import { SchemaManager, RedocComponent, BaseComponent } from '../base';
|
||||
import OptionsManager from '../../options';
|
||||
import { OptionsService } from '../../services/index';
|
||||
|
||||
@RedocComponent({
|
||||
selector: 'api-info',
|
||||
styleUrls: ['./lib/components/ApiInfo/api-info.css'],
|
||||
templateUrl: './lib/components/ApiInfo/api-info.html'
|
||||
})
|
||||
@Reflect.metadata('parameters', [[SchemaManager], [OptionsManager]])
|
||||
@Reflect.metadata('parameters', [[SchemaManager], [OptionsService]])
|
||||
export class ApiInfo extends BaseComponent {
|
||||
constructor(schemaMgr, optionsMgr) {
|
||||
constructor(schemaMgr, optionsService) {
|
||||
super(schemaMgr);
|
||||
this.optionsMgr = optionsMgr;
|
||||
this.optionsService = optionsService;
|
||||
}
|
||||
|
||||
prepareModel() {
|
||||
this.data = this.componentSchema.info;
|
||||
this.specUrl = this.optionsMgr.options.specUrl;
|
||||
this.specUrl = this.optionsService.options.specUrl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@ import { TestComponentBuilder } from '@angular/compiler/testing';
|
|||
|
||||
import ApiInfo from 'lib/components/ApiInfo/api-info';
|
||||
import SchemaManager from 'lib/utils/SchemaManager';
|
||||
import OptionsManager from 'lib/options';
|
||||
import { OptionsService } from 'lib/services/index';
|
||||
|
||||
let optsMgr = new OptionsManager();
|
||||
let optionsService = new OptionsService();
|
||||
|
||||
describe('Redoc components', () => {
|
||||
describe('ApiInfo Component', () => {
|
||||
|
@ -26,7 +26,7 @@ describe('Redoc components', () => {
|
|||
let fixture;
|
||||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: new SchemaManager()}),
|
||||
provide(OptionsManager, {useValue: optsMgr})
|
||||
provide(OptionsService, {useValue: optionsService})
|
||||
]);
|
||||
|
||||
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||
|
|
|
@ -5,7 +5,7 @@ import {CORE_DIRECTIVES} from '@angular/common';
|
|||
import { DynamicComponentLoader } from '@angular/core';
|
||||
|
||||
import { JsonSchema } from './json-schema';
|
||||
import OptionsManager from '../../options';
|
||||
import { OptionsService } from '../../services/index';
|
||||
import SchemaManager from '../../utils/SchemaManager';
|
||||
|
||||
|
||||
|
@ -18,14 +18,15 @@ var cache = {};
|
|||
template: '',
|
||||
directives: [CORE_DIRECTIVES]
|
||||
})
|
||||
@Reflect.metadata('parameters', [[SchemaManager], [ViewContainerRef], [ElementRef], [DynamicComponentLoader], [OptionsManager]])
|
||||
@Reflect.metadata('parameters', [[SchemaManager], [ViewContainerRef], [
|
||||
ElementRef], [DynamicComponentLoader], [OptionsService]])
|
||||
export class JsonSchemaLazy {
|
||||
|
||||
constructor(schemaMgr, viewRef, elementRef, dcl, optionsMgr) {
|
||||
constructor(schemaMgr, viewRef, elementRef, dcl, optionsService) {
|
||||
this.viewRef = viewRef;
|
||||
this.elementRef = elementRef;
|
||||
this.dcl = dcl;
|
||||
this.optionsMgr = optionsMgr;
|
||||
this.optionsService = optionsService;
|
||||
this.schemaMgr = schemaMgr;
|
||||
}
|
||||
|
||||
|
@ -35,7 +36,7 @@ export class JsonSchemaLazy {
|
|||
}
|
||||
|
||||
load() {
|
||||
if (this.optionsMgr.options.disableLazySchemas) return;
|
||||
if (this.optionsService.options.disableLazySchemas) return;
|
||||
if (this.loaded) return;
|
||||
if (this.pointer) {
|
||||
this.dcl.loadNextToLocation(JsonSchema, this.viewRef).then((compRef) => {
|
||||
|
|
|
@ -17,7 +17,7 @@ import { TestComponentBuilder } from '@angular/compiler/testing';
|
|||
|
||||
import JsonSchemaLazy from 'lib/components/JsonSchema/json-schema-lazy';
|
||||
import SchemaManager from 'lib/utils/SchemaManager';
|
||||
import OptionsManager from 'lib/options';
|
||||
import { OptionsService } from 'lib/services/index';
|
||||
|
||||
describe('Redoc components', () => {
|
||||
describe('JsonSchemaLazy Component', () => {
|
||||
|
@ -33,7 +33,7 @@ describe('Redoc components', () => {
|
|||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: schemaMgr}),
|
||||
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
|
||||
provide(OptionsManager, {useClass: OptionsManager})
|
||||
provide(OptionsService, {useClass: OptionsService})
|
||||
]);
|
||||
beforeEach(inject([TestComponentBuilder, DynamicComponentLoader], (tcb, dcl) => {
|
||||
builder = tcb;
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
import { getChildDebugElement } from 'tests/helpers';
|
||||
import { Component, provide } from '@angular/core';
|
||||
import OptionsManager from 'lib/options';
|
||||
|
||||
import {
|
||||
inject,
|
||||
beforeEach,
|
||||
beforeEachProviders,
|
||||
it
|
||||
} from '@angular/core/testing';
|
||||
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
|
||||
import JsonSchema from 'lib/components/JsonSchema/json-schema';
|
||||
import { OptionsService } from 'lib/services/index';
|
||||
import { getChildDebugElement } from 'tests/helpers';
|
||||
|
||||
|
||||
import { JsonSchema } from 'lib/components/index';
|
||||
import SchemaManager from 'lib/utils/SchemaManager';
|
||||
|
||||
describe('Redoc components', () => {
|
||||
|
@ -24,7 +24,7 @@ describe('Redoc components', () => {
|
|||
let fixture;
|
||||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: schemaMgr}),
|
||||
provide(OptionsManager, {useClass: OptionsManager})
|
||||
provide(OptionsService, {useClass: OptionsService})
|
||||
]);
|
||||
beforeEach(inject([TestComponentBuilder], (tcb) => {
|
||||
builder = tcb;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
import { getChildDebugElement } from 'tests/helpers';
|
||||
import { Component, provide } from '@angular/core';
|
||||
import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter';
|
||||
|
||||
import {
|
||||
inject,
|
||||
async,
|
||||
|
@ -11,12 +9,13 @@ import {
|
|||
beforeEachProviders,
|
||||
it
|
||||
} from '@angular/core/testing';
|
||||
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
|
||||
import Method from 'lib/components/Method/method';
|
||||
import { getChildDebugElement } from 'tests/helpers';
|
||||
|
||||
import { Method } from 'lib/components/index';
|
||||
import SchemaManager from 'lib/utils/SchemaManager';
|
||||
import OptionsManager from 'lib/options';
|
||||
import OptionsService from 'lib/services/index';
|
||||
|
||||
describe('Redoc components', () => {
|
||||
describe('Method Component', () => {
|
||||
|
@ -25,7 +24,7 @@ describe('Redoc components', () => {
|
|||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: new SchemaManager()}),
|
||||
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
|
||||
provide(OptionsManager, {useClass: OptionsManager})
|
||||
provide(OptionsService, {useClass: OptionsService})
|
||||
]);
|
||||
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||
builder = tcb;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import { getChildDebugElement } from 'tests/helpers';
|
||||
import {Component, provide} from '@angular/core';
|
||||
import OptionsManager from 'lib/options';
|
||||
import { OptionsService } from 'lib/services/index';
|
||||
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
||||
|
||||
import {
|
||||
|
@ -25,7 +25,7 @@ describe('Redoc components', () => {
|
|||
let fixture;
|
||||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: new SchemaManager()}),
|
||||
provide(OptionsManager, {useClass: OptionsManager}),
|
||||
provide(OptionsService, {useClass: OptionsService}),
|
||||
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter})
|
||||
]);
|
||||
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
import {provide, enableProdMode} from '@angular/core';
|
||||
import {ElementRef} from '@angular/core';
|
||||
import { provide, enableProdMode, ElementRef} from '@angular/core';
|
||||
import { bootstrap } from '@angular/platform-browser-dynamic';
|
||||
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
||||
|
||||
import detectScollParent from 'scrollparent';
|
||||
|
||||
import { RedocComponent, BaseComponent } from '../base';
|
||||
import SchemaManager from '../../utils/SchemaManager';
|
||||
|
||||
import {
|
||||
ApiInfo,
|
||||
ApiLogo,
|
||||
|
@ -17,10 +12,10 @@ import {
|
|||
SideMenu
|
||||
} from '../index';
|
||||
import { StickySidebar } from '../../shared/components/index';
|
||||
import SchemaManager from '../../utils/SchemaManager';
|
||||
import { OptionsService, RedocEventsService } from '../../services/index';
|
||||
|
||||
import OptionsManager from '../../options';
|
||||
import { RedocEventsService } from '../../services/index';
|
||||
|
||||
import detectScollParent from 'scrollparent';
|
||||
import './redoc-loading-styles.css!css';
|
||||
|
||||
var dom = new BrowserDomAdapter();
|
||||
|
@ -38,7 +33,7 @@ var _modeLocked = false;
|
|||
directives: [ApiInfo, ApiLogo, MethodsList, SideMenu, StickySidebar]
|
||||
})
|
||||
@Reflect.metadata('parameters', [
|
||||
[SchemaManager], [OptionsManager], [ElementRef], [RedocEventsService]])
|
||||
[SchemaManager], [OptionsService], [ElementRef], [RedocEventsService]])
|
||||
export class Redoc extends BaseComponent {
|
||||
constructor(schemaMgr, optionsMgr, elementRef, events) {
|
||||
super(schemaMgr);
|
||||
|
@ -71,11 +66,11 @@ export class Redoc extends BaseComponent {
|
|||
}
|
||||
|
||||
static init(specUrl, options) {
|
||||
var optionsMgr = new OptionsManager();
|
||||
optionsMgr.options = options;
|
||||
optionsMgr.options.specUrl = optionsMgr.options.specUrl || specUrl;
|
||||
var optionsService = new OptionsService(dom);
|
||||
optionsService.options = options;
|
||||
optionsService.options.specUrl = optionsService.options.specUrl || specUrl;
|
||||
var providers = [
|
||||
provide(OptionsManager, {useValue: optionsMgr})
|
||||
provide(OptionsService, {useValue: optionsService})
|
||||
];
|
||||
|
||||
if (Redoc.appRef) {
|
||||
|
@ -84,7 +79,7 @@ export class Redoc extends BaseComponent {
|
|||
Redoc.showLoadingAnimation();
|
||||
return SchemaManager.instance().load(specUrl)
|
||||
.then(() => {
|
||||
if (!_modeLocked && !optionsMgr.options.debugMode) {
|
||||
if (!_modeLocked && !optionsService.options.debugMode) {
|
||||
enableProdMode();
|
||||
_modeLocked = true;
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ import { TestComponentBuilder } from '@angular/compiler/testing';
|
|||
|
||||
import Redoc from 'lib/components/Redoc/redoc';
|
||||
import SchemaManager from 'lib/utils/SchemaManager';
|
||||
import OptionsManager from 'lib/options';
|
||||
import { OptionsService } from 'lib/services/index';
|
||||
|
||||
let optsMgr = new OptionsManager();
|
||||
let optsMgr = new OptionsService();
|
||||
|
||||
describe('Redoc components', () => {
|
||||
describe('Redoc Component', () => {
|
||||
|
@ -26,7 +26,7 @@ describe('Redoc components', () => {
|
|||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: new SchemaManager()}),
|
||||
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
|
||||
provide(OptionsManager, {useValue: optsMgr})
|
||||
provide(OptionsService, {useValue: optsMgr})
|
||||
]);
|
||||
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||
builder = tcb;
|
||||
|
@ -152,7 +152,7 @@ describe('Redoc components', () => {
|
|||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: new SchemaManager()}),
|
||||
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
|
||||
provide(OptionsManager, {useValue: optsMgr})
|
||||
provide(OptionsService, {useValue: optsMgr})
|
||||
]);
|
||||
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||
builder = tcb;
|
||||
|
|
|
@ -5,7 +5,7 @@ import JsonPointer from '../../utils/JsonPointer';
|
|||
import { JsonSchema, JsonSchemaLazy } from '../index';
|
||||
import {Zippy} from '../../shared/components/index';
|
||||
import {statusCodeType} from '../../utils/helpers';
|
||||
import OptionsManager from '../../options';
|
||||
import { OptionsService } from '../../services/index';
|
||||
|
||||
function isNumeric(n) {
|
||||
return (!isNaN(parseFloat(n)) && isFinite(n));
|
||||
|
@ -17,7 +17,7 @@ function isNumeric(n) {
|
|||
styleUrls: ['./lib/components/ResponsesList/responses-list.css'],
|
||||
directives: [JsonSchema, Zippy, JsonSchemaLazy]
|
||||
})
|
||||
@Reflect.metadata('parameters', [[SchemaManager], [OptionsManager]])
|
||||
@Reflect.metadata('parameters', [[SchemaManager], [OptionsService]])
|
||||
export class ResponsesList extends BaseComponent {
|
||||
constructor(schemaMgr, optionsMgr) {
|
||||
super(schemaMgr);
|
||||
|
|
|
@ -6,7 +6,7 @@ import { global } from '@angular/core/src/facade/lang';
|
|||
|
||||
import { RedocComponent, BaseComponent, SchemaManager } from '../base';
|
||||
import { RedocEventsService } from '../../services/index';
|
||||
import OptionsManager from '../../options';
|
||||
import { OptionsService } from '../../services/index';
|
||||
|
||||
const CHANGE = {
|
||||
NEXT : 1,
|
||||
|
@ -26,7 +26,7 @@ const INVIEW_POSITION = {
|
|||
styleUrls: ['./lib/components/SideMenu/side-menu.css']
|
||||
})
|
||||
@Reflect.metadata('parameters', [[SchemaManager], [ElementRef],
|
||||
[BrowserDomAdapter], [OptionsManager], [RedocEventsService]])
|
||||
[BrowserDomAdapter], [OptionsService], [RedocEventsService]])
|
||||
export class SideMenu extends BaseComponent {
|
||||
constructor(schemaMgr, elementRef, dom, optionsMgr, events) {
|
||||
super(schemaMgr);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import { getChildDebugElement, mouseclick} from 'tests/helpers';
|
||||
import {Component, provide, ViewMetadata} from '@angular/core';
|
||||
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
||||
import OptionsManager from 'lib/options';
|
||||
import { OptionsService } from 'lib/services/index';
|
||||
|
||||
import {
|
||||
inject,
|
||||
|
@ -20,7 +20,7 @@ import MethodsList from 'lib/components/MethodsList/methods-list';
|
|||
import SideMenu from 'lib/components/SideMenu/side-menu';
|
||||
import SchemaManager from 'lib/utils/SchemaManager';
|
||||
|
||||
let testOptions = new OptionsManager();
|
||||
let testOptions = new OptionsService();
|
||||
testOptions.options = {
|
||||
scrollYOffset: () => 0,
|
||||
scrollParent: window
|
||||
|
@ -34,7 +34,7 @@ describe('Redoc components', () => {
|
|||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: new SchemaManager()}),
|
||||
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
|
||||
provide(OptionsManager, {useValue: testOptions})
|
||||
provide(OptionsService, {useValue: testOptions})
|
||||
]);
|
||||
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||
builder = tcb;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
export * from './events.service.js';
|
||||
export * from './options.service.js';
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { isFunction, isString } from '@angular/core/src/facade/lang';
|
||||
import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter';
|
||||
import { global } from '@angular/core/src/facade/lang';
|
||||
|
||||
var defaults = {
|
||||
const defaults = {
|
||||
scrollYOffset: 0,
|
||||
disableLazySchemas: false,
|
||||
debugMode: global.redocDebugMode
|
||||
debugMode: global && global.redocDebugMode
|
||||
};
|
||||
|
||||
var OPTION_NAMES = new Set(['scrollYOffset', 'disableLazySchemas', 'specUrl']);
|
||||
const OPTION_NAMES = new Set(['scrollYOffset', 'disableLazySchemas', 'specUrl']);
|
||||
|
||||
@Injectable()
|
||||
@Reflect.metadata('parameters', [[BrowserDomAdapter]])
|
||||
export default class OptionsManager {
|
||||
constructor() {
|
||||
export class OptionsService {
|
||||
constructor(dom) {
|
||||
this._options = defaults;
|
||||
this.dom = new BrowserDomAdapter();
|
||||
this.dom = dom;
|
||||
}
|
||||
|
||||
get options() {
|
|
@ -69,9 +69,6 @@
|
|||
"map": {
|
||||
"http": "npm:stream-http@2.3.0"
|
||||
}
|
||||
},
|
||||
"npm:@angular/core@2.0.0-rc.1": {
|
||||
"format": "esm"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -33,9 +33,6 @@ System.config({
|
|||
},
|
||||
"jspm_packages/npm/json-schema-view-js@0.2.0/src/*": {
|
||||
"format": "esm"
|
||||
},
|
||||
"npm:@angular/**/*": {
|
||||
"format": "esm"
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -149,6 +146,7 @@ System.config({
|
|||
"process": "github:jspm/nodelibs-process@0.1.2"
|
||||
},
|
||||
"npm:@angular/core@2.0.0-rc.1": {
|
||||
"process": "github:jspm/nodelibs-process@0.1.2",
|
||||
"rxjs": "npm:rxjs@5.0.0-beta.6",
|
||||
"zone.js": "npm:zone.js@0.6.12"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user