Skip to content

Commit

Permalink
refactor(ngdart)!: migrate ChangeDetectorState to enum
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Zhao <[email protected]>
  • Loading branch information
GZGavinZhao committed Mar 6, 2023
1 parent f4e719b commit 598cae2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
14 changes: 7 additions & 7 deletions ngdart/lib/src/core/linker/views/component_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ abstract class ComponentView<T extends Object> extends RenderView {

@override
bool get firstCheck =>
_data.changeDetectorState == ChangeDetectorState.NeverChecked;
_data.changeDetectorState == ChangeDetectorState.neverChecked;

@override
void detectChangesDeprecated() {
Expand Down Expand Up @@ -164,7 +164,7 @@ abstract class ComponentView<T extends Object> extends RenderView {
}

// Set the state to already checked at least once.
_data.changeDetectorState = ChangeDetectorState.CheckedBefore;
_data.changeDetectorState = ChangeDetectorState.checkedBefore;
}

/// Generated code that is called by hosts.
Expand All @@ -174,7 +174,7 @@ abstract class ComponentView<T extends Object> extends RenderView {

@override
void disableChangeDetection() {
_data.changeDetectorState = ChangeDetectorState.Errored;
_data.changeDetectorState = ChangeDetectorState.errored;
}

/// Marks this view to be checked during change detection.
Expand Down Expand Up @@ -281,9 +281,9 @@ class _ComponentViewData implements RenderViewData {
}

@override
int get changeDetectorState => _changeDetectorState;
int _changeDetectorState = ChangeDetectorState.NeverChecked;
set changeDetectorState(int state) {
ChangeDetectorState get changeDetectorState => _changeDetectorState;
ChangeDetectorState _changeDetectorState = ChangeDetectorState.neverChecked;
set changeDetectorState(ChangeDetectorState state) {
if (_changeDetectorState != state) {
_changeDetectorState = state;
_updateShouldSkipChangeDetection();
Expand Down Expand Up @@ -313,6 +313,6 @@ class _ComponentViewData implements RenderViewData {
_shouldSkipChangeDetection =
_changeDetectionMode == ChangeDetectionStrategy.Checked ||
_changeDetectionMode == ChangeDetectionStrategy.Detached ||
_changeDetectorState == ChangeDetectorState.Errored;
_changeDetectorState == ChangeDetectorState.errored;
}
}
14 changes: 7 additions & 7 deletions ngdart/lib/src/core/linker/views/embedded_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ abstract class EmbeddedView<T> extends RenderView

@override
bool get firstCheck =>
_data.changeDetectorState == ChangeDetectorState.NeverChecked;
_data.changeDetectorState == ChangeDetectorState.neverChecked;

@override
void detectChangesDeprecated() {
Expand All @@ -148,12 +148,12 @@ abstract class EmbeddedView<T> extends RenderView
}

// Set the state to already checked at least once.
_data.changeDetectorState = ChangeDetectorState.CheckedBefore;
_data.changeDetectorState = ChangeDetectorState.checkedBefore;
}

@override
void disableChangeDetection() {
_data.changeDetectorState = ChangeDetectorState.Errored;
_data.changeDetectorState = ChangeDetectorState.errored;
}

@override
Expand Down Expand Up @@ -274,9 +274,9 @@ class _EmbeddedViewData<T> implements DynamicViewData, RenderViewData {
}

@override
int get changeDetectorState => _changeDetectorState;
int _changeDetectorState = ChangeDetectorState.NeverChecked;
set changeDetectorState(int state) {
ChangeDetectorState get changeDetectorState => _changeDetectorState;
ChangeDetectorState _changeDetectorState = ChangeDetectorState.neverChecked;
set changeDetectorState(ChangeDetectorState state) {
if (_changeDetectorState != state) {
_changeDetectorState = state;
_updateShouldSkipChangeDetection();
Expand Down Expand Up @@ -316,6 +316,6 @@ class _EmbeddedViewData<T> implements DynamicViewData, RenderViewData {
void _updateShouldSkipChangeDetection() {
_shouldSkipChangeDetection =
_changeDetectionMode == ChangeDetectionStrategy.Detached ||
_changeDetectorState == ChangeDetectorState.Errored;
_changeDetectorState == ChangeDetectorState.errored;
}
}
14 changes: 7 additions & 7 deletions ngdart/lib/src/core/linker/views/host_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abstract class HostView<T extends Object> extends View implements DynamicView {
// TODO(b/132122866): this could just return `componentView.firstCheck`.
@override
bool get firstCheck =>
_data.changeDetectorState == ChangeDetectorState.NeverChecked;
_data.changeDetectorState == ChangeDetectorState.neverChecked;

@override
int? get parentIndex => null;
Expand Down Expand Up @@ -148,7 +148,7 @@ abstract class HostView<T extends Object> extends View implements DynamicView {
}

// Set the state to already checked at least once.
_data.changeDetectorState = ChangeDetectorState.CheckedBefore;
_data.changeDetectorState = ChangeDetectorState.checkedBefore;
}

@override
Expand Down Expand Up @@ -184,7 +184,7 @@ abstract class HostView<T extends Object> extends View implements DynamicView {

@override
void disableChangeDetection() {
_data.changeDetectorState = ChangeDetectorState.Errored;
_data.changeDetectorState = ChangeDetectorState.errored;
}

@override
Expand Down Expand Up @@ -267,9 +267,9 @@ class _HostViewData implements DynamicViewData {
}

@override
int get changeDetectorState => _changeDetectorState;
int _changeDetectorState = ChangeDetectorState.NeverChecked;
set changeDetectorState(int state) {
ChangeDetectorState get changeDetectorState => _changeDetectorState;
ChangeDetectorState _changeDetectorState = ChangeDetectorState.neverChecked;
set changeDetectorState(ChangeDetectorState state) {
if (_changeDetectorState != state) {
_changeDetectorState = state;
_updateShouldSkipChangeDetection();
Expand Down Expand Up @@ -304,6 +304,6 @@ class _HostViewData implements DynamicViewData {
void _updateShouldSkipChangeDetection() {
_shouldSkipChangeDetection =
_changeDetectionMode == ChangeDetectionStrategy.Detached ||
_changeDetectorState == ChangeDetectorState.Errored;
_changeDetectorState == ChangeDetectorState.errored;
}
}
4 changes: 2 additions & 2 deletions ngdart/lib/src/core/linker/views/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:html' show Element;

import 'package:meta/dart2js.dart' as dart2js;
import 'package:meta/meta.dart';
import 'package:ngdart/src/core/change_detection/change_detector_ref.dart';
import 'package:ngdart/src/core/change_detection/change_detection.dart';
import 'package:ngdart/src/core/change_detection/host.dart';
import 'package:ngdart/src/di/errors.dart';
import 'package:ngdart/src/di/injector.dart';
Expand Down Expand Up @@ -250,7 +250,7 @@ abstract class ViewData {

/// Tracks this view's [ChangeDetectorState].
// TODO(b/132122866): host views only need an error bit.
int get changeDetectorState;
ChangeDetectorState get changeDetectorState;

/// Whether this view has been destroyed.
bool get destroyed;
Expand Down
14 changes: 7 additions & 7 deletions ngdart/lib/src/meta/change_detection_constants.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/// Describes the current state of the change detector.
class ChangeDetectorState {
/// [NeverChecked] means that the change detector has not been checked yet,
enum ChangeDetectorState {
/// [neverChecked] means that the change detector has not been checked yet,
/// and initialization methods should be called during detection.
static const int NeverChecked = 0;
neverChecked,

/// [CheckedBefore] means that the change detector has successfully completed
/// [checkedBefore] means that the change detector has successfully completed
/// at least one detection previously.
static const int CheckedBefore = 1;
checkedBefore,

/// [Errored] means that the change detector encountered an error checking a
/// [errored] means that the change detector encountered an error checking a
/// binding or calling a directive lifecycle method and is now in an
/// inconsistent state. Change detectors in this state will no longer detect
/// changes.
static const int Errored = 2;
errored,
}

/// Describes within the change detector which strategy will be used the next
Expand Down

0 comments on commit 598cae2

Please sign in to comment.