-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: Components with getter and setter without both are not supported ISSUES CLOSED: #28, #29
- Loading branch information
Showing
15 changed files
with
220 additions
and
65 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,103 @@ | ||
import { ChangeDetectionStrategy, Component, DoCheck, OnInit } from '@angular/core'; | ||
import { | ||
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
DoCheck, | ||
OnInit, | ||
} from '@angular/core'; | ||
import { onChangesWrapper } from '../utils'; | ||
|
||
const lifeCycleComponentSymbol = Symbol('Life Cycle Component'); | ||
|
||
export interface LifeCycleComponent { | ||
[lifeCycleComponentSymbol]: boolean; | ||
|
||
attach(context: unknown, changeDetectorRef: ChangeDetectorRef): void; | ||
} | ||
|
||
export function isLifeCycleComponent(component: unknown): component is LifeCycleComponent { | ||
return component && component[lifeCycleComponentSymbol]; | ||
} | ||
|
||
@Component({ | ||
selector: 'ngx-component-outlet-on-init-only', | ||
template: '', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class OnInitOnlyComponent implements OnInit { | ||
ngOnInit() {} | ||
export class OnInitOnlyComponent implements LifeCycleComponent, OnInit { | ||
[lifeCycleComponentSymbol] = true; | ||
|
||
private context: unknown; | ||
private changeDetectorRef: ChangeDetectorRef; | ||
|
||
ngOnInit() { | ||
if (this.context) { | ||
onChangesWrapper(() => {}).call(this.context); | ||
} | ||
} | ||
|
||
attach(context: unknown, changeDetectorRef: ChangeDetectorRef): void { | ||
this.context = context; | ||
this.changeDetectorRef = changeDetectorRef; | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'ngx-component-outlet-do-check-only', | ||
template: '', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class DoCheckOnlyComponent implements DoCheck { | ||
ngDoCheck() {} | ||
export class DoCheckOnlyComponent implements LifeCycleComponent, DoCheck { | ||
[lifeCycleComponentSymbol] = true; | ||
|
||
private context: unknown; | ||
private changeDetectorRef: ChangeDetectorRef; | ||
|
||
ngDoCheck() { | ||
if (this.context) { | ||
onChangesWrapper(() => {}).call(this.context); | ||
} | ||
|
||
if (this.changeDetectorRef) { | ||
this.changeDetectorRef.markForCheck(); | ||
} | ||
} | ||
|
||
attach(context: unknown, changeDetectorRef: ChangeDetectorRef): void { | ||
this.context = context; | ||
this.changeDetectorRef = changeDetectorRef; | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'ngx-component-outlet-on-init-do-check', | ||
template: '', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class OnInitAndDoCheckComponent implements OnInit, DoCheck { | ||
ngOnInit() {} | ||
export class OnInitAndDoCheckComponent implements LifeCycleComponent, OnInit, DoCheck { | ||
[lifeCycleComponentSymbol] = true; | ||
|
||
private context: unknown; | ||
private changeDetectorRef: ChangeDetectorRef; | ||
|
||
ngOnInit() { | ||
if (this.context) { | ||
onChangesWrapper(() => {}).call(this.context); | ||
} | ||
} | ||
|
||
ngDoCheck() { | ||
if (this.context) { | ||
onChangesWrapper(() => {}).call(this.context); | ||
} | ||
|
||
if (this.changeDetectorRef) { | ||
this.changeDetectorRef.markForCheck(); | ||
} | ||
} | ||
|
||
ngDoCheck() {} | ||
attach(context: unknown, changeDetectorRef: ChangeDetectorRef): void { | ||
this.context = context; | ||
this.changeDetectorRef = changeDetectorRef; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.