Skip to content

Commit

Permalink
Remove all defaultProps declarations
Browse files Browse the repository at this point in the history
Related #6465
  • Loading branch information
mjackson committed Nov 8, 2018
1 parent 4aefa2f commit 980bdd1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 75 deletions.
12 changes: 6 additions & 6 deletions packages/react-router-dom/.size-snapshot.json
Expand Up @@ -14,13 +14,13 @@
}
},
"umd/react-router-dom.js": {
"bundled": 126991,
"minified": 47032,
"gzipped": 14084
"bundled": 160055,
"minified": 57467,
"gzipped": 16536
},
"umd/react-router-dom.min.js": {
"bundled": 84909,
"minified": 30118,
"gzipped": 9978
"bundled": 97822,
"minified": 34506,
"gzipped": 10211

This comment has been minimized.

Copy link
@mjackson

mjackson Nov 8, 2018

Author Member

I have no idea why these numbers are bigger. If anything, I feel like I deleted more code than I added.

}
}
22 changes: 11 additions & 11 deletions packages/react-router/.size-snapshot.json
@@ -1,26 +1,26 @@
{
"esm/react-router.js": {
"bundled": 24721,
"minified": 14469,
"gzipped": 3778,
"bundled": 25037,
"minified": 14355,
"gzipped": 3799,
"treeshaked": {
"rollup": {
"code": 4464,
"code": 3293,
"import_statements": 472
},
"webpack": {
"code": 5940
"code": 4688
}
}
},
"umd/react-router.js": {
"bundled": 99946,
"minified": 35992,
"gzipped": 11338
"bundled": 100262,
"minified": 35923,
"gzipped": 11378
},
"umd/react-router.min.js": {
"bundled": 63430,
"minified": 22393,
"gzipped": 7861
"bundled": 63746,
"minified": 22308,
"gzipped": 7882
}
}
10 changes: 3 additions & 7 deletions packages/react-router/modules/Prompt.js
Expand Up @@ -8,16 +8,15 @@ import RouterContext from "./RouterContext";
/**
* The public API for prompting the user before navigating away from a screen.
*/
function Prompt(props) {
function Prompt({ message, when = true }) {
return (
<RouterContext.Consumer>
{context => {
invariant(context, "You should not use <Prompt> outside a <Router>");

if (!props.when || context.staticContext) return null;
if (!when || context.staticContext) return null;

const method = context.history.block;
const message = props.message;

return (
<Lifecycle
Expand All @@ -33,17 +32,14 @@ function Prompt(props) {
onUnmount={self => {
self.release();
}}
message={message}
/>
);
}}
</RouterContext.Consumer>
);
}

Prompt.defaultProps = {
when: true
};

if (__DEV__) {
const messageType = PropTypes.oneOfType([PropTypes.func, PropTypes.string]);

Expand Down
39 changes: 16 additions & 23 deletions packages/react-router/modules/Redirect.js
Expand Up @@ -10,44 +10,41 @@ import generatePath from "./generatePath";
/**
* The public API for navigating programmatically with a component.
*/
function Redirect(props) {
function Redirect({ computedMatch, to, push = false }) {
return (
<RouterContext.Consumer>
{context => {
invariant(context, "You should not use <Redirect> outside a <Router>");

const method = props.push
? context.history.push
: context.history.replace;
const to = createLocation(
props.computedMatch
? typeof props.to === "string"
? generatePath(props.to, props.computedMatch.params)
const { history, staticContext } = context;

const method = push ? history.push : history.replace;
const location = createLocation(
computedMatch
? typeof to === "string"
? generatePath(to, computedMatch.params)
: {
...props.to,
pathname: generatePath(
props.to.pathname,
props.computedMatch.params
)
...to,
pathname: generatePath(to.pathname, computedMatch.params)
}
: props.to
: to
);

// When rendering in a static context,
// set the new location immediately.
if (context.staticContext) {
method(to);
if (staticContext) {
method(location);
return null;
}

return (
<Lifecycle
onMount={() => {
method(to);
method(location);
}}
onUpdate={(self, prevProps) => {
if (!locationsAreEqual(prevProps.to, to)) {
method(to);
if (!locationsAreEqual(prevProps.to, location)) {
method(location);
}
}}
to={to}
Expand All @@ -58,10 +55,6 @@ function Redirect(props) {
);
}

Redirect.defaultProps = {
push: false
};

if (__DEV__) {
Redirect.propTypes = {
push: PropTypes.bool,
Expand Down
37 changes: 9 additions & 28 deletions packages/react-router/modules/StaticRouter.js
Expand Up @@ -51,36 +51,23 @@ function noop() {}
* server-rendering scenarios.
*/
class StaticRouter extends React.Component {
static defaultProps = {
basename: "",
location: "/"
};

createHref = path => addLeadingSlash(this.props.basename + createURL(path));

handlePush = location => {
const { basename, context } = this.props;
context.action = "PUSH";
navigateTo(location, action) {
const { basename = "", context } = this.props;
context.action = action;
context.location = addBasename(basename, createLocation(location));
context.url = createURL(context.location);
};

handleReplace = location => {
const { basename, context } = this.props;
context.action = "REPLACE";
context.location = addBasename(basename, createLocation(location));
context.url = createURL(context.location);
};
}

handlePush = location => this.navigateTo(location, "PUSH");
handleReplace = location => this.navigateTo(location, "REPLACE");
handleListen = () => noop;

handleBlock = () => noop;

render() {
const { basename, context, location, ...rest } = this.props;
const { basename = "", context = {}, location = "/", ...rest } = this.props;

const history = {
createHref: this.createHref,
createHref: path => addLeadingSlash(basename + createURL(path)),
action: "POP",
location: stripBasename(basename, createLocation(location)),
push: this.handlePush,
Expand All @@ -92,13 +79,7 @@ class StaticRouter extends React.Component {
block: this.handleBlock
};

return (
<Router
{...rest}
history={history}
staticContext={this.props.context || {}}
/>
);
return <Router {...rest} history={history} staticContext={context} />;
}
}

Expand Down

0 comments on commit 980bdd1

Please sign in to comment.