Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State should be able to be an array #23

Closed
timwis opened this issue May 27, 2016 · 7 comments
Closed

State should be able to be an array #23

timwis opened this issue May 27, 2016 · 7 comments

Comments

@timwis
Copy link
Member

timwis commented May 27, 2016

I have a "tables" model that's a collection of tables. I would expect to be able to set my state property to an array within the tables namespace and the resulting global state look like: { app: {}, tables: [] } as it would in redux. Instead, if you set the state to an empty array, it's not included in the global state. If you set it to an array with a value, it gets set to {tables: {0: 'that value'}}.

Not a big deal, just thought I'd point it out. At first glance I imagine it could be an issue with apply or xtend.

@yoshuawuyts
Copy link
Member

yoshuawuyts commented May 27, 2016

Hmm, I think this ties further into whether or not non-objects should be supported at the top level. If you're not using namespaces it should diff just fine. We could probably detect if an obj

Just to verify, what you're trying to achieve is:

app.model({
  namespace: 'tables',
  state: [],
  reducers: { /* things go here */}
})

Given the approach I'm proposing, this should be possible too:

app.model({
  namespace: 'something',
  state: 'foobar',
  reducers: {
    update: (state, action) => state + 'bar'  // 'foobarbar'
  }
})

does this make sense?

edit: fixed typo as per comment below

@timwis
Copy link
Member Author

timwis commented May 28, 2016

That's right. Of course state is the property name rather than model but yes

@yoshuawuyts
Copy link
Member

hah, you're right - derp. Fixed!

@yoshuawuyts
Copy link
Member

I reckon this should land in 3.1 not 3.0; wanna narrow down the scope a lil and have barracks at 100% coverage before adding big changes to the merging algorithm

@yoshuawuyts
Copy link
Member

Hmmm, I think arrays should perhaps be the only ones that can exist in the top level scope too; adding all other types throws us down JS type equality hell, which def isn't where we want to be.

@yoshuawuyts
Copy link
Member

yeah feel like this might be the solution to models troubles (: - well, if we add some docs and patterns too - selectors feel like v. useful - probs if we add plugins too we could do some amaze things C:

@yoshuawuyts
Copy link
Member

Closing because choo@5 will introduce a new API. See #425 for the merged PR. Thanks!

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

No branches or pull requests

2 participants