Skip to content

Commit

Permalink
Switch from WeakMap to Map
Browse files Browse the repository at this point in the history
  • Loading branch information
Demivan committed May 28, 2021
1 parent f846488 commit b2aa025
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions fluent-bundle/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FluentResource } from "./resource.js";
import { FluentValue, FluentNone, FluentFunction } from "./types.js";
import { Message, Term, Pattern } from "./ast.js";
import { NUMBER, DATETIME } from "./builtins.js";
import { getMemoizerForLocale } from "./memoizer.js";
import { getMemoizerForLocale, IntlCache } from "./memoizer.js";

export type TextTransform = (text: string) => string;

Expand All @@ -23,7 +23,7 @@ export class FluentBundle {
public _functions: Record<string, FluentFunction>;
public _useIsolating: boolean;
public _transform: TextTransform;
public _intls: WeakMap<object, Record<string, object>>;
public _intls: IntlCache;

/**
* Create an instance of `FluentBundle`.
Expand Down
4 changes: 2 additions & 2 deletions fluent-bundle/src/memoizer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
type IntlCache = WeakMap<object, Record<string, object>>;
export type IntlCache = Map<object, Record<string, object>>;

const cache = new Map<string, IntlCache>();

export function getMemoizerForLocale(locales: string | string[]): IntlCache {
const stringLocale = Array.isArray(locales) ? locales.join(" ") : locales;
let memoizer = cache.get(stringLocale);
if (memoizer === undefined) {
memoizer = new WeakMap();
memoizer = new Map();
cache.set(stringLocale, memoizer);
}

Expand Down

0 comments on commit b2aa025

Please sign in to comment.