From 379870a1b3dbb028c17d879618c060afe41c6bc2 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 22 Aug 2016 12:12:13 +0300 Subject: [PATCH] Migrate to angular rc.5 --- build/tasks/build.js | 2 +- karma.conf.js | 2 + lib/components/ApiInfo/api-info.ts | 9 +- lib/components/ApiLogo/api-logo.ts | 9 +- .../JsonSchema/json-schema-lazy.spec.ts | 14 +- lib/components/JsonSchema/json-schema-lazy.ts | 51 ++-- lib/components/JsonSchema/json-schema.html | 2 +- lib/components/JsonSchema/json-schema.spec.ts | 2 +- lib/components/JsonSchema/json-schema.ts | 23 +- lib/components/Method/method.ts | 21 +- lib/components/MethodsList/methods-list.ts | 17 +- lib/components/ParamsList/params-list.ts | 11 +- lib/components/Redoc/redoc.spec.ts | 237 +++++++++--------- lib/components/Redoc/redoc.ts | 97 +------ .../RequestSamples/request-samples.ts | 30 +-- .../ResponsesList/responses-list.ts | 15 +- .../ResponsesSamples/responses-samples.ts | 12 +- lib/components/SchemaSample/schema-sample.ts | 16 +- lib/components/SideMenu/side-menu.html | 2 +- lib/components/SideMenu/side-menu.spec.ts | 2 +- lib/components/SideMenu/side-menu.ts | 8 +- lib/components/Warnings/warnings.ts | 8 +- lib/components/base.ts | 58 +---- lib/components/index.ts | 35 ++- lib/index.js | 58 ++++- lib/redoc.module.ts | 31 +++ lib/shared/components/DropDown/drop-down.ts | 2 - lib/shared/components/Tabs/tabs.ts | 3 - lib/shared/components/Zippy/zippy.spec.ts | 1 - lib/shared/components/Zippy/zippy.ts | 5 +- lib/shared/components/index.ts | 16 +- lib/utils/SpecManager.ts | 2 +- lib/utils/pipes.ts | 4 + package.json | 25 +- system.config.js | 51 ++-- tests/setup.ts | 48 ++-- 36 files changed, 430 insertions(+), 499 deletions(-) create mode 100644 lib/redoc.module.ts diff --git a/build/tasks/build.js b/build/tasks/build.js index ec122a9e..5581575d 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -115,7 +115,7 @@ gulp.task('bundle', ['injectVersionFile'], function bundle(done) { builder .buildStatic(path.join(paths.tmp, paths.sourceEntryPoint), outputFileName, - { format:'umd', sourceMaps: !argv.prod, lowResSourceMaps: true, minify: argv.prod } + { format:'umd', sourceMaps: !argv.prod, lowResSourceMaps: true, minify: argv.prod, globalName: 'Redoc' } ) .then(() => { // wait some time to allow flush diff --git a/karma.conf.js b/karma.conf.js index e7c94a7a..b0900e8d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -40,6 +40,8 @@ module.exports = function (config) { files: [ 'node_modules/zone.js/dist/zone.js', 'node_modules/zone.js/dist/async-test.js', + 'node_modules/zone.js/dist/sync-test.js', + 'node_modules/zone.js/dist/proxy-zone.js', 'node_modules/zone.js/dist/jasmine-patch.js', 'node_modules/zone.js/dist/long-stack-trace-zone.js', 'node_modules/babel-polyfill/dist/polyfill.js', diff --git a/lib/components/ApiInfo/api-info.ts b/lib/components/ApiInfo/api-info.ts index 395e82ed..c63b5a10 100644 --- a/lib/components/ApiInfo/api-info.ts +++ b/lib/components/ApiInfo/api-info.ts @@ -1,12 +1,13 @@ 'use strict'; - -import { SpecManager, RedocComponent, BaseComponent } from '../base'; +import { Component, ChangeDetectionStrategy } from '@angular/core'; +import { SpecManager, BaseComponent } from '../base'; import { OptionsService, MenuService } from '../../services/index'; -@RedocComponent({ +@Component({ selector: 'api-info', styleUrls: ['./api-info.css'], - templateUrl: './api-info.html' + templateUrl: './api-info.html', + changeDetection: ChangeDetectionStrategy.OnPush }) export class ApiInfo extends BaseComponent { info: any; diff --git a/lib/components/ApiLogo/api-logo.ts b/lib/components/ApiLogo/api-logo.ts index 4127fbe6..5bf0dec3 100644 --- a/lib/components/ApiLogo/api-logo.ts +++ b/lib/components/ApiLogo/api-logo.ts @@ -1,11 +1,12 @@ 'use strict'; +import { Component, ChangeDetectionStrategy } from '@angular/core'; +import { BaseComponent, SpecManager } from '../base'; -import {RedocComponent, BaseComponent, SpecManager} from '../base'; - -@RedocComponent({ +@Component({ selector: 'api-logo', styleUrls: ['./api-logo.css'], - templateUrl: './api-logo.html' + templateUrl: './api-logo.html', + changeDetection: ChangeDetectionStrategy.OnPush }) export class ApiLogo extends BaseComponent { logo:any = {}; diff --git a/lib/components/JsonSchema/json-schema-lazy.spec.ts b/lib/components/JsonSchema/json-schema-lazy.spec.ts index 736823f5..f5052ba3 100644 --- a/lib/components/JsonSchema/json-schema-lazy.spec.ts +++ b/lib/components/JsonSchema/json-schema-lazy.spec.ts @@ -23,15 +23,11 @@ describe('Redoc components', () => { fixture = builder.createSync(TestAppComponent); let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema-lazy'); component = debugEl.componentInstance; - spyOn(component, '_loadAfterSelf').and.callThrough(); - spyOn(component.resolver, 'resolveComponent').and.returnValue({ then: () => { - return { catch: () => {/**/} }; - }}); + spyOn(component, '_loadAfterSelf').and.stub(); }); afterEach(() => { component._loadAfterSelf.and.callThrough(); - component.resolver.resolveComponent.and.callThrough(); }); it('should init component', () => { @@ -44,14 +40,6 @@ describe('Redoc components', () => { component.load(); expect(component._loadAfterSelf).toHaveBeenCalled(); }); - - it('should not run loadNextToLocation if already loaded', () => { - component.pointer = '#/def'; - fixture.detectChanges(); - component.load(); - component.load(); - expect(component._loadAfterSelf.calls.count()).toEqual(1); - }); }); }); diff --git a/lib/components/JsonSchema/json-schema-lazy.ts b/lib/components/JsonSchema/json-schema-lazy.ts index 0dbc137a..edbea22f 100644 --- a/lib/components/JsonSchema/json-schema-lazy.ts +++ b/lib/components/JsonSchema/json-schema-lazy.ts @@ -1,8 +1,7 @@ 'use strict'; import { Component, ElementRef, ViewContainerRef, OnDestroy, Input, - AfterViewInit, ComponentResolver, Renderer } from '@angular/core'; -import { CORE_DIRECTIVES } from '@angular/common'; + AfterViewInit, ComponentFactoryResolver, Renderer } from '@angular/core'; import { JsonSchema } from './json-schema'; import { OptionsService } from '../../services/options.service'; @@ -12,8 +11,8 @@ var cache = {}; @Component({ selector: 'json-schema-lazy', - template: '', - directives: [CORE_DIRECTIVES] + entryComponents: [ JsonSchema ], + template: '' }) export class JsonSchemaLazy implements OnDestroy, AfterViewInit { @Input() pointer: string; @@ -26,7 +25,7 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit { disableLazy: boolean = false; loaded: boolean = false; constructor(private specMgr:SpecManager, private location:ViewContainerRef, private elementRef:ElementRef, - private resolver:ComponentResolver, private optionsService:OptionsService, private _renderer: Renderer) { + private resolver:ComponentFactoryResolver, private optionsService:OptionsService, private _renderer: Renderer) { this.disableLazy = this.optionsService.options.disableLazySchemas; } @@ -36,19 +35,14 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit { } _loadAfterSelf() { + var componentFactory = this.resolver.resolveComponentFactory(JsonSchema); + let contextInjector = this.location.parentInjector; + let compRef = this.location.createComponent(componentFactory, null, contextInjector, null); + this.initComponent(compRef.instance); + this._renderer.setElementAttribute(compRef.location.nativeElement, 'class', this.location.element.nativeElement.className); + compRef.changeDetectorRef.detectChanges(); this.loaded = true; - return this.resolver.resolveComponent(JsonSchema).then(componentFactory => { - let contextInjector = this.location.parentInjector; - let compRef = this.location.createComponent( - componentFactory, null, contextInjector, null); - this.initComponent(compRef.instance); - this._renderer.setElementAttribute(compRef.location.nativeElement, 'class', this.location.element.nativeElement.className); - compRef.changeDetectorRef.detectChanges(); - return compRef; - }).catch(err => { - console.log(err); - throw err; - }); + return compRef; } load() { @@ -63,19 +57,18 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit { loadCached() { this.pointer = this.normalizePointer(); if (cache[this.pointer]) { - cache[this.pointer].then((compRef) => { - setTimeout( ()=> { - let $element = compRef.location.nativeElement; + let compRef = cache[this.pointer]; + setTimeout( ()=> { + let $element = compRef.location.nativeElement; - // skip caching view with tabs inside (discriminator) - // as it needs attached controller - if (!this.disableLazy && (compRef.instance.hasDescendants || compRef.instance._hasSubSchemas)) { - this._loadAfterSelf(); - return; - } - insertAfter($element.cloneNode(true), this.elementRef.nativeElement); - this.loaded = true; - }); + // skip caching view with descendant schemas + // as it needs attached controller + if (!this.disableLazy && (compRef.instance.hasDescendants || compRef.instance._hasSubSchemas)) { + this._loadAfterSelf(); + return; + } + insertAfter($element.cloneNode(true), this.elementRef.nativeElement); + this.loaded = true; }); } else { cache[this.pointer] = this._loadAfterSelf(); diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index dabb35da..3931b05e 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -39,7 +39,7 @@