Skip to content

Commit

Permalink
Code legibility improvement (#769)
Browse files Browse the repository at this point in the history
Moved the declaration from the variable subscribe above the declaration
of the var unsubscribe
  • Loading branch information
rodrijuarez authored and gigabo committed Nov 28, 2016
1 parent ca859de commit ae2bc1b
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions packages/react-server/core/components/RootElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,27 @@ RootElement.ensureRootElement = function(element){
}

RootElement.installListener = function(element, listen) {
var dfd = Q.defer();
var updater;
var unsubscribe = listen(childProps => {

// Once the component has mounted it will provide an updater.
// After that we can just short-circuit here and let it handle
// updating itself.
if (updater) {
updater(childProps);
}

// The promise itself will only resolve once, but we don't
// want to _clone_ multiple times.
else if (dfd.promise.isPending()) {
dfd.resolve(React.cloneElement(element, {
childProps,
subscribe,
unsubscribe,
}));
}
});
var subscribe = callback => {updater = callback};
var dfd = Q.defer(),
updater,
subscribe = callback => {updater = callback},
unsubscribe = listen(childProps => {
// Once the component has mounted it will provide an updater.
// After that we can just short-circuit here and let it handle
// updating itself.
if (updater) {
updater(childProps);
}

// The promise itself will only resolve once, but we don't
// want to _clone_ multiple times.
else if (dfd.promise.isPending()) {
dfd.resolve(React.cloneElement(element, {
childProps,
subscribe,
unsubscribe,
}));
}
});
return dfd.promise
}

Expand Down

0 comments on commit ae2bc1b

Please sign in to comment.