Skip to content

Fixed some minor bugs in HybridHelper #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions hybrid-helper.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { downgradeComponent, downgradeInjectable } from '@angular/upgrade/static';
import { FactoryProvider } from '@angular/core';
import * as angular from 'angular';

export interface IComponentUpgradeOptions {
inputs?: string[],
outputs?: string[]
inputs?: string[];
outputs?: string[];
}

export interface IHybridHelper {
downgradeComponent(moduleName: string, componentSelector: string, componentClass: any, options?: IComponentUpgradeOptions): IHybridHelper,
downgradeProvider(moduleName: string, providerName: string, providerClass: any): IHybridHelper,
buildProviderForUpgrade(ng1Name: string, ng2Name?: string): FactoryProvider
downgradeComponent(moduleName: string, componentSelector: string, componentClass: any, options?: IComponentUpgradeOptions): IHybridHelper;
downgradeProvider(moduleName: string, providerName: string, providerClass: any): IHybridHelper;
buildProviderForUpgrade(ng1Name: string, ng2Name?: string): FactoryProvider;
}

export const HybridHelper: IHybridHelper {
export const HybridHelper: IHybridHelper = {

downgradeComponent: (moduleName: string, componentName: string, componentClass: any, options?: IComponentUpgradeOptions): IHybridHelper => {
downgradeComponent: (moduleName: string, componentSelector: string, componentClass: any, options?: IComponentUpgradeOptions): IHybridHelper => {
options = options || {};
const inputs = options.inputs || [];
const outputs = options.outputs || [];
const component = componentClass;

angular.module(moduleName).directive(componentName, downgradeComponent({
component, inputs, outputs
angular.module(moduleName).directive(componentSelector, downgradeComponent({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the componentSelector. Selector has a dash.
I prefer to be consistence with the AngularJS code.
Please revert this change and I will merge this pull request.

The definition of the directive function in the AngularJS code:
/** * @ngdoc method * @name angular.Module#directive * @module ng * @param {string|Object} name Directive name, or an object map of directives where the * keys are the names and the values are the factories. * @param {Function} directiveFactory Factory function for creating new instance of * directives. * @description * See {@link ng.$compileProvider#directive $compileProvider.directive()}. */ directive: invokeLaterAndSetModuleName('$compileProvider', 'directive'),

component, inputs, outputs
}) as angular.IDirectiveFactory);

return HybridHelper;
Expand All @@ -35,15 +36,15 @@ export const HybridHelper: IHybridHelper {

buildProviderForUpgrade: (ng1Name: string, ng2Name?: string): FactoryProvider => {
ng2Name = ng2Name || ng1Name;

return {
provide: ng2Name,
useFactory: buildFactoryForUpgradeProvider(ng1Name),
deps: ['$injector']
};
}
}
};

function buildFactoryForUpgradeProvider(ng1Name: string): Function {
return (injector: any) => injector.get(ng1Name);
return (injector: any) => injector.get(ng1Name);
}