Sha256: 29e57445e31f02ec8dd4deb8fb5b69db6177f979058fd782432514b65cbbe421

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

import { EMBER_METAL_TRACKED_PROPERTIES } from '@ember/canary-features';
const COMPUTED_PROPERTY_CACHED_VALUES = new WeakMap();
const COMPUTED_PROPERTY_LAST_REVISION = EMBER_METAL_TRACKED_PROPERTIES
    ? new WeakMap()
    : undefined;
/**
  Returns the cached value for a property, if one exists.
  This can be useful for peeking at the value of a computed
  property that is generated lazily, without accidentally causing
  it to be created.

  @method cacheFor
  @static
  @for @ember/object/internals
  @param {Object} obj the object whose property you want to check
  @param {String} key the name of the property whose cached value you want
    to return
  @return {Object} the cached value
  @public
*/
export function getCacheFor(obj) {
    let cache = COMPUTED_PROPERTY_CACHED_VALUES.get(obj);
    if (cache === undefined) {
        cache = new Map();
        if (EMBER_METAL_TRACKED_PROPERTIES) {
            COMPUTED_PROPERTY_LAST_REVISION.set(obj, new Map());
        }
        COMPUTED_PROPERTY_CACHED_VALUES.set(obj, cache);
    }
    return cache;
}
export function getCachedValueFor(obj, key) {
    let cache = COMPUTED_PROPERTY_CACHED_VALUES.get(obj);
    if (cache !== undefined) {
        return cache.get(key);
    }
}
export let setLastRevisionFor;
export let getLastRevisionFor;
if (EMBER_METAL_TRACKED_PROPERTIES) {
    setLastRevisionFor = (obj, key, revision) => {
        let lastRevision = COMPUTED_PROPERTY_LAST_REVISION.get(obj);
        lastRevision.set(key, revision);
    };
    getLastRevisionFor = (obj, key) => {
        let cache = COMPUTED_PROPERTY_LAST_REVISION.get(obj);
        if (cache === undefined) {
            return 0;
        }
        else {
            let revision = cache.get(key);
            return revision === undefined ? 0 : revision;
        }
    };
}
export function peekCacheFor(obj) {
    return COMPUTED_PROPERTY_CACHED_VALUES.get(obj);
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/@ember/-internals/metal/lib/computed_cache.js
discourse-ember-source-3.5.1.1 dist/es/ember-metal/lib/computed_cache.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-metal/lib/computed_cache.js