Skip to content

Commit

Permalink
4.0.1-beta-0:
Browse files Browse the repository at this point in the history
- Renamed AotAware to LiComponent
  • Loading branch information
lVlyke committed Feb 2, 2020
1 parent 346bd4c commit c51db11
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 31 deletions.
23 changes: 6 additions & 17 deletions spec/aot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import { Template, Spec } from "detest-bdd";
import { Spec } from "detest-bdd";
import { AotAware } from "../src/aot";
import { AngularLifecycleType } from "../src/lifecycle-event";
import { LiComponent } from "../src/component";

const spec = Spec.create<{
targetClass: AotAware
}>();
const spec = Spec.create<{}>();

describe("Given an AotAware class", () => {

Template.withInputs<{ methodName: AngularLifecycleType }>(["methodName"], (methodName: AngularLifecycleType) => {

spec.beforeEach(params => { params.targetClass = new class extends AotAware {} });

spec.it(`should define a ${methodName} method`, (params) => {
const angularFn = params.targetClass[methodName];

expect(() => angularFn()).not.toThrow();

expect(params.targetClass[methodName]).toEqual(jasmine.any(Function));
});
}, ...AngularLifecycleType.values.map(methodName => ({ methodName })))();
spec.it("it should equal LiComponent", () => {
expect(AotAware).toBe(LiComponent)
});
});
27 changes: 27 additions & 0 deletions spec/component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Template, Spec } from "detest-bdd";
import { LiComponent } from "../src/component";
import { AngularLifecycleType } from "../src/lifecycle-event";

const spec = Spec.create<{
targetClass: LiComponent
}>();

describe("Given a LiComponent class", () => {

spec.it("it should extend TemplateDynamic", () => {
expect(Object.getPrototypeOf(LiComponent).name).toEqual("TemplateDynamic");
});

Template.withInputs<{ methodName: AngularLifecycleType }>(["methodName"], (methodName: AngularLifecycleType) => {

spec.beforeEach(params => { params.targetClass = new class extends LiComponent {} });

spec.it(`should define a ${methodName} method`, (params) => {
const angularFn = params.targetClass[methodName];

expect(() => angularFn()).not.toThrow();

expect(params.targetClass[methodName]).toEqual(jasmine.any(Function));
});
}, ...AngularLifecycleType.values.map(methodName => ({ methodName })))();
});
20 changes: 6 additions & 14 deletions src/aot.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
// Enable dynamic templating in AoT compiled components
export function AotDynamic(): new(...args: any[]) => { [K in keyof any]: any[K]; } {
return class {};
}
import { LiComponent } from "./component";

export class AotAware extends AotDynamic() {
public ngOnChanges() { }
public ngOnInit() { }
public ngOnDestroy() { }
public ngDoCheck() { }
public ngAfterContentInit() { }
public ngAfterContentChecked() { }
public ngAfterViewInit() { }
public ngAfterViewChecked() { }
}
/**
* @deprecated
* @see LiComponent
*/
export const AotAware = LiComponent;
16 changes: 16 additions & 0 deletions src/component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Enable dynamic templating for Ivy-compiled components:
export function TemplateDynamic(): new(...args: any[]) => { [K in keyof any]: any[K]; } {
return class TemplateDynamic{};
}

export abstract class LiComponent extends TemplateDynamic() {
public ngOnChanges() { }
public ngOnInit() { }
public ngOnDestroy() { }
public ngDoCheck() { }
public ngAfterContentInit() { }
public ngAfterContentChecked() { }
public ngAfterViewInit() { }
public ngAfterViewChecked() { }
}

/** @ClassDecoratorFactory */
export function Reactive(): ClassDecorator {
console.info("DEPRECATION NOTICE: The @Reactive() class decorator is no longer used and can be removed from your code. It will be removed in a future version of @lithiumjs/angular.");
Expand Down

0 comments on commit c51db11

Please sign in to comment.