@@ -16,6 +16,7 @@ library over_react.component_declaration.component_base;
1616
1717import 'dart:async' ;
1818import 'dart:collection' ;
19+ import 'dart:html' ;
1920
2021import 'package:meta/meta.dart' ;
2122import 'package:over_react/over_react.dart' ;
@@ -247,7 +248,7 @@ abstract class UiComponent<TProps extends UiProps> extends react.Component imple
247248 var unwrappedProps = this .unwrappedProps;
248249 var typedProps = _typedPropsCache[unwrappedProps];
249250 if (typedProps == null ) {
250- typedProps = typedPropsFactory (unwrappedProps);
251+ typedProps = typedPropsFactory (inReactDevMode ? new _WarnOnModify (unwrappedProps, true ) : unwrappedProps);
251252 _typedPropsCache[unwrappedProps] = typedProps;
252253 }
253254 return typedProps;
@@ -417,7 +418,7 @@ abstract class UiStatefulComponent<TProps extends UiProps, TState extends UiStat
417418 var unwrappedState = this .unwrappedState;
418419 var typedState = _typedStateCache[unwrappedState];
419420 if (typedState == null ) {
420- typedState = typedStateFactory (unwrappedState);
421+ typedState = typedStateFactory (inReactDevMode ? new _WarnOnModify (unwrappedState, false ) : unwrappedState);
421422 _typedStateCache[unwrappedState] = typedState;
422423 }
423424 return typedState;
@@ -446,6 +447,37 @@ abstract class UiStatefulComponent<TProps extends UiProps, TState extends UiStat
446447 // ----------------------------------------------------------------------
447448}
448449
450+ class _WarnOnModify <K , V > extends MapView <K , V > {
451+ //Used to customize warning based on whether the data is props or state
452+ bool isProps;
453+
454+ String message;
455+
456+ _WarnOnModify (Map componentData, this .isProps): super (componentData);
457+
458+ @override
459+ operator []= (K key, V value) {
460+ if (isProps) {
461+ message =
462+ '''
463+ props["$key "] was updated incorrectly. Never mutate this.props directly, as it can cause unexpected behavior;
464+ props must be updated only by passing in new values when re-rendering this component.
465+
466+ This will throw in UiComponentV2 (to be released as part of the React 16 upgrade).
467+ ''' ;
468+ } else {
469+ message =
470+ '''
471+ state["$key "] was updated incorrectly. Never mutate this.state directly, as it can cause unexpected behavior;
472+ state must be updated only via setState.
473+
474+ This will throw in UiComponentV2 (to be released as part of the React 16 upgrade).
475+ ''' ;
476+ }
477+ super [key] = value;
478+ ValidationUtil .warn (unindent (message));
479+ }
480+ }
449481
450482/// A `dart.collection.MapView` -like class with strongly-typed getters/setters for React state.
451483///
0 commit comments