Skip to content
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

Fixes: eslint semicolons + MemoryHistory failing test #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions modules/Actions.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import React from "react";
import PropTypes from "prop-types";
import { history as historyType } from "./PropTypes";
import React from "react"
import PropTypes from "prop-types"
import { history as historyType } from "./PropTypes"

class Action extends React.Component {
static propTypes = {
perform: PropTypes.func.isRequired
};
}

static contextTypes = {
history: historyType.isRequired
};
}

performAction() {
this.props.perform(this.context.history);
this.props.perform(this.context.history)
}

componentDidMount() {
this.performAction();
this.performAction()
}

componentDidUpdate() {
this.performAction();
this.performAction()
}

render() {
return null;
return null
}
}

export const Push = ({ location, path, state }) => (
<Action perform={history => history.push(location || path, state)} />
);
)

Push.propTypes = {
path: PropTypes.string,
Expand All @@ -41,26 +41,24 @@ Push.propTypes = {
hash: PropTypes.string,
state: PropTypes.object
})
};
}

export const Replace = ({ location, path, state }) => (
<Action perform={history => history.replace(location || path, state)} />
);
)

Replace.propTypes = Push.propTypes;
Replace.propTypes = Push.propTypes

export const Pop = ({ go }) => <Action perform={history => history.go(go)} />;
export const Pop = ({ go }) => <Action perform={history => history.go(go)} />

Pop.propTypes = {
go: PropTypes.number
};
}

Pop.defaultProps = {
go: -1
};
}

export const Back = () => <Action perform={history => history.goBack()} />;
export const Back = () => <Action perform={history => history.goBack()} />

export const Forward = () => (
<Action perform={history => history.goForward()} />
);
export const Forward = () => <Action perform={history => history.goForward()} />
28 changes: 14 additions & 14 deletions modules/BrowserHistory.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import PropTypes from "prop-types";
import createBrowserHistory from "history/createBrowserHistory";
import { history as historyType } from "./PropTypes";
import React from "react"
import PropTypes from "prop-types"
import createBrowserHistory from "history/createBrowserHistory"
import { history as historyType } from "./PropTypes"

/**
* Manages session history using the HTML5 history API including
Expand All @@ -14,14 +14,14 @@ class BrowserHistory extends React.Component {
getUserConfirmation: PropTypes.func,
keyLength: PropTypes.number,
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired
};
}

static childContextTypes = {
history: historyType.isRequired
};
}

getChildContext() {
return { history: this.history };
return { history: this.history }
}

componentWillMount() {
Expand All @@ -30,30 +30,30 @@ class BrowserHistory extends React.Component {
forceRefresh,
getUserConfirmation,
keyLength
} = this.props;
} = this.props

this.history = createBrowserHistory({
basename,
forceRefresh,
getUserConfirmation,
keyLength
});
})

// Do this here so we catch actions in cDM.
this.unlisten = this.history.listen(() => this.forceUpdate());
this.unlisten = this.history.listen(() => this.forceUpdate())
}

componentWillUnmount() {
this.unlisten();
this.unlisten()
}

render() {
const { children } = this.props;
const { children } = this.props

return typeof children === "function"
? children(this.history)
: React.Children.only(children);
: React.Children.only(children)
}
}

export default BrowserHistory;
export default BrowserHistory
28 changes: 14 additions & 14 deletions modules/HashHistory.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import PropTypes from "prop-types";
import createHashHistory from "history/createHashHistory";
import { history as historyType } from "./PropTypes";
import React from "react"
import PropTypes from "prop-types"
import createHashHistory from "history/createHashHistory"
import { history as historyType } from "./PropTypes"

/**
* Manages session history using window.location.hash.
Expand All @@ -12,40 +12,40 @@ class HashHistory extends React.Component {
getUserConfirmation: PropTypes.func,
hashType: PropTypes.oneOf(["hashbang", "noslash", "slash"]),
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired
};
}

static childContextTypes = {
history: historyType.isRequired
};
}

getChildContext() {
return { history: this.history };
return { history: this.history }
}

componentWillMount() {
const { basename, getUserConfirmation, hashType } = this.props;
const { basename, getUserConfirmation, hashType } = this.props

this.history = createHashHistory({
basename,
getUserConfirmation,
hashType
});
})

// Do this here so we catch actions in cDM.
this.unlisten = this.history.listen(() => this.forceUpdate());
this.unlisten = this.history.listen(() => this.forceUpdate())
}

componentWillUnmount() {
this.unlisten();
this.unlisten()
}

render() {
const { children } = this.props;
const { children } = this.props

return typeof children === "function"
? children(this.history)
: React.Children.only(children);
: React.Children.only(children)
}
}

export default HashHistory;
export default HashHistory
28 changes: 14 additions & 14 deletions modules/MemoryHistory.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import PropTypes from "prop-types";
import createMemoryHistory from "history/createMemoryHistory";
import { history as historyType } from "./PropTypes";
import React from "react"
import PropTypes from "prop-types"
import createMemoryHistory from "history/createMemoryHistory"
import { history as historyType } from "./PropTypes"

/**
* Manages session history using in-memory storage.
Expand All @@ -13,14 +13,14 @@ class MemoryHistory extends React.Component {
initialIndex: PropTypes.number,
keyLength: PropTypes.number,
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired
};
}

static childContextTypes = {
history: historyType.isRequired
};
}

getChildContext() {
return { history: this.history };
return { history: this.history }
}

componentWillMount() {
Expand All @@ -29,30 +29,30 @@ class MemoryHistory extends React.Component {
initialEntries,
initialIndex,
keyLength
} = this.props;
} = this.props

this.history = createMemoryHistory({
getUserConfirmation,
initialEntries,
initialIndex,
keyLength
});
})

// Do this here so we catch actions in cDM.
this.unlisten = this.history.listen(() => this.forceUpdate());
this.unlisten = this.history.listen(() => this.forceUpdate())
}

componentWillUnmount() {
this.unlisten();
this.unlisten()
}

render() {
const { children } = this.props;
const { children } = this.props

return typeof children === "function"
? children(this.history)
: React.Children.only(children);
: React.Children.only(children)
}
}

export default MemoryHistory;
export default MemoryHistory
32 changes: 16 additions & 16 deletions modules/Prompt.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
import React from "react";
import PropTypes from "prop-types";
import { history as historyType } from "./PropTypes";
import React from "react"
import PropTypes from "prop-types"
import { history as historyType } from "./PropTypes"

class Prompt extends React.Component {
static propTypes = {
when: PropTypes.bool,
message: PropTypes.oneOfType([PropTypes.func, PropTypes.string]).isRequired
};
}

static contextTypes = {
history: historyType.isRequired
};
}

static defaultProps = {
when: true
};
}

enable(message) {
if (this.unblock) this.unblock();
if (this.unblock) this.unblock()

this.unblock = this.context.history.block(message);
this.unblock = this.context.history.block(message)
}

disable() {
if (this.unblock) {
this.unblock();
this.unblock = null;
this.unblock()
this.unblock = null
}
}

componentWillMount() {
if (this.props.when) this.enable(this.props.message);
if (this.props.when) this.enable(this.props.message)
}

componentWillReceiveProps(nextProps) {
if (nextProps.when) {
if (!this.props.when || this.props.message !== nextProps.message)
this.enable(nextProps.message);
this.enable(nextProps.message)
} else {
this.disable();
this.disable()
}
}

componentWillUnmount() {
this.disable();
this.disable()
}

render() {
return null;
return null
}
}

export default Prompt;
export default Prompt
8 changes: 4 additions & 4 deletions modules/PropTypes.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import PropTypes from "prop-types";
import PropTypes from "prop-types"

export const action = PropTypes.oneOf(["PUSH", "REPLACE", "POP"]);
export const action = PropTypes.oneOf(["PUSH", "REPLACE", "POP"])

export const location = PropTypes.shape({
pathname: PropTypes.string.isRequired,
search: PropTypes.string.isRequired,
hash: PropTypes.string.isRequired,
state: PropTypes.object,
key: PropTypes.string
});
})

export const history = PropTypes.shape({
action: action.isRequired,
Expand All @@ -20,4 +20,4 @@ export const history = PropTypes.shape({
goForward: PropTypes.func.isRequired,
canGo: PropTypes.func,
block: PropTypes.func.isRequired
});
})
4 changes: 2 additions & 2 deletions modules/__tests__/RenderTestSequences/ReplaceChangesTheKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export default (done) => {
let keyAfterPush

const steps = [
({ location }) => {
({ location, entries }) => {
expect(location).toMatch({
pathname: '/',
key: undefined
key: entries ? /^[0-9a-z]+$/ : undefined
})

return <Push path="/hello" state={{ the: 'state' }}/>
Expand Down
10 changes: 5 additions & 5 deletions modules/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export BrowserHistory from "./BrowserHistory";
export HashHistory from "./HashHistory";
export MemoryHistory from "./MemoryHistory";
export Prompt from "./Prompt";
export * from "./Actions";
export BrowserHistory from "./BrowserHistory"
export HashHistory from "./HashHistory"
export MemoryHistory from "./MemoryHistory"
export Prompt from "./Prompt"
export * from "./Actions"