Last active
March 11, 2018 02:59
-
-
Save kechol/8dc1e4f07739015bca8c6c915f95867e to your computer and use it in GitHub Desktop.
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
import * as PropTypes from 'prop-types'; | |
import * as React from 'react'; | |
import { connect, Dispatch } from 'react-redux' | |
import { ActionCreator } from 'typescript-fsa'; | |
import { openExternal } from './reducer' | |
interface ExternalLinkPropTypes { | |
href: string, | |
target?: string, | |
onClick?: React.MouseEventHandler<HTMLAnchorElement>, | |
innerRef?: React.Ref<any>, | |
} | |
interface ExternalLinkAction { | |
openExternal: ActionCreator<string> | |
} | |
type ExternalLinkProps = ExternalLinkPropTypes & { dispatch: Dispatch<ExternalLinkAction> }; | |
export class ExternalLink extends React.Component<ExternalLinkProps> { | |
public static propTypes = { | |
href: PropTypes.string.isRequired, | |
innerRef: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), | |
onClick: PropTypes.func, | |
target: PropTypes.string, | |
} | |
public render() { | |
const { innerRef, dispatch, ...props } = this.props; | |
return ( | |
<a {...props} onClick={this.handleClick.bind(this)} ref={innerRef} /> | |
); | |
} | |
private handleClick(e: React.MouseEvent<HTMLAnchorElement>) { | |
if (this.props.onClick) { | |
this.props.onClick(e); | |
} | |
e.preventDefault(); | |
this.props.dispatch(openExternal(this.props.href)); | |
} | |
} | |
export default connect()(ExternalLink); |
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
import actionCreatorFactory from 'typescript-fsa'; | |
const actionCreator = actionCreatorFactory(); | |
export const openExternal = actionCreator<string>('@@electron/OPEN_EXTERNAL'); |
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
import { SagaIterator } from 'redux-saga'; | |
import { fork } from 'redux-saga/effects'; | |
import { createWatchIpcSender } from '../../saga' | |
import { openExternal } from './reducer' | |
export default function*(): SagaIterator { | |
yield fork(createWatchIpcSender(openExternal)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment