Uh oh!
There was an error while loading. Please reload this page.
Add state new usage for following example. - #5
Conversation
Personal think following more intuitive for a declare statement like syntax. e.g. state :state_name, 'initial value' state :state_name, 'initial value', class: true
catmando
left a comment
There was a problem hiding this comment.
if you add some test cases you will see that this does not always work.
All these cases should work:
state:foo# will be initialized to nilstatefoo: 12# will be initialized to 12state:foo,12# will be initialized to 12 alsostatefoo: 12,scope: :classstate:foo,12,scope: :classstate:foo,{}# foo is initialized to nil, and there are no optionsstate:foo,{},{}# foo is initialized to {} and there are no optionsThe thing that makes it tricky is that the last 2 cases.
Advice is to write test cases now...
catmando
commented
Jul 25, 2017
Lets keep the discussion on this change here (rather than in the gitter chat) There is too much code out in the wild depending on the current structure to change it. Besides I think most dev's find the structure natural. Finally as far as initialization to nil, this is standard ruby. State variables are just like instance variables that cause rerendering when changed. Instance variables by default initialize to nil, and so do state variables. So I am fine with adding your syntax, but you are going to have to parse it so that both old and new style work. |
zw963
commented
Jul 25, 2017
@catmando , Thanks for reply. After read some post write by you in quora, and Comparing-Redux-with-Hyperloop, I think current usage not so unreasonable. Though I still hope add new state usage to project, But, as I say previous in gitter, current, state:one_hash_state,scope: class,reader: allstate:one_hash_state,{scope: class},scope: class# {scope: class} is state default value |
Personal think following more intuitive for a declare statement like syntax.
e.g.
state :state_name, 'initial value'
state :state_name, 'initial value', class: true