How to use the @glimmer/reference.validate function in @glimmer/reference

To help you get started, we’ve selected a few @glimmer/reference examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emberjs / ember.js / packages / @ember / -internals / metal / lib / alias.ts View on Github external
get(obj: object, keyName: string): any {
    let ret: any;

    let propertyTag = tagForProperty(obj, keyName) as UpdatableTag;

    // We don't use the tag since CPs are not automatic, we just want to avoid
    // anything tracking while we get the altKey
    untrack(() => {
      ret = get(obj, this.altKey);
    });

    let lastRevision = getLastRevisionFor(obj, keyName);

    if (!validate(propertyTag, lastRevision)) {
      update(propertyTag, combine(getChainTagsForKey(obj, this.altKey)));
      setLastRevisionFor(obj, keyName, value(propertyTag));
      finishLazyChains(obj, keyName, ret);
    }

    consume(propertyTag);

    return ret;
  }
github emberjs / ember.js / packages / @ember / -internals / metal / lib / chain-tags.ts View on Github external
// lookup the value to chain off of like normal.

      if (!(segment in current) && typeof current.unknownProperty === 'function') {
        current = current.unknownProperty(segment);
      } else {
        current = current[segment];
      }
    } else {
      // If the descriptor is defined, then its a normal CP (not an alias, which
      // would have been handled earlier). We get the last revision to check if
      // the CP is still valid, and if so we use the cached value. If not, then
      // we create a lazy chain lookup, and the next time the CP is caluculated,
      // it will update that lazy chain.
      let lastRevision = getLastRevisionFor(current, segment);

      if (validate(propertyTag, lastRevision)) {
        current = peekCacheFor(current).get(segment);
      } else {
        let lazyChains = metaFor(current).writableLazyChainsFor(segment);

        let rest = path.substr(segmentEnd + 1);

        let placeholderTag = lazyChains[rest];

        if (placeholderTag === undefined) {
          placeholderTag = lazyChains[rest] = createUpdatableTag();
        }

        chainTags.push(placeholderTag);

        break;
      }
github emberjs / ember.js / packages / @ember / -internals / metal / lib / computed.ts View on Github external
get(obj: object, keyName: string): any {
    if (this._volatile) {
      return this._getter!.call(obj, keyName);
    }

    let cache = getCacheFor(obj);
    let propertyTag = tagForProperty(obj, keyName) as UpdatableTag;

    let ret;

    if (cache.has(keyName) && validate(propertyTag, getLastRevisionFor(obj, keyName))) {
      ret = cache.get(keyName);
    } else {
      // For backwards compatibility, we only throw if the CP has any dependencies. CPs without dependencies
      // should be allowed, even after the object has been destroyed, which is why we check _dependentKeys.
      assert(
        `Attempted to access the computed ${obj}.${keyName} on a destroyed object, which is not allowed`,
        this._dependentKeys === undefined || !metaFor(obj).isMetaDestroyed()
      );

      let upstreamTag: Tag | undefined = undefined;

      if (this._auto === true) {
        upstreamTag = track(() => {
          ret = this._getter!.call(obj, keyName);
        });
      } else {
github emberjs / ember.js / packages / @ember / -internals / runtime / lib / system / array_proxy.js View on Github external
_revalidate() {
    if (
      !this._arrangedContentIsUpdating &&
      !validate(this._arrangedContentTag, this._arrangedContentRevision)
    ) {
      this._arrangedContentIsUpdating = true;
      this._updateArrangedContentArray();
      this._arrangedContentIsUpdating = false;

      this._arrangedContentTag = combine(getChainTagsForKey(this, 'arrangedContent'));
      this._arrangedContentRevision = value(this._arrangedContentTag);
    }
  }
}
github emberjs / ember.js / packages / @ember / -internals / metal / lib / observer.ts View on Github external
activeObservers.forEach((observer, eventName) => {
      if (!validate(observer.tag, observer.lastRevision)) {
        let sendObserver = () => {
          try {
            sendEvent(target, eventName, [target, observer.path]);
          } finally {
            observer.tag = combine(getChainTagsForKey(target, observer.path));
            observer.lastRevision = value(observer.tag);
          }
        };

        if (shouldSchedule) {
          schedule('actions', sendObserver);
        } else {
          sendObserver();
        }
      }
    });