-
Notifications
You must be signed in to change notification settings - Fork 184
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 new component: <TheFold />
#221
Changes from all 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 |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import {ReactServerAgent, RootContainer, RootElement} from "react-server"; // eslint-disable-line | ||
|
||
// TODO: when we implement <TheFold/> (https://github.com/redfin/react-server/issues/161), | ||
// update this test page to use the new API | ||
import { | ||
ReactServerAgent, | ||
RootContainer, | ||
RootElement, | ||
TheFold, | ||
} from "react-server"; | ||
|
||
export default class RootWhenPage { | ||
handleRoute(next) { | ||
this.data = ReactServerAgent.get('/data/delay?ms=200'); | ||
this.data = ReactServerAgent.get('/data/delay?ms=200&big=10000') | ||
.then(res => res.body); | ||
return next(); | ||
} | ||
getElements() { | ||
return [ | ||
<RootContainer> | ||
<RootContainer when={this.data}> | ||
<div>One</div> | ||
</RootContainer>, | ||
<RootElement when={this.data}><div>Two</div></RootElement>, | ||
<RootContainer> | ||
<div>Three - there should be script tags starting from right after me b/c my getAboveTheFoldCount is 3!</div> | ||
<div>Three - there should be script tags starting from right after me.</div> | ||
<TheFold /> | ||
<RootElement when={this.data}><div>Four</div></RootElement> | ||
</RootContainer>, | ||
<div>Five</div>, | ||
] | ||
} | ||
|
||
getAboveTheFoldCount() { | ||
return 3; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ module.exports = { | |
RootContainer: require("./components/RootContainer"), | ||
RootElement: require("./components/RootElement"), | ||
Link: require('./components/Link'), | ||
TheFold: require('./components/TheFold').default, | ||
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. Awkward to pull out |
||
History: require('./components/History'), | ||
ClientRequest: require('./ClientRequest'), | ||
FramebackController: require('./FramebackController'), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {Component} from "react"; | ||
|
||
export default class TheFold extends Component { | ||
render() { | ||
throw new Error("Something went wrong. Trying to render the fold..."); | ||
} | ||
} | ||
|
||
TheFold.defaultProps = { | ||
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.
is, I think, privater 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. Yeah, I actually thought about that. AFAIK the reason |
||
_isTheFold: true, | ||
} | ||
|
||
export function isTheFold(element) { | ||
return element && element.props && element.props._isTheFold; | ||
} | ||
|
||
export function markTheFold() { | ||
return {isTheFold:true}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ var Q = require("q"), | |
|
||
var {isRootContainer, flattenForRender} = require('../components/RootContainer'); | ||
var {ensureRootElement, scheduleRender} = require('../components/RootElement'); | ||
var {isTheFold, markTheFold} = require('../components/TheFold'); | ||
|
||
// There are three data structures defined here that are relevant for page and | ||
// middleware authors: | ||
|
@@ -61,7 +62,6 @@ var PAGE_METHODS = { | |
getBase : [() => null, Q], | ||
getBodyClasses : [() => [], Q], | ||
getElements : [() => [], standardizeElements], | ||
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. Glad I never updated the tabling around this. It's almost like I knew it was an ugly hack that should be replaced... 👹 |
||
getAboveTheFoldCount : [() => 1, _ => _], | ||
getResponseData : [() => "", Q], | ||
}; | ||
|
||
|
@@ -174,6 +174,7 @@ function standardizeElements(elements) { | |
.makeArray(elements) | ||
.map(e => isRootContainer(e)?flattenForRender(e):e) | ||
.reduce((m, e) => m.concat(Array.isArray(e)?e:[e]), []) | ||
.map(e => isTheFold(e)?markTheFold():e) | ||
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. If I understand correctly, this is just converting a React element to an object that looks like 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. Yep, exactly. The normalized elements array contains only root elements and control objects. This introduces a new control object: |
||
.map(ensureRootElement) | ||
.map(scheduleRender) | ||
} | ||
|
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.
Added a
big=<size>
param to the test data endpoint that just tells it to return a JSON object withsize
keys. It's easiest to see the fold when there's a bunch of JS to for the browser to slurp up right after.