/// <summary> /// Checks if State modifications are allowed and writes a warning to the Trace log. /// </summary> /// <param name="atom">The observable to report.</param> internal static void CheckIfStateModificationsAreAllowed(this IAtom atom) { var sharedState = atom.SharedState; var configuration = sharedState.Configuration; // Should never be possible to change an observed observable from inside computed, see Mobx #798 if (sharedState.ComputationDepth > 0 && atom.HasObservers()) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.ComputedValuesAreNotAllowedToCauseSideEffects, atom.Name)); } // Should not be possible to change observed state outside strict mode, except during initialization, see Mobx #563 if (!sharedState.AllowStateChanges && sharedState.Configuration.EnforceActions != EnforceAction.Never && (atom.HasObservers() || sharedState.Configuration.EnforceActions == EnforceAction.Always)) { throw new InvalidOperationException(string.Format( CultureInfo.CurrentCulture, sharedState.Configuration.EnforceActions == EnforceAction.Always ? Resources.ModifiedOutsideActionEnforceAlways : Resources.ModifiedOutsideAction, atom.Name)); } }