|
1 |
| -var React = require('react'); |
2 | 1 | var Globalize = require('globalize');
|
| 2 | +var mixins = {}; |
3 | 3 |
|
4 | 4 | Object.getOwnPropertyNames(Globalize).forEach(function(fn) {
|
5 | 5 | if (fn.indexOf("format") === 0) {
|
6 |
| - var fnString = Globalize[fn].toString(), |
7 |
| - argString = fnString.substr(fnString.indexOf('(')+1, fnString.indexOf(')')-(fnString.indexOf('(')+1)).trim(), |
8 |
| - argArray = argString.split(', '); |
| 6 | + var fnString = Globalize[fn].toString(); |
| 7 | + var argString = fnString.substr(fnString.indexOf('(')+1, fnString.indexOf(')')-(fnString.indexOf('(')+1)).trim(); |
| 8 | + var argArray = argString.split(', '); |
9 | 9 |
|
10 | 10 | (function(currentFn, currentArgs) {
|
11 |
| - module.exports[currentFn.charAt(0).toUpperCase() + currentFn.slice(1)] = React.createClass({ |
12 |
| - currentArgs: currentArgs, |
13 |
| - render: function() { |
14 |
| - var that = this; |
15 |
| - var propArgs = this.currentArgs.map(function(element) { |
16 |
| - return that.props[element.replace(/(\s\/\*|\*\/)/,'')]; |
17 |
| - }); |
| 11 | + var formatter = function(nextProps) { |
| 12 | + var componentProps = nextProps || this.props; |
| 13 | + var propArgs = currentArgs.map(function(element) { |
| 14 | + return componentProps[element.replace(/(\s\/\*|\*\/)/,'')]; |
| 15 | + }); |
18 | 16 |
|
19 |
| - // set locale |
20 |
| - Globalize.locale( this.props.locale ); |
| 17 | + Globalize.locale( componentProps["locale"] ); |
| 18 | + this.setState({ |
| 19 | + formattedValue: Globalize[currentFn].apply(Globalize, propArgs) |
| 20 | + }); |
| 21 | + }; |
21 | 22 |
|
22 |
| - return ( |
23 |
| - React.createElement("span", null, Globalize[currentFn].apply(Globalize, propArgs)) |
24 |
| - ); |
25 |
| - } |
26 |
| - }); |
| 23 | + mixins[currentFn] = { |
| 24 | + componentWillMount: formatter, |
| 25 | + componentWillReceiveProps: formatter |
| 26 | + }; |
27 | 27 | })(fn, argArray);
|
28 | 28 | }
|
29 | 29 | });
|
| 30 | +module.exports = mixins; |
0 commit comments