set()

in js/index.js [499:545]


  set(options = {}, callback = _.noop) {
    const isSet = key => !_.isUndefined(options[key]);
    const itemHeightsCur = this._itemHeights;
    let invalidation = 0;

    _.extend(this.options, options);

    if (_.some(['model', 'listTemplate'], isSet)) {
      invalidation |= INVALIDATION_ALL;
    } else {
      if (_.some(['items', 'itemTemplate', 'defaultItemHeight'], isSet)) {
        if (isSet('defaultItemHeight') ||
          this.itemHeights.maxVal !== this.length) {
          this._itemHeights = null;
        }
        invalidation |= INVALIDATION_ITEMS;
      }
      if (isSet('events')) {
        invalidation |= INVALIDATION_EVENTS;
      }
    }

    if (invalidation) {
      if (this.viewport && this.$topFiller && this.$topFiller.length > 0 && itemHeightsCur) {
        const visibleTop = this.viewport.getMetrics().outer.top;
        const listTopCur = this.$topFiller.get(0).getBoundingClientRect().top;
        const visibleFirst = itemHeightsCur.lowerBound(visibleTop - listTopCur);

        if (visibleFirst < this.length) {
          const el = this.elementAt(visibleFirst);
          if (el) {
            const elTop = el.getBoundingClientRect().top;
            this._state.anchor = {
              index: visibleFirst,
              top: elTop,
            };
          }
        }
      }

      this._invalidate(invalidation, callback);
    } else {
      callback();
    }

    return this;
  }