Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Fixes #51: in componentDidMount() wait for the promise in componentWi…
Browse files Browse the repository at this point in the history
…llMount() to complete before fetching deferred fragments.
  • Loading branch information
Rick committed Jan 14, 2016
1 parent 108dbca commit af89ba6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-transmit",
"description": "Relay-inspired library based on Promises instead of GraphQL.",
"version": "3.1.6",
"version": "3.1.7",
"license": "BSD-3-Clause",
"repository": {
"type": "git",
Expand Down Expand Up @@ -38,9 +38,9 @@
"react": "0.14.6",
"react-dom": "0.14.6",
"react-hot-loader": "1.3.0",
"react-inline-css": "2.0.1",
"webpack": "1.12.10",
"webpack-dev-server": "1.14.0"
"react-inline-css": "2.1.0",
"webpack": "1.12.11",
"webpack-dev-server": "1.14.1"
},
"engines": {
"node": ">=0.10.32"
Expand Down
22 changes: 14 additions & 8 deletions src/lib/createContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ module.exports = function (Component, options) {
var promise = Container.fragments[fragmentName](variables);

if (typeof promise === "function" && isRootContainer(Container)) {
return new promiseProxy.Promise(function (resolve, reject) {
resolve(promise);
});
return promiseProxy.Promise.resolve(promise);
}

return promise;
Expand Down Expand Up @@ -94,11 +92,16 @@ module.exports = function (Component, options) {
this._mounted = true;

if (isRootContainer(Container)) {
var deferredFragments = this.missingFragments(false);
var promise = this.fetching || Promise.resolve(null);
var _this = this;

if (deferredFragments.length) {
this.forceFetch({}, deferredFragments);
}
promise.then(function () {
var deferredFragments = _this.missingFragments(false);

if (deferredFragments.length) {
_this.forceFetch({}, deferredFragments);
}
});
}
},
componentWillUnmount: function () {
Expand Down Expand Up @@ -237,7 +240,10 @@ module.exports = function (Component, options) {
var missingFragments = this.missingFragments(true);

if (missingFragments.length) {
this.forceFetch({}, missingFragments, true);
var _this = this;
this.fetching = this.forceFetch({}, missingFragments, true).then(function () {
_this.fetching = false;
});
}
else {
this.callOnFetchHandler(promiseProxy.Promise.resolve({}));
Expand Down

0 comments on commit af89ba6

Please sign in to comment.