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

Handing asynchronous requests from stores #28

Closed
jhollingworth opened this issue Nov 20, 2014 · 2 comments
Closed

Handing asynchronous requests from stores #28

jhollingworth opened this issue Nov 20, 2014 · 2 comments

Comments

@jhollingworth
Copy link
Contributor

When you are getting something from a store, you must assume it will require an asynchronous operation to fetch the data (right now we are only concerned with HTTP requests). Currently if we don't have the data yet we send off an HTTP request and return null/undefined. This approach leaves a number of unanswered questions

  • How do you differentiate from the entity not being in the local cache and it not existing at all (e.g. 404/410)
  • How you know if there is already an HTTP request in progress which is trying to get the data?
  • How do you know if an HTTP request has failed?
  • How do you ensure all the stores are synchronised before returning the result of a asynchronous result?
  • If a views initial state is not available before the component is mounted, what should we render?
@jhollingworth
Copy link
Contributor Author

Some ideas

var FooCache = Marty.createCache({
  mixins: [Marty.HttpCache],
  getById: function (id) {
    return this.lock(id, function () {
      if (this.contains(id)) {
        return this.state[id];
      }

      return this.get('/foos/' + id)
    });
  }
});

var FooStore = Marty.createStore({
  mixins: [HttpCache],
  getFoos: function (id) {
    this.getById(id)
  }
});

var FooState = Marty.createStateMixin({
  getState: function () {
    return {
      // if any state values is promises, we wait for them to be resolved
      foo: FooStore.getFoo(id)
    };
  }
});

var FooView = Marty.createStateMixin({
  mixins: [FooState],
  render: function () {

  }
})

@rymohr
Copy link

rymohr commented Nov 24, 2014

I like where you're going with the PR #29

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