Skip to content

Commit

Permalink
fix: remove params spread, potentially fix #1424
Browse files Browse the repository at this point in the history
  • Loading branch information
longlho committed Aug 21, 2019
1 parent 0b3a16b commit aeb177c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 22 deletions.
41 changes: 41 additions & 0 deletions examples/Injected.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as React from 'react';
import {IntlProvider, useIntl, injectIntl, IntlShape} from '../';

const Comp: React.FC<{}> = _ => {
const {formatDate} = useIntl();
return <h1>{formatDate(Date.now())}</h1>;
};

const Comp2: React.FC<{intl: IntlShape}> = ({
intl: {formatDate, formatTime},
}) => {
return (
<>
<h1>{formatDate(new Date(), {month: 'long'})}</h1>
<h2>{formatTime(undefined)}</h2>
</>
);
};

const Comp2WithIntl = injectIntl(Comp2);

interface Props {
currentTime?: Date | number;
}

const App: React.FC<Props> = _ => {
return (
<IntlProvider locale="en" timeZone="Asia/Tokyo">
<p>
<Comp />
<Comp2WithIntl />
</p>
</IntlProvider>
);
};

App.defaultProps = {
currentTime: new Date(),
};

export default App;
2 changes: 1 addition & 1 deletion examples/TimeZone.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import {FormattedDate, FormattedTime, IntlProvider} from '../dist';
import {FormattedDate, FormattedTime, IntlProvider} from '../';

interface Props {
currentTime?: Date | number;
Expand Down
29 changes: 15 additions & 14 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>React Intl Explicit Example</title>
</head>
<body>
<div id="timezone"></div>
<div id="messages"></div>
<div id="advanced"></div>
<script src="./index.tsx"></script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>React Intl Explicit Example</title>
</head>
<body>
<div id="timezone"></div>
<div id="messages"></div>
<div id="advanced"></div>
<div id="injected"></div>
<script src="./index.tsx"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions examples/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import * as ReactDOM from 'react-dom';
import Timezone from './TimeZone';
import Messages from './Messages';
import Advanced from './Advanced';
import Injected from './Injected';

ReactDOM.render(<Timezone />, document.getElementById('timezone'));

ReactDOM.render(<Messages />, document.getElementById('messages'));

ReactDOM.render(<Advanced />, document.getElementById('advanced'));
ReactDOM.render(<Injected />, document.getElementById('injected'));
18 changes: 11 additions & 7 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export function formatDate(
timeZone,
}: Pick<IntlConfig, 'locale' | 'formats' | 'onError' | 'timeZone'>,
state: Formatters,
...[value, options = {}]: Parameters<IntlFormatters['formatDate']>
value?: Parameters<IntlFormatters['formatDate']>[0],
options: Parameters<IntlFormatters['formatDate']>[1] = {}
) {
const {format} = options;
let defaults = {
Expand Down Expand Up @@ -130,7 +131,8 @@ export function formatTime(
timeZone,
}: Pick<IntlConfig, 'locale' | 'formats' | 'onError' | 'timeZone'>,
state: Formatters,
...[value, options = {}]: Parameters<IntlFormatters['formatTime']>
value?: Parameters<IntlFormatters['formatTime']>[0],
options: Parameters<IntlFormatters['formatTime']>[1] = {}
) {
const {format} = options;
let defaults = {
Expand Down Expand Up @@ -170,9 +172,9 @@ export function formatRelativeTime(
onError,
}: Pick<IntlConfig, 'locale' | 'formats' | 'onError'>,
state: Formatters,
...[value, unit = 'second', options = {}]: Parameters<
IntlFormatters['formatRelativeTime']
>
value: Parameters<IntlFormatters['formatRelativeTime']>[0],
unit: Parameters<IntlFormatters['formatRelativeTime']>[1] = 'second',
options: Parameters<IntlFormatters['formatRelativeTime']>[2] = {}
) {
const {format} = options;

Expand Down Expand Up @@ -201,7 +203,8 @@ export function formatNumber(
onError,
}: Pick<IntlConfig, 'locale' | 'formats' | 'onError'>,
state: Formatters,
...[value, options = {}]: Parameters<IntlFormatters['formatNumber']>
value: Parameters<IntlFormatters['formatNumber']>[0],
options: Parameters<IntlFormatters['formatNumber']>[1] = {}
) {
const {format} = options;
let defaults =
Expand All @@ -220,7 +223,8 @@ export function formatNumber(
export function formatPlural(
{locale, onError}: Pick<IntlConfig, 'locale' | 'onError'>,
state: Formatters,
...[value, options = {}]: Parameters<IntlFormatters['formatPlural']>
value: Parameters<IntlFormatters['formatPlural']>[0],
options: Parameters<IntlFormatters['formatPlural']>[1] = {}
) {
let filteredOptions = filterProps(options, PLURAL_FORMAT_OPTIONS);

Expand Down

0 comments on commit aeb177c

Please sign in to comment.