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 #180

Merged
merged 4 commits into from Mar 8, 2015
Merged

FetchResult#toPromise #180

merged 4 commits into from Mar 8, 2015

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 jhollingworth mentioned this pull request Mar 8, 2015
4 tasks
jhollingworth added a commit that referenced this pull request Mar 8, 2015
@jhollingworth jhollingworth merged commit 2ef0896 into v0.9 Mar 8, 2015
@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.

None yet

1 participant