Upgrade to Angular 2.0.0-beta.3 + refactoring

This commit is contained in:
Roman Hotsiy 2016-02-11 13:38:44 +02:00
parent 9744cddb16
commit a7913dec59
18 changed files with 82 additions and 73 deletions

View File

@ -17,7 +17,7 @@
<redoc scroll-y-offset="body > nav" spec-url='swagger.yml'></redoc>
<!-- ReDoc built file with all dependencies included -->
<script src="dist/redoc.js"> </script>
<script src="main.js"> </script>
<script src="dist/redoc.js"> </script>
</body>
</html>

View File

@ -8,4 +8,6 @@
Redoc.init(schemaUrlInput.value);
return false;
})
//window.redocDebugMode = true;
})();

View File

@ -49,12 +49,12 @@ module.exports = function (config) {
'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/babel-polyfill/dist/polyfill.js',
'node_modules/reflect-metadata/Reflect.js'
'./node_modules/reflect-metadata/Reflect.js'
],
jspm: {
config: 'system.config.js',
loadFiles: ['tests/unit/*.spec.js', 'tests/helpers.js', 'lib/**/*.js'],
loadFiles: ['tests/setup.js', 'tests/helpers.js', 'tests/unit/*.spec.js', 'lib/**/*.js'],
serveFiles: ['tests/schemas/**/*.json','tests/schemas/**/*.yml', 'lib/**/*.html', '.tmp/lib/**/*.css'],
nocache: true
},

View File

@ -56,7 +56,6 @@ describe('Redoc components', () => {
@Component({selector: 'test-app'})
@View({
directives: [ApiInfo],
providers: [SchemaManager],
template:
`<api-info></api-info>`
})

View File

@ -7,7 +7,7 @@ import {RedocComponent, BaseComponent} from '../base';
styleUrls: ['./lib/components/ApiLogo/api-logo.css'],
templateUrl: './lib/components/ApiLogo/api-logo.html'
})
export default class ApiInfo extends BaseComponent {
export default class ApiLogo extends BaseComponent {
constructor(schemaMgr) {
super(schemaMgr);
}

View File

@ -30,7 +30,6 @@ describe('Redoc components', () => {
beforeEachProviders(() => [
provide(SchemaManager, {useValue: schemaMgr}),
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
provide('OPTION_NAMES', {useValue: []}),
provide(OptionsManager, {useClass: OptionsManager})
]);
beforeEach(inject([TestComponentBuilder, DynamicComponentLoader], (tcb, dcl) => {
@ -84,7 +83,6 @@ describe('Redoc components', () => {
@Component({selector: 'test-app'})
@View({
directives: [JsonSchemaLazy],
providers: [SchemaManager, DynamicComponentLoader],
template:
`<json-schema-lazy></json-schema-lazy>`
})

View File

@ -23,7 +23,6 @@ describe('Redoc components', () => {
let fixture;
beforeEachProviders(() => [
provide(SchemaManager, {useValue: schemaMgr}),
provide('OPTION_NAMES', {useValue: []}),
provide(OptionsManager, {useClass: OptionsManager})
]);
beforeEach(inject([TestComponentBuilder], (tcb) => {

View File

@ -23,7 +23,6 @@ describe('Redoc components', () => {
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}),
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
provide('OPTION_NAMES', {useValue: []}),
provide(OptionsManager, {useClass: OptionsManager})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {

View File

@ -1,10 +1,9 @@
'use strict';
import {ChangeDetectionStrategy, provide} from 'angular2/core';
import {ChangeDetectionStrategy, provide, enableProdMode} from 'angular2/core';
import {ElementRef} from 'angular2/core';
import {BrowserDomAdapter, bootstrap} from 'angular2/platform/browser';
import detectScollParent from 'scrollparent';
import {RedocComponent, BaseComponent} from '../base';
import SchemaManager from '../../utils/SchemaManager';
@ -18,15 +17,14 @@ import {redocEvents} from '../../events';
import './redoc-loading-styles.css!css';
let dom = new BrowserDomAdapter();
var dom = new BrowserDomAdapter();
var _modeLocked = false;
@RedocComponent({
selector: 'redoc',
providers: [
SchemaManager,
BrowserDomAdapter,
provide('OPTION_NAMES', {useValue: new Set(['scrollYOffset', 'disableLazySchemas'])}),
provide(OptionsManager, {useClass: OptionsManager})
BrowserDomAdapter
],
templateUrl: './lib/components/Redoc/redoc.html',
styleUrls: ['./lib/components/Redoc/redoc.css'],
@ -60,14 +58,23 @@ export default class Redoc extends BaseComponent {
}
static init(schemaUrl, options) {
var optionsMgr = new OptionsManager();
optionsMgr.options = options;
var providers = [
provide(OptionsManager, {useValue: optionsMgr})
];
if (Redoc.appRef) {
Redoc.dispose();
}
Redoc.showLoadingAnimation();
return SchemaManager.instance().load(schemaUrl)
.then(() => {
(new OptionsManager()).options = options;
return bootstrap(Redoc);
if (!_modeLocked && !optionsMgr.options.debugMode) {
enableProdMode();
_modeLocked = true;
}
return bootstrap(Redoc, providers);
})
.then(
(appRef) => {

View File

@ -32,12 +32,10 @@ const INVIEW_POSITION = {
export default class SideMenu extends BaseComponent {
constructor(schemaMgr, elementRef, dom, zone, optionsMgr) {
super(schemaMgr);
this.$element = elementRef.nativeElement;
this.dom = dom;
this.options = optionsMgr.options;
this.$scrollParent = this.options.$scrollParent;
this.$mobileNav = dom.querySelector(elementRef.nativeElement, '.mobile-nav');
this.$resourcesNav = dom.querySelector(elementRef.nativeElement, '#resources-nav');
// for some reason constructor is not run inside zone
// as workaround running it manually
zone.run(() => {
@ -251,6 +249,8 @@ export default class SideMenu extends BaseComponent {
}
init() {
this.$mobileNav = this.dom.querySelector(this.$element, '.mobile-nav');
this.$resourcesNav = this.dom.querySelector(this.$element, '#resources-nav');
this.changeActive(CHANGE.INITIAL);
}
}

View File

@ -32,7 +32,6 @@ describe('Redoc components', () => {
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}),
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
provide('OPTION_NAMES', {useValue: []}),
provide(OptionsManager, {useValue: testOptions})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {

View File

@ -1,10 +1,7 @@
'use strict';
import {Redoc} from './components/index';
import {enableProdMode} from 'angular2/core';
export var init = Redoc.init;
window.Redoc = Redoc;
enableProdMode();
Redoc.autoInit();

View File

@ -1,20 +1,22 @@
'use strict';
import {Inject} from 'angular2/core';
import {isFunction, isString} from 'angular2/src/facade/lang';
import {BrowserDomAdapter} from 'angular2/platform/browser';
import {global} from 'angular2/src/facade/lang';
var defaults = {
scrollYOffset: 0,
disableLazySchemas: false
disableLazySchemas: false,
debugMode: global.redocDebugMode
};
@Reflect.metadata('parameters', [[new Inject('OPTION_NAMES')], [BrowserDomAdapter]])
var OPTION_NAMES = new Set(['scrollYOffset', 'disableLazySchemas']);
@Reflect.metadata('parameters', [[BrowserDomAdapter]])
export default class OptionsManager {
constructor(optionNames, dom) {
constructor() {
this._options = defaults;
this.optionNames = optionNames;
this.dom = dom;
this.dom = new BrowserDomAdapter();
}
get options() {
@ -36,7 +38,7 @@ export default class OptionsManager {
name: k.replace(/-(.)/g, (m, $1) => $1.toUpperCase())
})
)
.filter(option => this.optionNames.has(option.name))
.filter(option => OPTION_NAMES.has(option.name))
.forEach(option => {
parsedOpts[option.name] = attributesMap.get(option.attrName);
});

View File

@ -4,7 +4,6 @@ import {Pipe} from 'angular2/core';
import {isString, stringify, isBlank} from 'angular2/src/facade/lang';
import {BaseException} from 'angular2/src/facade/exceptions';
import {JsonPointer} from './JsonPointer';
import marked from 'marked';
import Prism from 'prismjs';
import 'prismjs/components/prism-actionscript.js';
@ -30,6 +29,8 @@ import 'prismjs/components/prism-vim.js';
import 'prismjs/themes/prism-dark.css!css';
import marked from 'marked';
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,

View File

@ -29,7 +29,7 @@
"jspm": {
"configFile": "system.config.js",
"dependencies": {
"angular2": "npm:angular2@^2.0.0-beta.0",
"angular2": "npm:angular2@2.0.0-beta.3",
"es6-shim": "github:es-shims/es6-shim@^0.33.6",
"json-formatter-js": "npm:json-formatter-js@^0.2.0",
"json-pointer": "npm:json-pointer@^0.3.0",

View File

@ -37,7 +37,7 @@ System.config({
},
map: {
"angular2": "npm:angular2@2.0.0-beta.0",
"angular2": "npm:angular2@2.0.0-beta.3",
"babel": "npm:babel-core@5.8.34",
"babel-runtime": "npm:babel-runtime@5.8.34",
"clean-css": "npm:clean-css@3.4.6",
@ -135,14 +135,14 @@ System.config({
"path": "github:jspm/nodelibs-path@0.1.0",
"process": "github:jspm/nodelibs-process@0.1.2"
},
"npm:angular2@2.0.0-beta.0": {
"npm:angular2@2.0.0-beta.3": {
"crypto": "github:jspm/nodelibs-crypto@0.1.0",
"es6-promise": "npm:es6-promise@3.0.2",
"es6-shim": "npm:es6-shim@0.33.13",
"process": "github:jspm/nodelibs-process@0.1.2",
"reflect-metadata": "npm:reflect-metadata@0.1.2",
"rxjs": "npm:rxjs@5.0.0-beta.0",
"zone.js": "npm:zone.js@0.5.10"
"zone.js": "npm:zone.js@0.5.11"
},
"npm:argparse@1.0.3": {
"assert": "github:jspm/nodelibs-assert@0.1.0",
@ -153,9 +153,9 @@ System.config({
"sprintf-js": "npm:sprintf-js@1.0.3",
"util": "github:jspm/nodelibs-util@0.1.0"
},
"npm:asn1.js@4.3.0": {
"npm:asn1.js@4.4.0": {
"assert": "github:jspm/nodelibs-assert@0.1.0",
"bn.js": "npm:bn.js@4.6.4",
"bn.js": "npm:bn.js@4.10.3",
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"inherits": "npm:inherits@2.0.1",
"minimalistic-assert": "npm:minimalistic-assert@1.0.0",
@ -199,11 +199,14 @@ System.config({
"readable-stream": "npm:readable-stream@2.0.5",
"util": "github:jspm/nodelibs-util@0.1.0"
},
"npm:bn.js@4.10.3": {
"buffer": "github:jspm/nodelibs-buffer@0.1.0"
},
"npm:boom@2.10.1": {
"hoek": "npm:hoek@2.16.3",
"http": "github:jspm/nodelibs-http@1.7.1"
},
"npm:browserify-aes@1.0.5": {
"npm:browserify-aes@1.0.6": {
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"buffer-xor": "npm:buffer-xor@1.0.3",
"cipher-base": "npm:cipher-base@1.0.2",
@ -215,7 +218,7 @@ System.config({
"systemjs-json": "github:systemjs/plugin-json@0.1.0"
},
"npm:browserify-cipher@1.0.0": {
"browserify-aes": "npm:browserify-aes@1.0.5",
"browserify-aes": "npm:browserify-aes@1.0.6",
"browserify-des": "npm:browserify-des@1.0.0",
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"crypto": "github:jspm/nodelibs-crypto@0.1.0",
@ -229,20 +232,20 @@ System.config({
"inherits": "npm:inherits@2.0.1"
},
"npm:browserify-rsa@4.0.0": {
"bn.js": "npm:bn.js@4.6.4",
"bn.js": "npm:bn.js@4.10.3",
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"constants": "github:jspm/nodelibs-constants@0.1.0",
"crypto": "github:jspm/nodelibs-crypto@0.1.0",
"randombytes": "npm:randombytes@2.0.2"
},
"npm:browserify-sign@4.0.0": {
"bn.js": "npm:bn.js@4.6.4",
"bn.js": "npm:bn.js@4.10.3",
"browserify-rsa": "npm:browserify-rsa@4.0.0",
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"create-hash": "npm:create-hash@1.1.2",
"create-hmac": "npm:create-hmac@1.1.4",
"crypto": "github:jspm/nodelibs-crypto@0.1.0",
"elliptic": "npm:elliptic@6.0.2",
"elliptic": "npm:elliptic@6.2.3",
"inherits": "npm:inherits@2.0.1",
"parse-asn1": "npm:parse-asn1@5.0.0",
"stream": "github:jspm/nodelibs-stream@0.1.0"
@ -332,10 +335,10 @@ System.config({
"buffer": "github:jspm/nodelibs-buffer@0.1.0"
},
"npm:create-ecdh@4.0.0": {
"bn.js": "npm:bn.js@4.6.4",
"bn.js": "npm:bn.js@4.10.3",
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"crypto": "github:jspm/nodelibs-crypto@0.1.0",
"elliptic": "npm:elliptic@6.0.2"
"elliptic": "npm:elliptic@6.2.3"
},
"npm:create-hash@1.1.2": {
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
@ -363,14 +366,14 @@ System.config({
"create-ecdh": "npm:create-ecdh@4.0.0",
"create-hash": "npm:create-hash@1.1.2",
"create-hmac": "npm:create-hmac@1.1.4",
"diffie-hellman": "npm:diffie-hellman@5.0.1",
"diffie-hellman": "npm:diffie-hellman@5.0.2",
"inherits": "npm:inherits@2.0.1",
"pbkdf2": "npm:pbkdf2@3.0.4",
"public-encrypt": "npm:public-encrypt@4.0.0",
"randombytes": "npm:randombytes@2.0.2"
},
"npm:dashdash@1.12.1": {
"assert-plus": "npm:assert-plus@0.1.5",
"npm:dashdash@1.12.2": {
"assert-plus": "npm:assert-plus@0.2.0",
"fs": "github:jspm/nodelibs-fs@0.1.2",
"path": "github:jspm/nodelibs-path@0.1.0",
"process": "github:jspm/nodelibs-process@0.1.2",
@ -393,8 +396,8 @@ System.config({
"inherits": "npm:inherits@2.0.1",
"minimalistic-assert": "npm:minimalistic-assert@1.0.0"
},
"npm:diffie-hellman@5.0.1": {
"bn.js": "npm:bn.js@4.6.4",
"npm:diffie-hellman@5.0.2": {
"bn.js": "npm:bn.js@4.10.3",
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"crypto": "github:jspm/nodelibs-crypto@0.1.0",
"miller-rabin": "npm:miller-rabin@4.0.0",
@ -406,8 +409,8 @@ System.config({
"crypto": "github:jspm/nodelibs-crypto@0.1.0",
"jsbn": "npm:jsbn@0.1.0"
},
"npm:elliptic@6.0.2": {
"bn.js": "npm:bn.js@4.6.4",
"npm:elliptic@6.2.3": {
"bn.js": "npm:bn.js@4.10.3",
"brorand": "npm:brorand@1.0.5",
"hash.js": "npm:hash.js@1.0.3",
"inherits": "npm:inherits@2.0.1",
@ -584,7 +587,7 @@ System.config({
"process": "github:jspm/nodelibs-process@0.1.2"
},
"npm:miller-rabin@4.0.0": {
"bn.js": "npm:bn.js@4.6.4",
"bn.js": "npm:bn.js@4.10.3",
"brorand": "npm:brorand@1.0.5"
},
"npm:mime-db@1.21.0": {
@ -616,8 +619,8 @@ System.config({
"process": "github:jspm/nodelibs-process@0.1.2"
},
"npm:parse-asn1@5.0.0": {
"asn1.js": "npm:asn1.js@4.3.0",
"browserify-aes": "npm:browserify-aes@1.0.5",
"asn1.js": "npm:asn1.js@4.4.0",
"browserify-aes": "npm:browserify-aes@1.0.6",
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"create-hash": "npm:create-hash@1.1.2",
"evp_bytestokey": "npm:evp_bytestokey@1.0.0",
@ -637,10 +640,7 @@ System.config({
"systemjs-json": "github:systemjs/plugin-json@0.1.0"
},
"npm:pinkie-promise@2.0.0": {
"pinkie": "npm:pinkie@2.0.1"
},
"npm:pinkie@2.0.1": {
"process": "github:jspm/nodelibs-process@0.1.2"
"pinkie": "npm:pinkie@2.0.4"
},
"npm:prismjs@1.3.0": {
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
@ -654,7 +654,7 @@ System.config({
"assert": "github:jspm/nodelibs-assert@0.1.0"
},
"npm:public-encrypt@4.0.0": {
"bn.js": "npm:bn.js@4.6.4",
"bn.js": "npm:bn.js@4.10.3",
"browserify-rsa": "npm:browserify-rsa@4.0.0",
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"create-hash": "npm:create-hash@1.1.2",
@ -758,7 +758,7 @@ System.config({
"assert-plus": "npm:assert-plus@0.2.0",
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"crypto": "github:jspm/nodelibs-crypto@0.1.0",
"dashdash": "npm:dashdash@1.12.1",
"dashdash": "npm:dashdash@1.12.2",
"ecc-jsbn": "npm:ecc-jsbn@0.1.1",
"jodid25519": "npm:jodid25519@1.0.2",
"jsbn": "npm:jsbn@0.1.0",
@ -866,7 +866,7 @@ System.config({
"systemjs-json": "github:systemjs/plugin-json@0.1.0",
"validator": "npm:validator@4.5.0"
},
"npm:zone.js@0.5.10": {
"npm:zone.js@0.5.11": {
"es6-promise": "npm:es6-promise@3.0.2",
"process": "github:jspm/nodelibs-process@0.1.2"
}

View File

@ -1,27 +1,20 @@
'use strict';
import {BrowserDomAdapter} from 'angular2/platform/browser';
BrowserDomAdapter.makeCurrent();
import {By} from 'angular2/platform/browser';
/** Gets a child DebugElement by tag name. */
export function getChildDebugElement(parent, tagName) {
return parent.query(debugEl => {
return debugEl.nativeElement.tagName && debugEl.nativeElement.tagName.toLowerCase() === tagName;
});
return parent.query(By.css(tagName));
}
/** Gets a child DebugElement by Component Type. */
export function getChildDebugElementByType(parent, type) {
return parent.query(debugEl => {
return debugEl.componentInstance instanceof type;
});
return parent.query(By.directive(type));
}
/** Gets a child DebugElements by tag name. */
export function getChildDebugElementAll(parent, tagName) {
return parent.queryAll(debugEl => {
return debugEl.nativeElement.tagName && debugEl.nativeElement.tagName.toLowerCase() === tagName;
});
return parent.queryAll(By.css(tagName));
}
export function mouseclick( element ) {

13
tests/setup.js Normal file
View File

@ -0,0 +1,13 @@
'use strict';
import {setBaseTestProviders} from 'angular2/testing';
import {
TEST_BROWSER_PLATFORM_PROVIDERS,
TEST_BROWSER_APPLICATION_PROVIDERS
} from 'angular2/platform/testing/browser';
import {
ELEMENT_PROBE_PROVIDERS_PROD_MODE
} from 'angular2/platform/browser';
setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, [TEST_BROWSER_APPLICATION_PROVIDERS, ELEMENT_PROBE_PROVIDERS_PROD_MODE]);