Skip to content

Commit

Permalink
Rehydrate based on resolution keys
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdustan committed Apr 22, 2015
1 parent 5f0efec commit ae54d7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ export default class Resolver {
throw new ReferenceError(`${container.constructor.displayName} should have an ID`);
}

const state = this.states.hasOwnProperty(id) ? this.states[id] : {
fulfilled: false,
rejected: false,
values: {},
};
const state = this.states.hasOwnProperty(id) ? this.states[id] : this.rehydrate(id);

if (!this.states.hasOwnProperty(id)) {
this.states[id] = state;
Expand All @@ -72,6 +68,17 @@ export default class Resolver {
throw new Error(`${this.constructor.displayName} was rejected: ${error}`);
}

rehydrate(id) {
if (typeof __resolver__ === 'undefined') {
return {
fulfilled: false,
rejected: false,
values: {},
};
}
return __resolver__[id];
}

resolve(container, callback) {
const asyncProps = container.props.resolve || {};
const state = this.getContainerState(container);
Expand Down
12 changes: 10 additions & 2 deletions test/Container.element.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ describe("<Container />", function() {

context("when keys are rehydrating", function() {
before(function() {
global.__resolver__ = { user: "Exists" };
global.__resolver__ = {
'.0': {
values: {
fulfilled: false,
rejected: false,
user: "Exists"
}
}
};
});

after(function() {
Expand Down Expand Up @@ -130,7 +138,7 @@ describe("<Container />", function() {
/>
);

assert.equal(actual, `<code>${JSON.stringify(global.__resolver__)}</code>`);
assert.equal(actual, `<code>${JSON.stringify(global.__resolver__['.0'].values)}</code>`);
});
});
});
Expand Down

0 comments on commit ae54d7c

Please sign in to comment.