{"action":"created","issue":{"url":"https://api.github.com/repos/zetachang/react.rb/issues/24","labels_url":"https://api.github.com/repos/zetachang/react.rb/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/zetachang/react.rb/issues/24/comments","events_url":"https://api.github.com/repos/zetachang/react.rb/issues/24/events","html_url":"https://github.com/zetachang/react.rb/issues/24","id":72743900,"number":24,"title":"Need a way to deal with objects changing state (i.e. arrays)","user":{"login":"catmando","id":63146,"avatar_url":"https://avatars.githubusercontent.com/u/63146?v=3","gravatar_id":"","url":"https://api.github.com/users/catmando","html_url":"https://github.com/catmando","followers_url":"https://api.github.com/users/catmando/followers","following_url":"https://api.github.com/users/catmando/following{/other_user}","gists_url":"https://api.github.com/users/catmando/gists{/gist_id}","starred_url":"https://api.github.com/users/catmando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/catmando/subscriptions","organizations_url":"https://api.github.com/users/catmando/orgs","repos_url":"https://api.github.com/users/catmando/repos","events_url":"https://api.github.com/users/catmando/events{/privacy}","received_events_url":"https://api.github.com/users/catmando/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-05-03T04:05:01Z","updated_at":"2015-05-08T07:03:02Z","closed_at":null,"body":"For 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"},"comment":{"url":"https://api.github.com/repos/zetachang/react.rb/issues/comments/100128274","html_url":"https://github.com/zetachang/react.rb/issues/24#issuecomment-100128274","issue_url":"https://api.github.com/repos/zetachang/react.rb/issues/24","id":100128274,"user":{"login":"zetachang","id":839973,"avatar_url":"https://avatars.githubusercontent.com/u/839973?v=3","gravatar_id":"","url":"https://api.github.com/users/zetachang","html_url":"https://github.com/zetachang","followers_url":"https://api.github.com/users/zetachang/followers","following_url":"https://api.github.com/users/zetachang/following{/other_user}","gists_url":"https://api.github.com/users/zetachang/gists{/gist_id}","starred_url":"https://api.github.com/users/zetachang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zetachang/subscriptions","organizations_url":"https://api.github.com/users/zetachang/orgs","repos_url":"https://api.github.com/users/zetachang/repos","events_url":"https://api.github.com/users/zetachang/events{/privacy}","received_events_url":"https://api.github.com/users/zetachang/received_events","type":"User","site_admin":false},"created_at":"2015-05-08T07:03:02Z","updated_at":"2015-05-08T07:03:02Z","body":"Hey, thanks for taking time making this suggestion. \r\n\r\n> or if no parameter is provided then foo! returns an object that will update after any method calls on foo. \r\n\r\nHow is this going to be implemented? A wrapper object which will delegate all method invocations? \r\n\r\n> In addition I added two class methods require_param and optional_param that will declare a validated parameter. The difference is these methods will also create methods that can read the parameters directly.\r\n\r\nWe currently got a `params` class methods, it becomes complicated for me to choose which one to use if another `require_params`, `optional_params` is introduced. So maybe add a new parameter, that's say `accessor: true`. So you can write like this,\r\n\r\n```ruby\r\nparams do\r\n    requires :foo, type: Proc, accessor: true\r\nend\r\n```\r\n\r\n> Finally if the type of parameter is Proc then the created method will call the proc. \r\n\r\nThis is actually quite neat,  :+1:  on this.\r\n\r\n> You can say class MyComponent < React::Component::Base instead of including React::Component\r\n\r\nWould you mind elaborating more on why having a base class rather than current module approach? The initial design decision made is to allow every Ruby class got render defined could be valid component. `React::Component` only provide helper methods. And there is a lot of refactoring work for `React::Component` on #17 , so I will suggest postponing this until it's done.\r\n\r\n> And any class that responds to 'render' can be used in the rendering dsl.\r\n\r\n:+1:  on this.\r\n\r\n\r\nLast but not least, would you mind open separate pull requests for these features? Thus we can review and merge them faster. :smiley: \r\n\r\n\r\n"}}