{"action":"created","issue":{"url":"https://api.github.com/repos/reactrb/reactrb/issues/24","repository_url":"https://api.github.com/repos/reactrb/reactrb","labels_url":"https://api.github.com/repos/reactrb/reactrb/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/reactrb/reactrb/issues/24/comments","events_url":"https://api.github.com/repos/reactrb/reactrb/issues/24/events","html_url":"https://github.com/reactrb/reactrb/issues/24","id":159710868,"number":24,"title":"Need a way to deal with objects changing state (i.e. arrays)","user":{"login":"sollycatprint","id":8051004,"avatar_url":"https://avatars.githubusercontent.com/u/8051004?v=3","gravatar_id":"","url":"https://api.github.com/users/sollycatprint","html_url":"https://github.com/sollycatprint","followers_url":"https://api.github.com/users/sollycatprint/followers","following_url":"https://api.github.com/users/sollycatprint/following{/other_user}","gists_url":"https://api.github.com/users/sollycatprint/gists{/gist_id}","starred_url":"https://api.github.com/users/sollycatprint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sollycatprint/subscriptions","organizations_url":"https://api.github.com/users/sollycatprint/orgs","repos_url":"https://api.github.com/users/sollycatprint/repos","events_url":"https://api.github.com/users/sollycatprint/events{/privacy}","received_events_url":"https://api.github.com/users/sollycatprint/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-10T19:58:52Z","updated_at":"2016-06-10T19:58:53Z","closed_at":null,"body":"_From @catmando on May 3, 2015 4:5_\n\nFor example\r\n\r\n```ruby\r\ndefine_state(:foo) { ['joe', 'fred'] }\r\n\r\ndef add_friend(friend) \r\n  foo << friend\r\nend\r\n```\r\n\r\nThis does not work as `foo << friend` updates the array object, but there is no way to know that the foo state has been updated.\r\n\r\nI have implemented a couple of solutions, and am interested in which people would prefer:\r\n\r\n1) define foo! method that will return an object that wrap the current value of foo, and observe any changes to that object.   So you can write\r\n\r\n```ruby\r\ndef add_friend(friend)\r\n  foo! << friend\r\nend\r\n```\r\n\r\n2) define foo! method that simple does `foo = foo` to indicate a state change.  This would return self so that the methods could be chained\r\n\r\n```ruby\r\ndef add_friend(friend)\r\n  foo << friend; foo!\r\nend\r\n```\r\n\r\nor\r\n\r\n```ruby\r\ndef add_friend(friend)\r\n  foo << friend\r\nensure\r\n  foo!.bar!\r\nend\r\n```\r\n\r\n2b) In addition the Proc class can be updated so this works\r\n\r\n```ruby\r\nlambda { |new_friend| foo << new_friend }.foo! \r\n```\r\n\r\nJust looking for people's input, preferences, or other ideas!\r\n\r\n\n\n_Copied from original issue: zetachang/react.rb#24_"},"comment":{"url":"https://api.github.com/repos/reactrb/reactrb/issues/comments/225280684","html_url":"https://github.com/reactrb/reactrb/issues/24#issuecomment-225280684","issue_url":"https://api.github.com/repos/reactrb/reactrb/issues/24","id":225280684,"user":{"login":"sollycatprint","id":8051004,"avatar_url":"https://avatars.githubusercontent.com/u/8051004?v=3","gravatar_id":"","url":"https://api.github.com/users/sollycatprint","html_url":"https://github.com/sollycatprint","followers_url":"https://api.github.com/users/sollycatprint/followers","following_url":"https://api.github.com/users/sollycatprint/following{/other_user}","gists_url":"https://api.github.com/users/sollycatprint/gists{/gist_id}","starred_url":"https://api.github.com/users/sollycatprint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sollycatprint/subscriptions","organizations_url":"https://api.github.com/users/sollycatprint/orgs","repos_url":"https://api.github.com/users/sollycatprint/repos","events_url":"https://api.github.com/users/sollycatprint/events{/privacy}","received_events_url":"https://api.github.com/users/sollycatprint/received_events","type":"User","site_admin":false},"created_at":"2016-06-10T19:58:53Z","updated_at":"2016-06-10T19:58:53Z","body":"_From @zetachang on May 3, 2015 5:56_\n\nThanks for pointing this out, I think this could be a common mistake given that the original `setState` is wrapped inside the setter.\r\n\r\nCurrently, you can write as below, \r\n```ruby\r\ndef add_friend(friend)\r\n  self.foo = foo << friend; self\r\nend\r\n```\r\n\r\nTo get the benefit of brevity and also make it chainable. "}}
{"actor":{"display_login":"sollycatprint"}}