reportChanged() shouldn't be able to be called on an atom outside of an action in strict mode
Intended outcome:
Calling atom.reportChanged() outside of an action should fail when enforceActions is set to 'observed' or 'always'. This is because atom.reportChanged() indicates that some state has changed.
Actual outcome:
It passes just fine and no errors are raised.
How to reproduce the issue:
I would expect this to fail: https://codesandbox.io/s/romantic-flower-s22i6r?file=/index.js (though I can't even get https://codesandbox.io/s/relaxed-spence-bfhlfu?file=/index.js to fail so maybe I haven't set this test case up correctly).
Looking through the code, it doesn't appear that checkIfStateModificationsAreAllowed is called within atom.reportChanged() which I would expect it to be.
Versions
We're using mobx 6 but I believe this affects all versions.
IIRC there was a kinda stupid reason for that - the reportChanged is supposed to be called after the value changed, but the check was supposed to prevent the write operation, so it had to run before the change. Therefore the reportChanged would have to be somehow able to intercept the write operation (eg reportChanged(() => { this.value = value })).
Since it no longer throws, but only warns, this is probably not an issue now and the check can be part of reportChanged.
There may be some issues with structures that modifies multiple observables as part of a single operation (like Map) - eg we probably don't want to warn for every individual atom etc, but I think this can be worked around.
To handle similar complex cases in user land, we might need to expose allowStateChanges[Start|End] to public (or rather document it as it's already exported for libs), not sure. And probably even checkIfStateModificationsAreAllowed (that would be another way to support enforceActions for custom atoms).
Would it be a BC? Existing code might start to warn, but strictly speaking it should (?) have warned before...