-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Framework: Add makeLayout() middleware * Allow elements as props to the layout component * Add a ReduxWrappedLayout helper function * Split the entry points for the isomorphic router controller (allowing client-specific dependencies) * Framework: fix layout section proptype * Themes: Remove obsolete comment * my-sites/controller: Export makeNavigation middleware * Themes: Use makeNavigation and makeLayout for rendering logged-in * client/boot: Remove an obsolete check * my-sites/controller: Use JSX for createNavigation() return value * client/controller: Make README.md more verbose * client/controller: Move shared code to shared.js * Framework: Unmount multi-tree layout before rendering single-tree * Themes: Remove siteSelection middleware from multi-site route * Layout: Conditionally add wp-singletree-layout class * client/controller: Drop layoutFocus import * client/controller: Move makeLayoutMiddleware to shared.js
- Loading branch information
Showing
10 changed files
with
201 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Isomorphic Routing Helpers | ||
========================== | ||
|
||
Provides middleware to be used agnostically with either `page.js`, or with | ||
`express` (through middleware adapters found in `server/`). Since some of the | ||
middleware needs to function differently on the server than on the client, | ||
both versions are provided transparently in those cases (by `index.web.js` and | ||
`index.node.js`, respectively.) | ||
|
||
These middlewares include: | ||
* `makeLayout`: creates a `Layout` (or `LayoutLoggedOut`) component in `context.layout`. | ||
Accepts `primary`, `secondary`, and `tertiary` arguments which it will use to | ||
populate the corresponding `<div>`s. | ||
* `clientRouter`: Essentially an alias for `page`, which invokes a client-side | ||
`render` middleware after all other middlewares. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* External Dependencies | ||
*/ | ||
import React from 'react'; | ||
import { Provider as ReduxProvider } from 'react-redux'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { makeLayoutMiddleware } from './shared.js'; | ||
import LayoutLoggedOut from 'layout/logged-out'; | ||
|
||
/** | ||
* Re-export | ||
*/ | ||
export { setSection } from './shared.js'; | ||
|
||
const ReduxWrappedLoggedOutLayout = ( { store, primary, secondary, tertiary } ) => ( | ||
<ReduxProvider store={ store }> | ||
<LayoutLoggedOut primary={ primary } | ||
secondary={ secondary } | ||
tertiary={ tertiary } /> | ||
</ReduxProvider> | ||
); | ||
|
||
/** | ||
* @param { object } context -- Middleware context | ||
* @param { function } next -- Call next middleware in chain | ||
* | ||
* Produce a `LayoutLoggedOut` element in `context.layout`, using | ||
* `context.primary`, `context.secondary`, and `context.tertiary` to populate it. | ||
*/ | ||
export const makeLayout = makeLayoutMiddleware( ReduxWrappedLoggedOutLayout ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"main": "index.node.js", | ||
"browser": "index.web.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import noop from 'lodash/noop'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { setSection as setSectionAction } from 'state/ui/actions'; | ||
import { getCurrentUser } from 'state/current-user/selectors'; | ||
|
||
export function makeLayoutMiddleware( LayoutComponent ) { | ||
return ( context, next ) => { | ||
const { store, primary, secondary, tertiary } = context; | ||
|
||
// On server, only render LoggedOutLayout when logged-out. | ||
if ( ! context.isServerSide || getCurrentUser( context.store.getState() ) ) { | ||
context.layout = ( | ||
<LayoutComponent store={ store } | ||
primary={ primary } | ||
secondary={ secondary } | ||
tertiary={ tertiary } | ||
/> | ||
); | ||
} | ||
next(); | ||
}; | ||
} | ||
|
||
export function setSection( section ) { | ||
return ( context, next = noop ) => { | ||
context.store.dispatch( setSectionAction( section ) ); | ||
|
||
next(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.