{"action":"created","issue":{"url":"https://api.github.com/repos/mobxjs/mobx/issues/940","repository_url":"https://api.github.com/repos/mobxjs/mobx","labels_url":"https://api.github.com/repos/mobxjs/mobx/issues/940/labels{/name}","comments_url":"https://api.github.com/repos/mobxjs/mobx/issues/940/comments","events_url":"https://api.github.com/repos/mobxjs/mobx/issues/940/events","html_url":"https://github.com/mobxjs/mobx/issues/940","id":220527908,"number":940,"title":"observable map modifications outside action do not rise errors with useStrict","user":{"login":"fedorl","id":6994311,"avatar_url":"https://avatars0.githubusercontent.com/u/6994311?v=3","gravatar_id":"","url":"https://api.github.com/users/fedorl","html_url":"https://github.com/fedorl","followers_url":"https://api.github.com/users/fedorl/followers","following_url":"https://api.github.com/users/fedorl/following{/other_user}","gists_url":"https://api.github.com/users/fedorl/gists{/gist_id}","starred_url":"https://api.github.com/users/fedorl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fedorl/subscriptions","organizations_url":"https://api.github.com/users/fedorl/orgs","repos_url":"https://api.github.com/users/fedorl/repos","events_url":"https://api.github.com/users/fedorl/events{/privacy}","received_events_url":"https://api.github.com/users/fedorl/received_events","type":"User","site_admin":false},"labels":[{"id":187164033,"url":"https://api.github.com/repos/mobxjs/mobx/labels/bug","name":"bug","color":"fc2929","default":true},{"id":472349456,"url":"https://api.github.com/repos/mobxjs/mobx/labels/ready-to-be-implemented-by-volunteer","name":"ready-to-be-implemented-by-volunteer","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-04-10T03:20:29Z","updated_at":"2017-06-23T22:42:41Z","closed_at":null,"body":"`map.set(existingKey, x)` in the strict mode outside an action fails as expected with `Invariant failed`, requiring an action context.\r\n\r\nHowever, map.set(nonExistentKey, x) as well as other modifying operations e.g.  map.delete(), map.clear() silently run without any error even when no action is present. \r\n\r\n**Any** operation that modifies anything in the observable map state outside of an action must fail; the same way as an existing key replacement and the same way as ObservableArray.clear() or ObservableArray.push().\r\n\r\nCurrent behavior is not consistent and loses the value of useStrict for maps, because one can't rely on it anymore. Consider two equivalent operations `set(key, v); set(key, v)` and `set(key);delete(key);set(key); ` which have now completely different outcome, one will fail and one will work outside of an action. \r\n\r\nNot only does it allow uncontrolled state mutations, it does it in an unpredictable way depending on other mutations and their order. \r\n\r\n`\r\nclass PropTest {\r\n  @observable propMap = observable.map();\r\n}\r\n\r\nconst key = 'testKey';\r\nautorun((r) => {\r\n   const val = propTest.propMap.get(key);\r\n   console.info('------> ' + val);\r\n});\r\n\r\npropTest.propMap.set(key, 1);\r\npropTest.propMap.set(key, 2); // -> Invariant failed as expected\r\n\r\n//below runs fine which is not what one would expect in strict mode\r\npropTest.propMap.set(key, 1);\r\npropTest.propMap.delete(key);\r\npropTest.propMap.set(key, 2);\r\npropTest.propMap.clear();\r\n`\r\n\r\nIf there are implementation difficulties, this limitation should be reflected in documentation, as this inconsistency seems to be an alarming issue.\r\n"},"comment":{"url":"https://api.github.com/repos/mobxjs/mobx/issues/comments/310788586","html_url":"https://github.com/mobxjs/mobx/issues/940#issuecomment-310788586","issue_url":"https://api.github.com/repos/mobxjs/mobx/issues/940","id":310788586,"user":{"login":"roperzh","id":4419992,"avatar_url":"https://avatars3.githubusercontent.com/u/4419992?v=3","gravatar_id":"","url":"https://api.github.com/users/roperzh","html_url":"https://github.com/roperzh","followers_url":"https://api.github.com/users/roperzh/followers","following_url":"https://api.github.com/users/roperzh/following{/other_user}","gists_url":"https://api.github.com/users/roperzh/gists{/gist_id}","starred_url":"https://api.github.com/users/roperzh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roperzh/subscriptions","organizations_url":"https://api.github.com/users/roperzh/orgs","repos_url":"https://api.github.com/users/roperzh/repos","events_url":"https://api.github.com/users/roperzh/events{/privacy}","received_events_url":"https://api.github.com/users/roperzh/received_events","type":"User","site_admin":false},"created_at":"2017-06-23T22:42:41Z","updated_at":"2017-06-23T22:42:41Z","body":"Hey @mweststrate , sorry to bother! I've been looking at this and I wanted to ask before proceeding. \r\n\r\nSince `checkIfStateModificationsAreAllowed` expects an `Atom` as an argument, should we instantiate a new `Atom` when the map is created? I'm thinking in something in the lines of [`ObservableArray`](https://github.com/mobxjs/mobx/blob/master/src/types/observablearray.ts#L102).\r\n\r\nThank you!"}}
{"actor":{"display_login":"roperzh"}}