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

FetchResult#toPromise #132

Closed
wants to merge 128 commits into from
Closed

FetchResult#toPromise #132

wants to merge 128 commits into from

Conversation

jhollingworth
Copy link
Contributor

For cases when you want to consume a fetch result outside of a component we want to be able to transform a FetchResult into a promise. FetchResults know their Id and what store they came from but stores won't tell us when a fetch changes (only when the store state changes). To get around this I suggest we add Store#addFetchChangedListener() which calls any listeners just before a fetch result is returned.

var fetch = require('marty/fetch');
fetch.done({foo: 'bar'}).toPromise().then(function (result) {
  console.log('resolved immediately', result); 
})

fetch.failed(new Error()).toPromise().catch(function (error) {
  console.log('failed immediately', error);
})

fetch.pending().toPromise().then(function () {
  console.log('this wont result'); 
})

Resolves #131

To do

  • Add Store#addFetchChangedListener()
  • toPromise should still work if we don't pass in an Id/store
  • Tests
  • Docs

@jhollingworth
Copy link
Contributor Author

You can't change the branch a PR merges into so moving this to #180

@jhollingworth jhollingworth deleted the when-promise branch March 8, 2015 12:13
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

Successfully merging this pull request may close these issues.

Fetch object and async operations
3 participants