{"action":"created","issue":{"url":"https://api.github.com/repos/arqex/freezer/issues/35","labels_url":"https://api.github.com/repos/arqex/freezer/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/arqex/freezer/issues/35/comments","events_url":"https://api.github.com/repos/arqex/freezer/issues/35/events","html_url":"https://github.com/arqex/freezer/issues/35","id":73266696,"number":35,"title":"Best way to set multiple fields","user":{"login":"aptheod","id":6471299,"avatar_url":"https://avatars.githubusercontent.com/u/6471299?v=3","gravatar_id":"","url":"https://api.github.com/users/aptheod","html_url":"https://github.com/aptheod","followers_url":"https://api.github.com/users/aptheod/followers","following_url":"https://api.github.com/users/aptheod/following{/other_user}","gists_url":"https://api.github.com/users/aptheod/gists{/gist_id}","starred_url":"https://api.github.com/users/aptheod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aptheod/subscriptions","organizations_url":"https://api.github.com/users/aptheod/orgs","repos_url":"https://api.github.com/users/aptheod/repos","events_url":"https://api.github.com/users/aptheod/events{/privacy}","received_events_url":"https://api.github.com/users/aptheod/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-05T09:58:44Z","updated_at":"2015-05-05T11:47:40Z","closed_at":null,"body":"Suppose i have two classes. On the first i set the frozen data...\r\n\r\n```js\r\nvar dataStore = new Freezer({\r\ndata: { \r\narray_1: [],\r\nint_value: 0,\r\narray_2: [],\r\nbool_value: false\r\n}\r\n});\r\n```\r\n\r\n..and pass the `dataStore.get().data` as parameter on the constructor of the second one, on variable `this.data`. Now i want to assign some values to these fields. What's the best way to do it?\r\n\r\n```js\r\nthis.data = this.data.set({int_value: 5});\r\nthis.data = this.data.set({array_2: [1,2 ,3]});\r\nthis.data = this.data.array_1.append( [4, ,5 ,6] ); \r\n```\r\nThis way is working, since i don't have get() available, i have to assign to itself on every set. Is that correct?\r\n\r\nthanks "},"comment":{"url":"https://api.github.com/repos/arqex/freezer/issues/comments/99056095","html_url":"https://github.com/arqex/freezer/issues/35#issuecomment-99056095","issue_url":"https://api.github.com/repos/arqex/freezer/issues/35","id":99056095,"user":{"login":"arqex","id":6509397,"avatar_url":"https://avatars.githubusercontent.com/u/6509397?v=3","gravatar_id":"","url":"https://api.github.com/users/arqex","html_url":"https://github.com/arqex","followers_url":"https://api.github.com/users/arqex/followers","following_url":"https://api.github.com/users/arqex/following{/other_user}","gists_url":"https://api.github.com/users/arqex/gists{/gist_id}","starred_url":"https://api.github.com/users/arqex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arqex/subscriptions","organizations_url":"https://api.github.com/users/arqex/orgs","repos_url":"https://api.github.com/users/arqex/repos","events_url":"https://api.github.com/users/arqex/events{/privacy}","received_events_url":"https://api.github.com/users/arqex/received_events","type":"User","site_admin":false},"created_at":"2015-05-05T11:47:40Z","updated_at":"2015-05-05T11:47:40Z","body":"Hi @aptheod \r\n\r\nI would do something like \r\n\r\n```js\r\nvar data = this.data.set({ int_value: 5, array_2: [1,2,3] })\r\n  .array_1.append( [4,5,6] )\r\n;\r\n```\r\n\r\nBut be aware of the `data` object returned, it will have the updated `array_1` node, instead of the `data` one, because the last operation is made on `this.data.array_1`.\r\n\r\nIf you don't have access to the `get()` method to restore the data object, your best option is use transactions\r\n\r\n```js\r\nvar dataStore = new Freezer({\r\n  data: { \r\n    array_1: [],\r\n    int_value: 0,\r\n    array_2: [],\r\n    bool_value: false  \r\n  }\r\n});\r\n\r\nvar data = dataStore.get().data,\r\n    trans = data.transact()\r\n;\r\n\r\n// trans is a mutable representation of data\r\n// that holds all the changes in its children\r\ntrans.int_value = 5;\r\ntrans.array_2.reset([1,2,3]);\r\ntrans.array_2.append([4,5,6]);\r\n\r\n// Run transaction\r\ndata = data.run();\r\n\r\nconsole.log( data );\r\nconsole.log( dataStore.get().data );\r\n```\r\nhttp://jsbin.com/noqikokiqa/2/edit\r\n"}}