Skip to content
This repository has been archived by the owner on Oct 19, 2018. It is now read-only.

Add state new usage for following example. #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zw963
Copy link

@zw963 zw963 commented Jul 19, 2017

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

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
Copy link
Contributor

@catmando catmando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 nil
  state foo: 12 # will be initialized to 12
  state :foo, 12 # will be initialized to 12 also
  state foo: 12, scope: :class
  state :foo, 12, scope: :class
  state :foo, {} # foo is initialized to nil, and there are no options
  state :foo, {}, {} # foo is initialized to {} and there are no options

The thing that makes it tricky is that the last 2 cases.

Advice is to write test cases now...

@catmando
Copy link
Contributor

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
Copy link
Author

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,
If I If i did not make a mistake, it seem like we have no idea to distinguish following usage,
right?

state :one_hash_state, scope: class, reader: all
state :one_hash_state, {scope: class}, scope: class   # {scope: class} is state default value

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants