Comparing version 0.0.8 to 0.0.9
import kebabCaseToCamelCase from "../../../helpers/kebab-case-to-camel-case"; | ||
import {DeclarationType} from "../../../models/declaration-type"; | ||
import {Metakeys} from "../../../models/metakeys"; | ||
import {removeBracketsAndDot} from "../../directive/helpers"; | ||
import {DirectiveFactory} from "../../directive/factory"; | ||
export default function daclarationHandler(ng1Module: any, declarations: any) { | ||
declarations.forEach((declaration: any) => { | ||
const selectorNg2 = declaration.selector; | ||
const selectorNg1 = kebabCaseToCamelCase(selectorNg2); | ||
const hasNg1Meta = Reflect.hasMetadata(Metakeys.type, declaration); | ||
ng1Module.component(selectorNg1, declaration); | ||
if (hasNg1Meta) { | ||
const declarationType = Reflect.getMetadata(Metakeys.type, declaration); | ||
const selectorNg2 = declaration.selector; | ||
let selectorNg1: string; | ||
switch (declarationType) { | ||
case DeclarationType.component: | ||
selectorNg1 = kebabCaseToCamelCase(selectorNg2); | ||
ng1Module.component(selectorNg1, declaration); | ||
break; | ||
case DeclarationType.directive: | ||
selectorNg1 = removeBracketsAndDot(selectorNg2); | ||
ng1Module.directive(selectorNg1, DirectiveFactory(declaration)); | ||
break; | ||
} | ||
} | ||
}); | ||
} |
@@ -24,2 +24,6 @@ const HtmlWebpackPlugin = require("html-webpack-plugin"); | ||
devServer: { | ||
port: 3000 | ||
}, | ||
plugins: [ | ||
@@ -26,0 +30,0 @@ new HtmlWebpackPlugin({ |
@@ -40,3 +40,7 @@ const DefinePlugin = require("webpack/lib/DefinePlugin"); | ||
devServer: { | ||
port: 3001 | ||
}, | ||
plugins | ||
}); |
@@ -8,2 +8,3 @@ const {Component} = require("./export-switch"); | ||
<ng-shift-component></ng-shift-component> | ||
<ng-shift-directive></ng-shift-directive> | ||
<ng-shift-router></ng-shift-router> | ||
@@ -10,0 +11,0 @@ ` |
if (process.env.NG2) { | ||
var {NgModule, Component, EventEmitter, Inject, Input, Output} = require("@angular/core"); | ||
var {NgModule, Component, Directive, EventEmitter, Inject, Input, Output} = require("@angular/core"); | ||
@@ -8,3 +8,3 @@ var BrowserModule = [require("@angular/platform-browser").BrowserModule] as any; | ||
} else { | ||
var {NgModule, Component, EventEmitter, Inject, Input, Output} = require("../../../index"); | ||
var {NgModule, Component, Directive, EventEmitter, Inject, Input, Output} = require("../../../index"); | ||
@@ -23,2 +23,3 @@ var BrowserModule = [] as any; | ||
NgModule, | ||
Directive, | ||
Component, | ||
@@ -25,0 +26,0 @@ EventEmitter, |
@@ -8,2 +8,3 @@ const {NgModule, BrowserModule, UIRouterModule} = require("./export-switch"); | ||
import {NgShiftComponentModule} from "./component/index"; | ||
import {NgShiftDirectiveModule} from "./directive/index"; | ||
import {NgShiftRouterTestModule} from "./router"; | ||
@@ -19,2 +20,3 @@ | ||
NgShiftComponentModule, | ||
NgShiftDirectiveModule, | ||
NgShiftRouterTestModule | ||
@@ -21,0 +23,0 @@ ], |
import {NgModuleDecorator} from "./decorators/ng-module/interfaces"; | ||
import {DirectiveDecorator} from "./decorators/directive/interfaces"; | ||
@@ -8,2 +9,8 @@ /** | ||
/** | ||
* Directive decorator and metadata. | ||
*/ | ||
export declare const Directive: DirectiveDecorator; | ||
export interface Component { | ||
@@ -10,0 +17,0 @@ /** |
@@ -1,3 +0,7 @@ | ||
export * from './decorators/ng-module'; | ||
import {DeclarationType} from "./models/declaration-type"; | ||
import {Metakeys} from "./models/metakeys"; | ||
export * from "./decorators/ng-module"; | ||
export * from "./decorators/directive"; | ||
interface IComponentClass extends Function { | ||
@@ -109,2 +113,4 @@ $inject?: Array<string>; | ||
Reflect.defineMetadata(Metakeys.type, DeclarationType.component, target); | ||
return target; | ||
@@ -111,0 +117,0 @@ } |
{ | ||
"name": "ng1-shift", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Angular 1.5+ decorators for writing Angular2 like.", | ||
@@ -49,2 +49,3 @@ "main": "dist/index.js", | ||
"jest": "20.0.4", | ||
"reflect-metadata": "0.1.10", | ||
"rollup-watch": "3.2.2", | ||
@@ -51,0 +52,0 @@ "ts-jest": "20.0.5", |
@@ -57,2 +57,57 @@ # ng1-shift | ||
## Directive | ||
Decorator for class, which links class to directive contoller. | ||
It also passes property `selector` as a directive selector. | ||
Lifecycle hooks: | ||
- **ngOnInit** - links to $onInit | ||
- **ngAfterViewInit** - links to $postLink | ||
- **ngOnChanges** - links to $onChanges | ||
- **ngOnDestroy** - links to $onDestroy | ||
```typescript | ||
import {Directive} from "ng1-shift"; | ||
@Directive({ | ||
selector: `.ngClassDirective`, | ||
}) | ||
export class PlaygroundDirective implements ng.IController { | ||
ngOnInit() { | ||
} | ||
ngAfterViewInit() { | ||
} | ||
ngOnChanges() { | ||
} | ||
ngOnDestroy() { | ||
} | ||
} | ||
``` | ||
Equals to: | ||
```typescript | ||
export directiveInstance() { | ||
return { | ||
controller: PlaygroundDirective, | ||
restrict: "C" | ||
} | ||
} | ||
class PlaygroundDirective implements ng.IController { | ||
$onInit() { | ||
} | ||
$postLink() { | ||
} | ||
$onChanges() { | ||
} | ||
$onDestroy() { | ||
} | ||
} | ||
``` | ||
## Input | ||
@@ -59,0 +114,0 @@ Property decorator for bindings. Literary puts binding property name into static object `bindings` as one-way binding "<". |
@@ -15,3 +15,3 @@ import * as path from "path"; | ||
], | ||
external: ["reflect-metadata"] | ||
external: ["reflect-metadata", "tslib"] | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50044
67
1228
172
7