mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-27 09:04:31 +02:00
Make cache management available in non-dev environment (#1721)
This commit is contained in:
committed by
Ian Storm Taylor
parent
c071df36ea
commit
25aa1ec952
@@ -1,16 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Is in development?
|
* GLOBAL: True if memoization should is enabled.
|
||||||
*
|
|
||||||
* @type {Boolean}
|
|
||||||
*/
|
|
||||||
|
|
||||||
const IS_DEV =
|
|
||||||
typeof process !== 'undefined' &&
|
|
||||||
process.env &&
|
|
||||||
process.env.NODE_ENV !== 'production'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GLOBAL: True if memoization should is enabled. Only effective when `IS_DEV`.
|
|
||||||
*
|
*
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
*/
|
*/
|
||||||
@@ -19,7 +8,6 @@ let ENABLED = true
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* GLOBAL: Changing this cache key will clear all previous cached results.
|
* GLOBAL: Changing this cache key will clear all previous cached results.
|
||||||
* Only effective when `IS_DEV`.
|
|
||||||
*
|
*
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
@@ -69,16 +57,14 @@ function memoize(object, properties) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object[property] = function(...args) {
|
object[property] = function(...args) {
|
||||||
if (IS_DEV) {
|
// If memoization is disabled, call into the original method.
|
||||||
// If memoization is disabled, call into the original method.
|
if (!ENABLED) return original.apply(this, args)
|
||||||
if (!ENABLED) return original.apply(this, args)
|
|
||||||
|
|
||||||
// If the cache key is different, previous caches must be cleared.
|
// If the cache key is different, previous caches must be cleared.
|
||||||
if (CACHE_KEY !== this.__cache_key) {
|
if (CACHE_KEY !== this.__cache_key) {
|
||||||
this.__cache_key = CACHE_KEY
|
this.__cache_key = CACHE_KEY
|
||||||
this.__cache = new Map() // eslint-disable-line no-undef,no-restricted-globals
|
this.__cache = new Map() // eslint-disable-line no-undef,no-restricted-globals
|
||||||
this.__cache_no_args = {}
|
this.__cache_no_args = {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.__cache) {
|
if (!this.__cache) {
|
||||||
|
Reference in New Issue
Block a user