From b81b1fb81c669babaa329a1a4911164a25896b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Fri, 19 Feb 2016 10:34:03 -0800 Subject: [PATCH] revert: fix(change_detection): allow to destroy `OnPush` components inside of a host event This reverts commit 280b86ec553ec0a5bd6ca9b022c77eedbbba2640. --- .../change_detection_jit_generator.ts | 2 +- .../dynamic_change_detector.ts | 4 +-- .../test/core/linker/integration_spec.ts | 34 ------------------- 3 files changed, 2 insertions(+), 38 deletions(-) diff --git a/modules/angular2/src/core/change_detection/change_detection_jit_generator.ts b/modules/angular2/src/core/change_detection/change_detection_jit_generator.ts index 37a9dfa983..80d1573c34 100644 --- a/modules/angular2/src/core/change_detection/change_detection_jit_generator.ts +++ b/modules/angular2/src/core/change_detection/change_detection_jit_generator.ts @@ -174,7 +174,7 @@ export class ChangeDetectorJITGenerator { var evalRecord = this._logic.genEventBindingEvalValue(eb, r); var markPath = this._genMarkPathToRootAsCheckOnce(r); var prevDefault = this._genUpdatePreventDefault(eb, r); - return `${markPath}\n${evalRecord}\n${prevDefault}`; + return `${evalRecord}\n${markPath}\n${prevDefault}`; } else { return this._logic.genEventBindingEvalValue(eb, r); } diff --git a/modules/angular2/src/core/change_detection/dynamic_change_detector.ts b/modules/angular2/src/core/change_detection/dynamic_change_detector.ts index 62be8b7df7..078c51f20c 100644 --- a/modules/angular2/src/core/change_detection/dynamic_change_detector.ts +++ b/modules/angular2/src/core/change_detection/dynamic_change_detector.ts @@ -60,11 +60,9 @@ export class DynamicChangeDetector extends AbstractChangeDetector { if (proto.isSkipRecord()) { protoIdx += this._computeSkipLength(protoIdx, proto, values); } else { - if (proto.lastInBinding) { - this._markPathAsCheckOnce(proto); - } var res = this._calculateCurrValue(proto, values, locals); if (proto.lastInBinding) { + this._markPathAsCheckOnce(proto); return res; } else { this._writeSelf(proto, res, values); diff --git a/modules/angular2/test/core/linker/integration_spec.ts b/modules/angular2/test/core/linker/integration_spec.ts index fb0f8e73f3..eb00f4b5dd 100644 --- a/modules/angular2/test/core/linker/integration_spec.ts +++ b/modules/angular2/test/core/linker/integration_spec.ts @@ -755,30 +755,6 @@ function declareTests() { async.done(); })})); - if (DOM.supportsDOMEvents()) { - it("should allow to destroy a component from within a host event handler", - inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => { - - var fixture: ComponentFixture; - tcb.overrideView( - MyComp, new ViewMetadata({ - template: '', - directives: [[[PushCmpWithHostEvent]]] - })) - - .createAsync(MyComp) - .then(root => { fixture = root; }); - tick(); - fixture.detectChanges(); - - var cmpEl = fixture.debugElement.children[0]; - var cmp: PushCmpWithHostEvent = cmpEl.inject(PushCmpWithHostEvent); - cmp.ctxCallback = (_) => fixture.destroy(); - - expect(() => cmpEl.triggerEventHandler('click', {})).not.toThrow(); - }))); - } - it('should not affect updating properties on the component', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { @@ -1977,16 +1953,6 @@ class PushCmpWithRef { propagate() { this.ref.markForCheck(); } } -@Component({ - selector: 'push-cmp-with-host-event', - host: {'(click)': 'ctxCallback($event)'}, - changeDetection: ChangeDetectionStrategy.OnPush, - template: '' -}) -class PushCmpWithHostEvent { - ctxCallback: Function = (_) => {}; -} - @Component({ selector: 'push-cmp-with-async', changeDetection: ChangeDetectionStrategy.OnPush,