Skip to content

Commit

Permalink
Merge pull request #23 from readdle/feature/tslint-support
Browse files Browse the repository at this point in the history
Add tslint and fix all warnings
  • Loading branch information
endway authored Oct 30, 2017
2 parents 663f142 + ad596c8 commit b45b0c7
Show file tree
Hide file tree
Showing 12 changed files with 1,219 additions and 28 deletions.
2 changes: 1 addition & 1 deletion decorators/directive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ export function Directive<IComponentClass>({selector}: {
Reflect.defineMetadata(Metakeys.type, DeclarationType.directive, target);

return target;
}
};
}
16 changes: 10 additions & 6 deletions decorators/ng-module/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import importHandler from "./metadata-handlers/import";
import daclarationHandler from "./metadata-handlers/declaration";
import providerHandler from "./metadata-handlers/provider";
import counter from '../../helpers/counter';
import counter from "../../helpers/counter";

export function NgModule({id, imports, declarations, providers, directRegister}: any) {
return function (target: any) {
var ng1ModuleIds: Array<string> = [];
var ng1RouterConfig;
let ng1ModuleIds: Array<string> = [];
let ng1RouterConfig;

if (imports && imports.length) {
var {ng1ModuleIds, ng1RouterConfig} = importHandler(imports);
const hasImports = imports && imports.length;

if (hasImports) {
const handledImports = importHandler(imports);
ng1ModuleIds = handledImports.ng1ModuleIds;
ng1RouterConfig = handledImports.ng1RouterConfig;
}

target.ng1ShiftModuleName = `${target.name}-${counter("moduleName")}`;
Expand All @@ -35,5 +39,5 @@ export function NgModule({id, imports, declarations, providers, directRegister}:
if (directRegister) {
directRegister(ng1Module);
}
}
};
}
2 changes: 1 addition & 1 deletion decorators/ng-module/metadata-handlers/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export default function importHandler(imports: Array<ng1Module>) {
return {
ng1ModuleIds,
ng1RouterConfig
}
};
}
2 changes: 1 addition & 1 deletion helpers/array.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function findFirst<T>(array: Array<T>, expression: (value: T) => boolean): T {
if (!angular.isFunction(expression)) {
let first = array[0];
const first = array[0];
if (!first) {
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions helpers/counter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
let store = {} as any;
const entityCounters: Record<string, number> = {};

export default function counter(entity: string) {
const registeredEntity = entity in store;
const registeredEntity = entity in entityCounters;

if (!registeredEntity) {
store[entity] = 0;
entityCounters[entity] = 0;
}

return store[entity]++;
return entityCounters[entity]++;
}
5 changes: 3 additions & 2 deletions helpers/kebab-case-to-camel-case.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export default function kebabCaseToCamelCase(str: string) {
if (str.indexOf("-") !== -1) {
const newArr = str.split("-");
const newArr = str.toLowerCase().split("-");

for (var i = 1 ; i < newArr.length ; i++) {
// We are starting from 1 because the first letter in camelCase word is in lowercase
for (let i = 1; i < newArr.length; i++) {
newArr[i] = newArr[i].charAt(0).toUpperCase() + newArr[i].substr(1);
}

Expand Down
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function Inject(dependencyName: string): ParameterDecorator {
};
}

export function Component<IComponentClass>(config?: {selector?: string, template?: string}): ClassDecorator {
export function Component(config?: {selector?: string, template?: string}): ClassDecorator {
return function (target: any) {
if (config) {
if (config.template) {
Expand Down Expand Up @@ -118,7 +118,7 @@ export function Component<IComponentClass>(config?: {selector?: string, template
Reflect.defineMetadata(Metakeys.type, DeclarationType.component, target);

return target;
}
};
}

export class EventEmitter {
Expand Down
Loading

0 comments on commit b45b0c7

Please sign in to comment.