more refactor

This commit is contained in:
Roman Hotsiy 2016-05-06 12:46:41 +03:00
parent d2eca9fcde
commit 68e77f9350
16 changed files with 76 additions and 84 deletions

View File

@ -1,22 +1,22 @@
'use strict'; 'use strict';
import {SchemaManager, RedocComponent, BaseComponent} from '../base'; import { SchemaManager, RedocComponent, BaseComponent } from '../base';
import OptionsManager from '../../options'; import { OptionsService } from '../../services/index';
@RedocComponent({ @RedocComponent({
selector: 'api-info', selector: 'api-info',
styleUrls: ['./lib/components/ApiInfo/api-info.css'], styleUrls: ['./lib/components/ApiInfo/api-info.css'],
templateUrl: './lib/components/ApiInfo/api-info.html' templateUrl: './lib/components/ApiInfo/api-info.html'
}) })
@Reflect.metadata('parameters', [[SchemaManager], [OptionsManager]]) @Reflect.metadata('parameters', [[SchemaManager], [OptionsService]])
export class ApiInfo extends BaseComponent { export class ApiInfo extends BaseComponent {
constructor(schemaMgr, optionsMgr) { constructor(schemaMgr, optionsService) {
super(schemaMgr); super(schemaMgr);
this.optionsMgr = optionsMgr; this.optionsService = optionsService;
} }
prepareModel() { prepareModel() {
this.data = this.componentSchema.info; this.data = this.componentSchema.info;
this.specUrl = this.optionsMgr.options.specUrl; this.specUrl = this.optionsService.options.specUrl;
} }
} }

View File

@ -15,9 +15,9 @@ import { TestComponentBuilder } from '@angular/compiler/testing';
import ApiInfo from 'lib/components/ApiInfo/api-info'; import ApiInfo from 'lib/components/ApiInfo/api-info';
import SchemaManager from 'lib/utils/SchemaManager'; 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('Redoc components', () => {
describe('ApiInfo Component', () => { describe('ApiInfo Component', () => {
@ -26,7 +26,7 @@ describe('Redoc components', () => {
let fixture; let fixture;
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}), provide(SchemaManager, {useValue: new SchemaManager()}),
provide(OptionsManager, {useValue: optsMgr}) provide(OptionsService, {useValue: optionsService})
]); ]);
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {

View File

@ -1,11 +1,11 @@
'use strict'; 'use strict';
import {Component, ElementRef, ViewContainerRef} from '@angular/core'; import { Component, ElementRef, ViewContainerRef } from '@angular/core';
import {CORE_DIRECTIVES} from '@angular/common'; import { CORE_DIRECTIVES } from '@angular/common';
import {DynamicComponentLoader} from '@angular/core'; import { DynamicComponentLoader } from '@angular/core';
import {JsonSchema} from './json-schema'; import { JsonSchema } from './json-schema';
import OptionsManager from '../../options'; import { OptionsService } from '../../services/index';
import SchemaManager from '../../utils/SchemaManager'; import SchemaManager from '../../utils/SchemaManager';
@ -18,14 +18,15 @@ var cache = {};
template: '', template: '',
directives: [CORE_DIRECTIVES] directives: [CORE_DIRECTIVES]
}) })
@Reflect.metadata('parameters', [[SchemaManager], [ViewContainerRef], [ElementRef], [DynamicComponentLoader], [OptionsManager]]) @Reflect.metadata('parameters', [[SchemaManager], [ViewContainerRef], [
ElementRef], [DynamicComponentLoader], [OptionsService]])
export class JsonSchemaLazy { export class JsonSchemaLazy {
constructor(schemaMgr, viewRef, elementRef, dcl, optionsMgr) { constructor(schemaMgr, viewRef, elementRef, dcl, optionsService) {
this.viewRef = viewRef; this.viewRef = viewRef;
this.elementRef = elementRef; this.elementRef = elementRef;
this.dcl = dcl; this.dcl = dcl;
this.optionsMgr = optionsMgr; this.optionsService = optionsService;
this.schemaMgr = schemaMgr; this.schemaMgr = schemaMgr;
} }
@ -35,7 +36,7 @@ export class JsonSchemaLazy {
} }
load() { load() {
if (this.optionsMgr.options.disableLazySchemas) return; if (this.optionsService.options.disableLazySchemas) return;
if (this.loaded) return; if (this.loaded) return;
if (this.pointer) { if (this.pointer) {
this.dcl.loadNextToLocation(JsonSchema, this.viewRef).then((compRef) => { this.dcl.loadNextToLocation(JsonSchema, this.viewRef).then((compRef) => {

View File

@ -1,9 +1,9 @@
'use strict'; 'use strict';
import { getChildDebugElement } from 'tests/helpers'; import { getChildDebugElement } from 'tests/helpers';
import {Component, provide} from '@angular/core'; import { Component, provide } from '@angular/core';
import {DynamicComponentLoader} from '@angular/core'; import { DynamicComponentLoader } from '@angular/core';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter'; import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter';
import { import {
inject, inject,
@ -17,7 +17,7 @@ import { TestComponentBuilder } from '@angular/compiler/testing';
import JsonSchemaLazy from 'lib/components/JsonSchema/json-schema-lazy'; import JsonSchemaLazy from 'lib/components/JsonSchema/json-schema-lazy';
import SchemaManager from 'lib/utils/SchemaManager'; import SchemaManager from 'lib/utils/SchemaManager';
import OptionsManager from 'lib/options'; import { OptionsService } from 'lib/services/index';
describe('Redoc components', () => { describe('Redoc components', () => {
describe('JsonSchemaLazy Component', () => { describe('JsonSchemaLazy Component', () => {
@ -33,7 +33,7 @@ describe('Redoc components', () => {
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: schemaMgr}), provide(SchemaManager, {useValue: schemaMgr}),
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}), provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
provide(OptionsManager, {useClass: OptionsManager}) provide(OptionsService, {useClass: OptionsService})
]); ]);
beforeEach(inject([TestComponentBuilder, DynamicComponentLoader], (tcb, dcl) => { beforeEach(inject([TestComponentBuilder, DynamicComponentLoader], (tcb, dcl) => {
builder = tcb; builder = tcb;

View File

@ -1,19 +1,19 @@
'use strict'; 'use strict';
import { getChildDebugElement } from 'tests/helpers'; import { Component, provide } from '@angular/core';
import {Component, provide} from '@angular/core';
import OptionsManager from 'lib/options';
import { import {
inject, inject,
beforeEach, beforeEach,
beforeEachProviders, beforeEachProviders,
it it
} from '@angular/core/testing'; } from '@angular/core/testing';
import { TestComponentBuilder } from '@angular/compiler/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'; import SchemaManager from 'lib/utils/SchemaManager';
describe('Redoc components', () => { describe('Redoc components', () => {
@ -24,7 +24,7 @@ describe('Redoc components', () => {
let fixture; let fixture;
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: schemaMgr}), provide(SchemaManager, {useValue: schemaMgr}),
provide(OptionsManager, {useClass: OptionsManager}) provide(OptionsService, {useClass: OptionsService})
]); ]);
beforeEach(inject([TestComponentBuilder], (tcb) => { beforeEach(inject([TestComponentBuilder], (tcb) => {
builder = tcb; builder = tcb;

View File

@ -1,9 +1,7 @@
'use strict'; 'use strict';
import { getChildDebugElement } from 'tests/helpers'; import { Component, provide } from '@angular/core';
import {Component, provide} from '@angular/core'; import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import { import {
inject, inject,
async, async,
@ -11,12 +9,13 @@ import {
beforeEachProviders, beforeEachProviders,
it it
} from '@angular/core/testing'; } from '@angular/core/testing';
import { TestComponentBuilder } from '@angular/compiler/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 SchemaManager from 'lib/utils/SchemaManager';
import OptionsManager from 'lib/options'; import OptionsService from 'lib/services/index';
describe('Redoc components', () => { describe('Redoc components', () => {
describe('Method Component', () => { describe('Method Component', () => {
@ -25,7 +24,7 @@ describe('Redoc components', () => {
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}), provide(SchemaManager, {useValue: new SchemaManager()}),
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}), provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
provide(OptionsManager, {useClass: OptionsManager}) provide(OptionsService, {useClass: OptionsService})
]); ]);
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;

View File

@ -2,7 +2,7 @@
import { getChildDebugElement } from 'tests/helpers'; import { getChildDebugElement } from 'tests/helpers';
import {Component, provide} from '@angular/core'; 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 {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import { import {
@ -25,7 +25,7 @@ describe('Redoc components', () => {
let fixture; let fixture;
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}), provide(SchemaManager, {useValue: new SchemaManager()}),
provide(OptionsManager, {useClass: OptionsManager}), provide(OptionsService, {useClass: OptionsService}),
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}) provide(BrowserDomAdapter, {useClass: BrowserDomAdapter})
]); ]);
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {

View File

@ -1,15 +1,10 @@
'use strict'; 'use strict';
import {provide, enableProdMode} from '@angular/core'; import { provide, enableProdMode, ElementRef} from '@angular/core';
import {ElementRef} from '@angular/core'; import { bootstrap } from '@angular/platform-browser-dynamic';
import {bootstrap} from '@angular/platform-browser-dynamic';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter'; import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import detectScollParent from 'scrollparent'; import { RedocComponent, BaseComponent } from '../base';
import {RedocComponent, BaseComponent} from '../base';
import SchemaManager from '../../utils/SchemaManager';
import { import {
ApiInfo, ApiInfo,
ApiLogo, ApiLogo,
@ -17,10 +12,10 @@ import {
SideMenu SideMenu
} from '../index'; } from '../index';
import { StickySidebar } from '../../shared/components/index'; import { StickySidebar } from '../../shared/components/index';
import SchemaManager from '../../utils/SchemaManager';
import { OptionsService, RedocEventsService } from '../../services/index';
import OptionsManager from '../../options'; import detectScollParent from 'scrollparent';
import { RedocEventsService } from '../../services/index';
import './redoc-loading-styles.css!css'; import './redoc-loading-styles.css!css';
var dom = new BrowserDomAdapter(); var dom = new BrowserDomAdapter();
@ -38,7 +33,7 @@ var _modeLocked = false;
directives: [ApiInfo, ApiLogo, MethodsList, SideMenu, StickySidebar] directives: [ApiInfo, ApiLogo, MethodsList, SideMenu, StickySidebar]
}) })
@Reflect.metadata('parameters', [ @Reflect.metadata('parameters', [
[SchemaManager], [OptionsManager], [ElementRef], [RedocEventsService]]) [SchemaManager], [OptionsService], [ElementRef], [RedocEventsService]])
export class Redoc extends BaseComponent { export class Redoc extends BaseComponent {
constructor(schemaMgr, optionsMgr, elementRef, events) { constructor(schemaMgr, optionsMgr, elementRef, events) {
super(schemaMgr); super(schemaMgr);
@ -71,11 +66,11 @@ export class Redoc extends BaseComponent {
} }
static init(specUrl, options) { static init(specUrl, options) {
var optionsMgr = new OptionsManager(); var optionsService = new OptionsService(dom);
optionsMgr.options = options; optionsService.options = options;
optionsMgr.options.specUrl = optionsMgr.options.specUrl || specUrl; optionsService.options.specUrl = optionsService.options.specUrl || specUrl;
var providers = [ var providers = [
provide(OptionsManager, {useValue: optionsMgr}) provide(OptionsService, {useValue: optionsService})
]; ];
if (Redoc.appRef) { if (Redoc.appRef) {
@ -84,7 +79,7 @@ export class Redoc extends BaseComponent {
Redoc.showLoadingAnimation(); Redoc.showLoadingAnimation();
return SchemaManager.instance().load(specUrl) return SchemaManager.instance().load(specUrl)
.then(() => { .then(() => {
if (!_modeLocked && !optionsMgr.options.debugMode) { if (!_modeLocked && !optionsService.options.debugMode) {
enableProdMode(); enableProdMode();
_modeLocked = true; _modeLocked = true;
} }

View File

@ -16,9 +16,9 @@ import { TestComponentBuilder } from '@angular/compiler/testing';
import Redoc from 'lib/components/Redoc/redoc'; import Redoc from 'lib/components/Redoc/redoc';
import SchemaManager from 'lib/utils/SchemaManager'; 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 components', () => {
describe('Redoc Component', () => { describe('Redoc Component', () => {
@ -26,7 +26,7 @@ describe('Redoc components', () => {
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}), provide(SchemaManager, {useValue: new SchemaManager()}),
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}), provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
provide(OptionsManager, {useValue: optsMgr}) provide(OptionsService, {useValue: optsMgr})
]); ]);
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;
@ -152,7 +152,7 @@ describe('Redoc components', () => {
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}), provide(SchemaManager, {useValue: new SchemaManager()}),
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}), provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
provide(OptionsManager, {useValue: optsMgr}) provide(OptionsService, {useValue: optsMgr})
]); ]);
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;

View File

@ -5,7 +5,7 @@ import JsonPointer from '../../utils/JsonPointer';
import { JsonSchema, JsonSchemaLazy } from '../index'; import { JsonSchema, JsonSchemaLazy } from '../index';
import {Zippy} from '../../shared/components/index'; import {Zippy} from '../../shared/components/index';
import {statusCodeType} from '../../utils/helpers'; import {statusCodeType} from '../../utils/helpers';
import OptionsManager from '../../options'; import { OptionsService } from '../../services/index';
function isNumeric(n) { function isNumeric(n) {
return (!isNaN(parseFloat(n)) && isFinite(n)); return (!isNaN(parseFloat(n)) && isFinite(n));
@ -17,7 +17,7 @@ function isNumeric(n) {
styleUrls: ['./lib/components/ResponsesList/responses-list.css'], styleUrls: ['./lib/components/ResponsesList/responses-list.css'],
directives: [JsonSchema, Zippy, JsonSchemaLazy] directives: [JsonSchema, Zippy, JsonSchemaLazy]
}) })
@Reflect.metadata('parameters', [[SchemaManager], [OptionsManager]]) @Reflect.metadata('parameters', [[SchemaManager], [OptionsService]])
export class ResponsesList extends BaseComponent { export class ResponsesList extends BaseComponent {
constructor(schemaMgr, optionsMgr) { constructor(schemaMgr, optionsMgr) {
super(schemaMgr); super(schemaMgr);

View File

@ -6,7 +6,7 @@ import { global } from '@angular/core/src/facade/lang';
import { RedocComponent, BaseComponent, SchemaManager } from '../base'; import { RedocComponent, BaseComponent, SchemaManager } from '../base';
import { RedocEventsService } from '../../services/index'; import { RedocEventsService } from '../../services/index';
import OptionsManager from '../../options'; import { OptionsService } from '../../services/index';
const CHANGE = { const CHANGE = {
NEXT : 1, NEXT : 1,
@ -26,7 +26,7 @@ const INVIEW_POSITION = {
styleUrls: ['./lib/components/SideMenu/side-menu.css'] styleUrls: ['./lib/components/SideMenu/side-menu.css']
}) })
@Reflect.metadata('parameters', [[SchemaManager], [ElementRef], @Reflect.metadata('parameters', [[SchemaManager], [ElementRef],
[BrowserDomAdapter], [OptionsManager], [RedocEventsService]]) [BrowserDomAdapter], [OptionsService], [RedocEventsService]])
export class SideMenu extends BaseComponent { export class SideMenu extends BaseComponent {
constructor(schemaMgr, elementRef, dom, optionsMgr, events) { constructor(schemaMgr, elementRef, dom, optionsMgr, events) {
super(schemaMgr); super(schemaMgr);

View File

@ -3,7 +3,7 @@
import { getChildDebugElement, mouseclick} from 'tests/helpers'; import { getChildDebugElement, mouseclick} from 'tests/helpers';
import {Component, provide, ViewMetadata} from '@angular/core'; import {Component, provide, ViewMetadata} from '@angular/core';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter'; import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import OptionsManager from 'lib/options'; import { OptionsService } from 'lib/services/index';
import { import {
inject, inject,
@ -20,7 +20,7 @@ import MethodsList from 'lib/components/MethodsList/methods-list';
import SideMenu from 'lib/components/SideMenu/side-menu'; import SideMenu from 'lib/components/SideMenu/side-menu';
import SchemaManager from 'lib/utils/SchemaManager'; import SchemaManager from 'lib/utils/SchemaManager';
let testOptions = new OptionsManager(); let testOptions = new OptionsService();
testOptions.options = { testOptions.options = {
scrollYOffset: () => 0, scrollYOffset: () => 0,
scrollParent: window scrollParent: window
@ -34,7 +34,7 @@ describe('Redoc components', () => {
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}), provide(SchemaManager, {useValue: new SchemaManager()}),
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}), provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
provide(OptionsManager, {useValue: testOptions}) provide(OptionsService, {useValue: testOptions})
]); ]);
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;

View File

@ -1,3 +1,4 @@
'use strict'; 'use strict';
export * from './events.service.js'; export * from './events.service.js';
export * from './options.service.js';

View File

@ -1,22 +1,23 @@
'use strict'; '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';
import {isFunction, isString} from '@angular/core/src/facade/lang'; const defaults = {
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import {global} from '@angular/core/src/facade/lang';
var defaults = {
scrollYOffset: 0, scrollYOffset: 0,
disableLazySchemas: false, 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]]) @Reflect.metadata('parameters', [[BrowserDomAdapter]])
export default class OptionsManager { export class OptionsService {
constructor() { constructor(dom) {
this._options = defaults; this._options = defaults;
this.dom = new BrowserDomAdapter(); this.dom = dom;
} }
get options() { get options() {

View File

@ -69,9 +69,6 @@
"map": { "map": {
"http": "npm:stream-http@2.3.0" "http": "npm:stream-http@2.3.0"
} }
},
"npm:@angular/core@2.0.0-rc.1": {
"format": "esm"
} }
} }
}, },

View File

@ -33,9 +33,6 @@ System.config({
}, },
"jspm_packages/npm/json-schema-view-js@0.2.0/src/*": { "jspm_packages/npm/json-schema-view-js@0.2.0/src/*": {
"format": "esm" "format": "esm"
},
"npm:@angular/**/*": {
"format": "esm"
} }
}, },
@ -149,6 +146,7 @@ System.config({
"process": "github:jspm/nodelibs-process@0.1.2" "process": "github:jspm/nodelibs-process@0.1.2"
}, },
"npm:@angular/core@2.0.0-rc.1": { "npm:@angular/core@2.0.0-rc.1": {
"process": "github:jspm/nodelibs-process@0.1.2",
"rxjs": "npm:rxjs@5.0.0-beta.6", "rxjs": "npm:rxjs@5.0.0-beta.6",
"zone.js": "npm:zone.js@0.6.12" "zone.js": "npm:zone.js@0.6.12"
}, },