refactor(upgrade): clean up some types

This commit is contained in:
Georgios Kalpakas 2017-07-11 16:15:40 +03:00 committed by Alex Rickabaugh
parent a0b06befb6
commit 44b50427d9
5 changed files with 44 additions and 44 deletions

View File

@ -50,7 +50,7 @@ export interface IRootScopeService {
$destroy(): any;
$apply(exp?: Ng1Expression): any;
$digest(): any;
$evalAsync(): any;
$evalAsync(exp: Ng1Expression, locals?: any): void;
$on(event: string, fn?: (event?: any, ...args: any[]) => void): Function;
$$childTail: IScope;
$$childHead: IScope;
@ -101,7 +101,10 @@ export interface IComponent {
templateUrl?: string|Function;
transclude?: DirectiveTranscludeProperty;
}
export interface IAttributes { $observe(attr: string, fn: (v: string) => void): void; }
export interface IAttributes {
$observe(attr: string, fn: (v: string) => void): void;
[key: string]: any;
}
export interface ITranscludeFunction {
// If the scope is provided, then the cloneAttachFn must be as well.
(scope: IScope, cloneAttachFn: ICloneAttachFunction): IAugmentedJQuery;
@ -135,7 +138,10 @@ export interface IProvideService {
decorator(token: Ng1Token, factory: IInjectable): void;
}
export interface IParseService { (expression: string): ICompiledExpression; }
export interface ICompiledExpression { assign(context: any, value: any): any; }
export interface ICompiledExpression {
(context: any, locals: any): any;
assign?: (context: any, value: any) => any;
}
export interface IHttpBackendService {
(method: string, url: string, post?: any, callback?: Function, headers?: any, timeout?: number,
withCredentials?: boolean): void;
@ -211,8 +217,8 @@ function noNg() {
let angular: {
bootstrap: (e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig) =>
void,
bootstrap: (e: Element, modules: (string | IInjectable)[], config?: IAngularBootstrapConfig) =>
IInjectorService,
module: (prefix: string, dependencies?: string[]) => IModule,
element: (e: Element | string) => IAugmentedJQuery,
version: {major: number},
@ -256,16 +262,16 @@ export function getAngularLib(): any {
}
export const bootstrap =
(e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig): void =>
(e: Element, modules: (string | IInjectable)[], config?: IAngularBootstrapConfig) =>
angular.bootstrap(e, modules, config);
export const module = (prefix: string, dependencies?: string[]): IModule =>
export const module = (prefix: string, dependencies?: string[]) =>
angular.module(prefix, dependencies);
export const element = (e: Element | string): IAugmentedJQuery => angular.element(e);
export const element = (e: Element | string) => angular.element(e);
export const resumeBootstrap = (): void => angular.resumeBootstrap();
export const resumeBootstrap = () => angular.resumeBootstrap();
export const getTestability = (e: Element): ITestabilityService => angular.getTestability(e);
export const getTestability = (e: Element) => angular.getTestability(e);
export const version = angular.version;

View File

@ -69,7 +69,7 @@ export class DowngradeComponentAdapter {
const inputs = this.componentFactory.inputs || [];
for (let i = 0; i < inputs.length; i++) {
const input = new PropertyBinding(inputs[i].propName, inputs[i].templateName);
let expr: any /** TODO #9100 */ = null;
let expr: string|null = null;
if (attrs.hasOwnProperty(input.attr)) {
const observeFn = (prop => {
@ -91,20 +91,20 @@ export class DowngradeComponentAdapter {
// Use `$watch()` (in addition to `$observe()`) in order to initialize the input in time
// for `ngOnChanges()`. This is necessary if we are already in a `$digest`, which means that
// `ngOnChanges()` (which is called by a watcher) will run before the `$observe()` callback.
let unwatch: any = this.componentScope.$watch(() => {
unwatch('');
let unwatch: Function|null = this.componentScope.$watch(() => {
unwatch !();
unwatch = null;
observeFn((attrs as any)[input.attr]);
observeFn(attrs[input.attr]);
});
} else if (attrs.hasOwnProperty(input.bindAttr)) {
expr = (attrs as any /** TODO #9100 */)[input.bindAttr];
expr = attrs[input.bindAttr];
} else if (attrs.hasOwnProperty(input.bracketAttr)) {
expr = (attrs as any /** TODO #9100 */)[input.bracketAttr];
expr = attrs[input.bracketAttr];
} else if (attrs.hasOwnProperty(input.bindonAttr)) {
expr = (attrs as any /** TODO #9100 */)[input.bindonAttr];
expr = attrs[input.bindonAttr];
} else if (attrs.hasOwnProperty(input.bracketParenAttr)) {
expr = (attrs as any /** TODO #9100 */)[input.bracketParenAttr];
expr = attrs[input.bracketParenAttr];
}
if (expr != null) {
const watchFn =
@ -132,24 +132,22 @@ export class DowngradeComponentAdapter {
const outputs = this.componentFactory.outputs || [];
for (let j = 0; j < outputs.length; j++) {
const output = new PropertyBinding(outputs[j].propName, outputs[j].templateName);
let expr: any /** TODO #9100 */ = null;
let expr: string|null = null;
let assignExpr = false;
const bindonAttr =
output.bindonAttr ? output.bindonAttr.substring(0, output.bindonAttr.length - 6) : null;
const bracketParenAttr = output.bracketParenAttr ?
`[(${output.bracketParenAttr.substring(2, output.bracketParenAttr.length - 8)})]` :
null;
const bindonAttr = output.bindonAttr.substring(0, output.bindonAttr.length - 6);
const bracketParenAttr =
`[(${output.bracketParenAttr.substring(2, output.bracketParenAttr.length - 8)})]`;
if (attrs.hasOwnProperty(output.onAttr)) {
expr = (attrs as any /** TODO #9100 */)[output.onAttr];
expr = attrs[output.onAttr];
} else if (attrs.hasOwnProperty(output.parenAttr)) {
expr = (attrs as any /** TODO #9100 */)[output.parenAttr];
} else if (attrs.hasOwnProperty(bindonAttr !)) {
expr = (attrs as any /** TODO #9100 */)[bindonAttr !];
expr = attrs[output.parenAttr];
} else if (attrs.hasOwnProperty(bindonAttr)) {
expr = attrs[bindonAttr];
assignExpr = true;
} else if (attrs.hasOwnProperty(bracketParenAttr !)) {
expr = (attrs as any /** TODO #9100 */)[bracketParenAttr !];
} else if (attrs.hasOwnProperty(bracketParenAttr)) {
expr = attrs[bracketParenAttr];
assignExpr = true;
}
@ -162,10 +160,8 @@ export class DowngradeComponentAdapter {
const emitter = this.component[output.prop] as EventEmitter<any>;
if (emitter) {
emitter.subscribe({
next: assignExpr ?
((setter: any) => (v: any /** TODO #9100 */) => setter(this.scope, v))(setter) :
((getter: any) => (v: any /** TODO #9100 */) =>
getter(this.scope, {'$event': v}))(getter)
next: assignExpr ? (v: any) => setter !(this.scope, v) :
(v: any) => getter(this.scope, {'$event': v})
});
} else {
throw new Error(

View File

@ -247,7 +247,7 @@ export class UpgradeModule {
const upgradeModule = angular.module(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));
// Make sure resumeBootstrap() only exists if the current bootstrap is deferred
const windowAngular = (window as any /** TODO #???? */)['angular'];
const windowAngular = (window as any)['angular'];
windowAngular.resumeBootstrap = undefined;
// Bootstrap the AngularJS application inside our zone
@ -280,4 +280,4 @@ class NgAdapterInjector implements Injector {
return this.modInjector.get(token, notFoundValue);
}
}
}

View File

@ -21,8 +21,8 @@ export function main() {
afterEach(() => destroyPlatform());
it('should interleave scope and component expressions', async(() => {
const log: any[] /** TODO #9100 */ = [];
const l = (value: any /** TODO #9100 */) => {
const log: string[] = [];
const l = (value: string) => {
log.push(value);
return value + ';';
};
@ -46,8 +46,7 @@ export function main() {
template: `{{l('2A')}}<ng1a></ng1a>{{l('2B')}}<ng1b></ng1b>{{l('2C')}}`
})
class Ng2Component {
l: (value: any) => string;
constructor() { this.l = l; }
l = l;
}
@NgModule({
@ -63,7 +62,7 @@ export function main() {
.directive('ng1a', () => ({template: '{{ l(\'ng1a\') }}'}))
.directive('ng1b', () => ({template: '{{ l(\'ng1b\') }}'}))
.directive('ng2', downgradeComponent({component: Ng2Component}))
.run(($rootScope: any /** TODO #9100 */) => {
.run(($rootScope: angular.IRootScopeService) => {
$rootScope.l = l;
$rootScope.reset = () => log.length = 0;
});
@ -72,7 +71,6 @@ export function main() {
html('<div>{{reset(); l(\'1A\');}}<ng2>{{l(\'1B\')}}</ng2>{{l(\'1C\')}}</div>');
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then((upgrade) => {
expect(document.body.textContent).toEqual('1A;2A;ng1a;2B;ng1b;2C;1C;');
// https://github.com/angular/angular.js/issues/12983
expect(log).toEqual(['1A', '1C', '2A', '2B', '2C', 'ng1a', 'ng1b']);
});
}));
@ -88,7 +86,7 @@ export function main() {
@Component({
selector: 'my-child',
template: '<div>{{valueFromPromise}}',
template: '<div>{{ valueFromPromise }}</div>',
})
class ChildComponent {
valueFromPromise: number;

View File

@ -18,7 +18,7 @@ export function bootstrap(
// We bootstrap the Angular module first; then when it is ready (async)
// We bootstrap the AngularJS module on the bootstrap element
return platform.bootstrapModule(Ng2Module).then(ref => {
const upgrade = ref.injector.get(UpgradeModule) as UpgradeModule;
const upgrade = ref.injector.get<UpgradeModule>(UpgradeModule);
upgrade.bootstrap(element, [ng1Module.name]);
return upgrade;
});