@react-aria/i18n 3.3.2 → 3.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/i18n",
3
- "version": "3.3.2",
3
+ "version": "3.3.6",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -18,11 +18,12 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.6.2",
21
- "@internationalized/message": "^3.0.2",
22
- "@internationalized/number": "^3.0.2",
23
- "@react-aria/ssr": "^3.0.3",
24
- "@react-aria/utils": "^3.8.2",
25
- "@react-types/shared": "^3.8.0"
21
+ "@internationalized/date": "3.0.0-alpha.3",
22
+ "@internationalized/message": "^3.0.5",
23
+ "@internationalized/number": "^3.0.5",
24
+ "@react-aria/ssr": "^3.1.2",
25
+ "@react-aria/utils": "^3.11.2",
26
+ "@react-types/shared": "^3.11.1"
26
27
  },
27
28
  "peerDependencies": {
28
29
  "react": "^16.8.0 || ^17.0.0-rc.1"
@@ -30,5 +31,5 @@
30
31
  "publishConfig": {
31
32
  "access": "public"
32
33
  },
33
- "gitHead": "9204e1b8cb61dac767e91087fb16203611dc67c5"
34
+ "gitHead": "404d41859b7d6f56201d7fc01bd9f22ae3512937"
34
35
  }
@@ -10,33 +10,48 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ import {DateFormatter} from '@internationalized/date';
13
14
  import {useLocale} from './context';
15
+ import {useMemo, useRef} from 'react';
14
16
 
15
17
  interface DateFormatterOptions extends Intl.DateTimeFormatOptions {
16
18
  calendar?: string
17
19
  }
18
20
 
19
- let formatterCache = new Map<string, Intl.DateTimeFormat>();
20
-
21
21
  /**
22
22
  * Provides localized date formatting for the current locale. Automatically updates when the locale changes,
23
23
  * and handles caching of the date formatter for performance.
24
24
  * @param options - Formatting options.
25
25
  */
26
- export function useDateFormatter(options?: DateFormatterOptions): Intl.DateTimeFormat {
26
+ export function useDateFormatter(options?: DateFormatterOptions): DateFormatter {
27
+ // Reuse last options object if it is shallowly equal, which allows the useMemo result to also be reused.
28
+ let lastOptions = useRef(null);
29
+ if (options && lastOptions.current && isEqual(options, lastOptions.current)) {
30
+ options = lastOptions.current;
31
+ }
32
+
33
+ lastOptions.current = options;
34
+
27
35
  let {locale} = useLocale();
36
+ return useMemo(() => new DateFormatter(locale, options), [locale, options]);
37
+ }
38
+
39
+ function isEqual(a: DateFormatterOptions, b: DateFormatterOptions) {
40
+ if (a === b) {
41
+ return true;
42
+ }
28
43
 
29
- // Polyfill the `calendar` option - not supported in Safari.
30
- if (options?.calendar && !locale.includes('-u-ca-')) {
31
- locale += '-u-ca-' + options.calendar;
44
+ let aKeys = Object.keys(a);
45
+ let bKeys = Object.keys(b);
46
+ if (aKeys.length !== bKeys.length) {
47
+ return false;
32
48
  }
33
49
 
34
- let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
35
- if (formatterCache.has(cacheKey)) {
36
- return formatterCache.get(cacheKey);
50
+ for (let key of aKeys) {
51
+ if (b[key] !== a[key]) {
52
+ return false;
53
+ }
37
54
  }
38
55
 
39
- let formatter = new Intl.DateTimeFormat(locale, options);
40
- formatterCache.set(cacheKey, formatter);
41
- return formatter;
56
+ return true;
42
57
  }