Commit 78e2b0be authored by Matija Obreza's avatar Matija Obreza
Browse files

SSR: needs methods receive arguments { state, ownProps, search, params }

- state and ownProps pair allow for using similar structures as in mapStateToProps
- search and params are for backward compatiblity
parent e4267a5d
export default function fetchComponentData(dispatch, branch, search) {
export default function fetchComponentData(dispatch, branch, search, state = null) {
const promisesWithProps = [];
branch.map(({ route, match }) => {
......@@ -8,9 +8,12 @@ export default function fetchComponentData(dispatch, branch, search) {
return;
}
const ownProps = { route, match };
// console.log('SSR need with arguments (state, ownProps, search)=', '..snip..'); // , ownProps, search);
// Provide params to static needs
component.needs.filter((need) => need({ search, params: match.params })).map((need) => {
return dispatch(need({ search, params: match.params }));
component.needs.filter((need) => need({ state, ownProps, search, params: match.params })).map((need) => {
return dispatch(need({ state, ownProps, search, params: match.params }));
})
// a nice array of Promises
.forEach((promise) => promisesWithProps.push(promise));
......
......@@ -112,7 +112,7 @@ const prerenderer = (html, errHtml) => (req, res) => {
console.log(`Rendering ${pathWithoutLang} for ${pathname}`);
const branch = matchRoutes(routes, pathWithoutLang);
fetchComponentData(store.dispatch, branch, search)
fetchComponentData(store.dispatch, branch, search, store.getState())
.catch((err) => {
console.log('Error fetching component data', err);
res.status(500).end(err.message);
......
......@@ -51,12 +51,12 @@ const styles = (theme) => ({
class RepositoryBrowser extends React.Component<IRepositoryBrowserProps, any> {
protected static needs = [
({ root, path }) => getFolder(root + path),
({ ownProps }) => getFolder(normalize((ownProps.route.root || '/') + (ownProps.match.params.path || '/')).replace(/^(.+)\/$/, '$1')),
];
public componentWillMount() {
const { folder, folderPath, getFolder } = this.props;
// console.log(`RepositoryBrowser.componentWillMount...`, normalize(root + path));
// console.log(`RepositoryBrowser.cwm...`, folderPath);
if (!folder || (folder.folder && folder.folder.path !== folderPath)) {
// console.log(`Loading folder root=${root} path=${path}`);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment