Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81152 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule memoizeStringOnly
10
* @typechecks static-only
11
*/
12
13
"use strict";
14
15
/**
16
* Memoizes the return value of a function that accepts one string argument.
17
*
18
* @param {function} callback
19
* @return {function}
20
*/
21
function memoizeStringOnly(callback) {
22
var cache = {};
23
return function(string) {
24
if (cache.hasOwnProperty(string)) {
25
return cache[string];
26
} else {
27
return cache[string] = callback.call(this, string);
28
}
29
};
30
}
31
32
module.exports = memoizeStringOnly;
33
34