Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c9a9a99
Updated react (also in tests) to version 16.3.0
marcesengel May 29, 2018
6d8bdfb
Updated Provider to use new Context API
marcesengel May 29, 2018
e7d8488
Added HOC to inject intl from context into properties
marcesengel May 29, 2018
69f9540
Updated shouldIntlComponentUpdate to not check old context anymore
marcesengel May 29, 2018
c31a03c
Updated FormattedDate to use new Context API
marcesengel May 29, 2018
12daee7
Updated FormattedHTMLMessage to use new Context API
marcesengel May 29, 2018
9308dbb
Updated FormattedMessage to use new Context API
marcesengel May 29, 2018
fee8e3b
Updated FormattedNumber to use new Context API
marcesengel May 29, 2018
d47586c
Updated FormattedPlural to use new Context API
marcesengel May 29, 2018
ec2fac4
Fixed Provider
marcesengel May 29, 2018
daf8b06
Updated FormattedRelative to use new Context API
marcesengel May 29, 2018
70e5bbf
Updated FormattedTime to use new Context API
marcesengel May 29, 2018
be92142
Updated injectIntl to use new Context API
marcesengel May 29, 2018
9c3a522
Set version of react-test-renderer to react version
marcesengel May 29, 2018
bab8c7a
Updated React to 16.3.1 to prevent "Warning: Unexpected Fiber popped."
marcesengel May 29, 2018
7102a06
Fixed wrong export in Provider (exported Context.Provider instead of …
marcesengel May 29, 2018
8e2eef9
Fixed bundling error in Provider
marcesengel May 29, 2018
a68d6d7
Fixed typo
marcesengel May 29, 2018
7defe05
Fixed injectIntl not having the intl context
marcesengel May 29, 2018
ac1cf19
Fixed Provider not copying unchanged values from previous context
marcesengel May 29, 2018
9485916
Fixed now() not beeing passed to formatters
marcesengel May 29, 2018
dc1c3fb
Updated peerDependencies to show the current lack of polyfills
marcesengel May 29, 2018
dbe1f66
WIP: Not really usefull, just for compare
langpavel May 30, 2018
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
9,026 changes: 9,026 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 17 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,29 @@
"intl-format-cache": "^2.0.5",
"intl-messageformat": "^2.1.0",
"intl-relativeformat": "^2.1.0",
"invariant": "^2.1.1"
"invariant": "^2.1.1",
"react-addons-test-utils": "^0.14.8"
},
"peerDependencies": {
"react": "^0.14.9 || ^15.0.0 || ^16.0.0",
"react": ">= 16.3.1",
"prop-types": "^15.5.4"
},
"devDependencies": {
"babel-cli": "^6.2.0",
"babel-eslint": "^7.1.1",
"babel-jest": "^19.0.0",
"babel-plugin-external-helpers": "^6.18.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-react-intl": "^2.0.0",
"babel-plugin-transform-async-to-generator": "^6.16.0",
"babel-plugin-transform-class-properties": "^6.11.5",
"babel-plugin-transform-es2015-modules-commonjs": "^6.18.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-plugin-transform-es3-member-expression-literals": "^6.3.13",
"babel-plugin-transform-es3-property-literals": "^6.3.13",
"babel-plugin-transform-object-rest-spread": "^6.1.18",
"babel-plugin-transform-react-remove-prop-types": "^0.3.2",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"babel-preset-react": "^6.24.1",
"babelify": "^7.2.0",
"benchmark": "^2.1.0",
"browserify": "^14.0.0",
Expand All @@ -105,19 +107,19 @@
"jest": "^19.0.0",
"mkdirp": "^0.5.1",
"prettier": "^1.6.1",
"prop-types": "^15.5.4",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-test-renderer": "^15.5.4",
"prop-types": "^15.6.1",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-test-renderer": "^16.3.0",
"rimraf": "^2.4.2",
"rollup": "^0.50.0",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-commonjs": "^8.2.1",
"rollup": "^0.50.1",
"rollup-plugin-babel": "^3.0.4",
"rollup-plugin-commonjs": "^8.4.1",
"rollup-plugin-memory": "^2.0.0",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^2.0.0",
"serialize-javascript": "^1.1.1",
"serialize-javascript": "^1.5.0",
"superagent": "^3.0.0",
"watchify": "^3.7.0"
},
Expand All @@ -133,10 +135,11 @@
"react:clean": "rimraf node_modules/{react,react-dom,react-addons-test-utils}",
"react:14": "npm run react:clean && npm i react@^0.14 react-dom@^0.14 react-addons-test-utils@^0.14",
"react:15": "npm run react:clean && npm i react@^15 react-dom@^15",
"react:16": "npm run react:clean && npm i [email protected] [email protected]",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "jest --coverage --verbose",
"test:react": "npm run react:14 && jest && npm run react:15 && jest",
"test:react": "jest",
"test:all": "npm run lint && npm run test && npm run test:react",
"test:watch": "jest --watch",
"test:perf": "cross-env NODE_ENV=production babel-node test/perf",
Expand Down
34 changes: 0 additions & 34 deletions src/.babelrc

This file was deleted.

98 changes: 98 additions & 0 deletions src/components/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// @flow
/*
* Copyright 2018, Pavel Lang <[email protected]>
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/

import * as React from 'react';
import { hasTranslator } from '../get-translator';
import type Translator from '../translator';

function getDefaultContext(): Translator | null {
let locale: LocaleCode = 'en-US';
if (
__CLIENT__ &&
document &&
document.documentElement &&
document.documentElement.lang
) {
locale = ((document.documentElement.lang: any): LocaleCode);
}
return hasTranslator(locale);
}

export const { Consumer: IntlConsumer, Provider } = React.createContext(
getDefaultContext(),
);

type IntlProviderProps =
| {| translator: Translator, children: React.Node |}
| {| locale: LocaleCode, children: React.Node |};

type IntlProviderState = {
locale: LocaleCode,
translator: ?Translator,
nextLocale?: ?LocaleCode,
};

export class IntlProvider extends React.Component<
IntlProviderProps,
IntlProviderState,
> {
constructor(props: IntlProviderProps) {
super(props);
if (props.translator) {
this.state = {
locale: props.translator.locale,
translator: props.translator,
};
} else if (props.locale) {
this.state = {
locale: props.locale,
translator: hasTranslator(props.locale),
};
}
}

static getDerivedStateFromProps(
nextProps: IntlProviderProps,
prevState: IntlProviderState,
) {
if (
nextProps.translator &&
(!prevState || nextProps.translator !== prevState.translator)
) {
return {
locale: nextProps.translator.locale,
translator: nextProps.translator,
nextLocale: null,
};
}

if (
nextProps.locale &&
(!prevState || nextProps.locale !== prevState.locale)
) {
const translator = hasTranslator(nextProps.locale);
if (translator) {
return {
locale: nextProps.locale,
translator,
};
}
// signal that state is not in sync with props
// and new locale should be used when available
return {
nextLocale: nextProps.locale,
};
}

return null;
}

render() {
const { translator } = this.state;
return <Provider value={translator}>{this.props.children}</Provider>;
}
}
81 changes: 34 additions & 47 deletions src/components/date.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
/*
* Copyright 2015, Yahoo Inc.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {intlShape, dateTimeFormatPropTypes} from '../types';
import {invariantIntlContext, shouldIntlComponentUpdate} from '../utils';

export default class FormattedDate extends Component {
static displayName = 'FormattedDate';

static contextTypes = {
intl: intlShape,
};

static propTypes = {
...dateTimeFormatPropTypes,
value: PropTypes.any.isRequired,
format: PropTypes.string,
children: PropTypes.func,
};

constructor(props, context) {
super(props, context);
invariantIntlContext(context);
}

shouldComponentUpdate(...next) {
return shouldIntlComponentUpdate(this, ...next);
}

render() {
const {formatDate, textComponent: Text} = this.context.intl;
const {value, children} = this.props;

let formattedDate = formatDate(value, this.props);

if (typeof children === 'function') {
return children(formattedDate);
}

return <Text>{formattedDate}</Text>;
}
}
// // @flow
// /*
// * Copyright 2018, Pavel Lang <[email protected]>
// * Copyright 2015, Yahoo Inc.
// * Copyrights licensed under the New BSD License.
// * See the accompanying LICENSE file for terms.
// */
//
// import * as React from 'react';
// import { IntlConsumer } from './context';
// import type { DateTimeFormatPropTypes } from '../types';
//
// export default class FormattedDate extends React.Component<
// DateTimeFormatPropTypes,
// > {
// render() {
// const { value, children } = this.props;
// return (
// <IntlConsumer>
// {intl => {
// const { formatDate, textComponent: Text } = intl;
//
// const formattedDate = formatDate(value, this.props);
//
// if (typeof children === 'function') {
// return children(formattedDate);
// }
//
// return <Text>{formattedDate}</Text>;
// }}
// </IntlConsumer>
// );
// }
// }
88 changes: 0 additions & 88 deletions src/components/html-message.js

This file was deleted.

Loading