Skip to content
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

feat(core/linker): add SimpleChanges interface to lifecycle_hooks #8557

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,7 +4,7 @@ import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
import {
OnChanges,
OnDestroy,
SimpleChange,
SimpleChanges,
Query,
Directive,
forwardRef,
Expand Down Expand Up @@ -114,7 +114,7 @@ export class NgControlName extends NgControl implements OnChanges,
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}

ngOnChanges(changes: {[key: string]: SimpleChange}) {
ngOnChanges(changes: SimpleChanges) {
if (!this._added) {
this.formDirective.addControl(this);
this._added = true;
Expand Down
Expand Up @@ -3,7 +3,7 @@ import {StringMapWrapper} from 'angular2/src/facade/collection';
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
import {
OnChanges,
SimpleChange,
SimpleChanges,
Query,
Directive,
forwardRef,
Expand Down Expand Up @@ -97,7 +97,7 @@ export class NgFormControl extends NgControl implements OnChanges {
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}

ngOnChanges(changes: {[key: string]: SimpleChange}): void {
ngOnChanges(changes: SimpleChanges): void {
if (this._isControlChanged(changes)) {
setUpControl(this.form, this);
this.form.updateValueAndValidity({emitEvent: false});
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/src/common/forms/directives/ng_form_model.ts
Expand Up @@ -2,7 +2,7 @@ import {CONST_EXPR} from 'angular2/src/facade/lang';
import {ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
import {ObservableWrapper, EventEmitter} from 'angular2/src/facade/async';
import {
SimpleChange,
SimpleChanges,
OnChanges,
Directive,
forwardRef,
Expand Down Expand Up @@ -113,7 +113,7 @@ export class NgFormModel extends ControlContainer implements Form,
super();
}

ngOnChanges(changes: {[key: string]: SimpleChange}): void {
ngOnChanges(changes: SimpleChanges): void {
if (StringMapWrapper.contains(changes, "form")) {
var sync = composeValidators(this._validators);
this.form.validator = Validators.compose([this.form.validator, sync]);
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/src/common/forms/directives/ng_model.ts
Expand Up @@ -2,7 +2,7 @@ import {CONST_EXPR} from 'angular2/src/facade/lang';
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
import {
OnChanges,
SimpleChange,
SimpleChanges,
Query,
Directive,
forwardRef,
Expand Down Expand Up @@ -71,7 +71,7 @@ export class NgModel extends NgControl implements OnChanges {
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}

ngOnChanges(changes: {[key: string]: SimpleChange}) {
ngOnChanges(changes: SimpleChanges) {
if (!this._added) {
setUpControl(this._control, this);
this._control.updateValueAndValidity({emitEvent: false});
Expand Down
5 changes: 3 additions & 2 deletions modules/angular2/src/core/linker.ts
Expand Up @@ -7,7 +7,8 @@ export {
OnChanges,
OnDestroy,
OnInit,
DoCheck
DoCheck,
SimpleChanges
} from './linker/interfaces';
export {DirectiveResolver} from './linker/directive_resolver';
export {ViewResolver} from './linker/view_resolver';
Expand All @@ -19,4 +20,4 @@ export {ElementRef} from './linker/element_ref';
export {TemplateRef} from './linker/template_ref';
export {ViewRef, HostViewRef, ProtoViewRef} from './linker/view_ref';
export {ViewContainerRef} from './linker/view_container_ref';
export {ComponentRef} from './linker/dynamic_component_loader';
export {ComponentRef} from './linker/dynamic_component_loader';
10 changes: 8 additions & 2 deletions modules/angular2/src/core/linker/interfaces.ts
Expand Up @@ -12,6 +12,12 @@ export enum LifecycleHooks {
AfterViewChecked
}

/**
* A `changes` object whose keys are property names and
* values are instances of {@link SimpleChange}. See {@link OnChanges}
*/
export interface SimpleChanges {[propName: string]: SimpleChange};

/**
* @internal
*/
Expand Down Expand Up @@ -57,7 +63,7 @@ export var LIFECYCLE_HOOKS_VALUES = [
* class MyComponent implements OnChanges {
* @Input() myProp: any;
*
* ngOnChanges(changes: {[propName: string]: SimpleChange}) {
* ngOnChanges(changes: SimpleChanges) {
* console.log('ngOnChanges - myProp = ' + changes['myProp'].currentValue);
* }
* }
Expand All @@ -76,7 +82,7 @@ export var LIFECYCLE_HOOKS_VALUES = [
* bootstrap(App).catch(err => console.error(err));
* ```
*/
export interface OnChanges { ngOnChanges(changes: {[key: string]: SimpleChange}); }
export interface OnChanges { ngOnChanges(changes: SimpleChanges); }

/**
* Implement this interface to execute custom initialization logic after your directive's
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/src/upgrade/downgrade_ng2_adapter.ts
Expand Up @@ -6,7 +6,7 @@ import {
Injector,
OnChanges,
ProtoViewRef,
SimpleChange
SimpleChanges
} from 'angular2/core';
import {NG1_SCOPE} from './constants';
import {ComponentInfo} from './metadata';
Expand All @@ -20,7 +20,7 @@ const INITIAL_VALUE = {
export class DowngradeNg2ComponentAdapter {
component: any = null;
inputChangeCount: number = 0;
inputChanges: {[key: string]: SimpleChange} = null;
inputChanges: SimpleChanges = null;
hostViewRef: HostViewRef = null;
changeDetector: ChangeDetectorRef = null;
componentScope: angular.IScope;
Expand Down
3 changes: 2 additions & 1 deletion modules/angular2/src/upgrade/upgrade_ng1_adapter.ts
Expand Up @@ -6,6 +6,7 @@ import {
Inject,
OnChanges,
SimpleChange,
SimpleChanges,
Type
} from 'angular2/core';
import {
Expand Down Expand Up @@ -224,7 +225,7 @@ class UpgradeNg1ComponentAdapter implements OnChanges, DoCheck {
}
}

ngOnChanges(changes: {[name: string]: SimpleChange}) {
ngOnChanges(changes: SimpleChanges) {
for (var name in changes) {
if ((<Object>changes).hasOwnProperty(name)) {
var change: SimpleChange = changes[name];
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/test/compiler/runtime_metadata_spec.ts
Expand Up @@ -30,7 +30,7 @@ import {
AfterContentChecked,
AfterViewInit,
AfterViewChecked,
SimpleChange,
SimpleChanges,
provide
} from 'angular2/core';

Expand Down Expand Up @@ -136,7 +136,7 @@ class DirectiveWithoutModuleId {
class ComponentWithEverything implements OnChanges,
OnInit, DoCheck, OnDestroy, AfterContentInit, AfterContentChecked, AfterViewInit,
AfterViewChecked {
ngOnChanges(changes: {[key: string]: SimpleChange}): void {}
ngOnChanges(changes: SimpleChanges): void {}
ngOnInit(): void {}
ngDoCheck(): void {}
ngOnDestroy(): void {}
Expand Down