martyjs / marty

A Javascript library for state management in React applications
http://martyjs.org
MIT License
1.09k stars 76 forks source link

when's behaviour question #119

Closed dariocravero closed 9 years ago

dariocravero commented 9 years ago

Hi all,

We've been playing with when for a while and got thinking as to whether the wrapper could actually be removed when going to the view itself.

So instead of wrapping whatever my store's object is, just append a status field to it of some kind. I'm sure there are some reasons why it's done this way. However I wanted to see if anybody else thought about it as well and if it would make sense to return an unwrapped object rather than a wrapped one.

Thanks :)

jhollingworth commented 9 years ago

not sure I follow. when is just a convenience function so you don't have to do this

var user = UserStore.getUser(123);

if (user.status === "pending") {
  console.log('waiting for user');
}

if (user.status === "error") {
  console.log('failed to get user', user.error);
}

if (user.status === "done") {
  console.log(user.result);
}

We've found its really handy when you're render function needs to handle the various states