-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add resolve feature #42
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,6 +395,33 @@ describe('AsyncProps', () => { | |
/> | ||
), div, next) | ||
}) | ||
|
||
it('allows to override resolver function', (done) => { | ||
const appSpy = spyOn(App, 'loadProps').andCallThrough() | ||
|
||
const next = execNext([ | ||
() => {}, | ||
() => { | ||
expect(appSpy.calls.length).toEqual(1) | ||
expect(appSpy.calls[0].arguments[2]).toEqual('check') | ||
}, | ||
done | ||
]) | ||
|
||
function resolver(Component, params, cb) { | ||
Component.loadProps(params, cb, 'check') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this would pass even w/o your changes, right? Maybe switch the name from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's impossible. there a lot of places where we are checking that loadProps method exists There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will work only with resolver feature |
||
} | ||
|
||
App.setAssertions(next) | ||
|
||
render(( | ||
<Router | ||
history={createHistory('/')} | ||
routes={routes} | ||
render={(props) => <AsyncProps {...props} resolver={resolver} />} | ||
/> | ||
), div, next) | ||
}) | ||
}) | ||
|
||
describe('server rendering', () => { | ||
|
@@ -420,6 +447,24 @@ describe('AsyncProps', () => { | |
}) | ||
}) | ||
|
||
it('allows to override resolver function', (done) => { | ||
const appSpy = spyOn(App, 'loadProps').andCallThrough() | ||
function resolver(Component, params, cb) { | ||
Component.loadProps(params, cb, 'check') | ||
} | ||
const loadPropsRoutes = { | ||
path: '/', | ||
component: App | ||
} | ||
match({ routes: loadPropsRoutes, location: '/' }, (err, redirect, renderProps) => { | ||
loadPropsOnServer(renderProps, () => { | ||
expect(appSpy.calls.length).toEqual(1) | ||
expect(appSpy.calls[0].arguments[2]).toEqual('check1') | ||
done() | ||
}, resolver) | ||
}) | ||
}) | ||
|
||
it('renders synchronously with props from hydration', () => { | ||
const html = renderToString( | ||
<Router | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets put the resolver in the object with
components
andparams
. Gives nice symmetry between component props and static function "props".