Repository: wagtail/wagtail
File: client/src/components/StreamField/blocks/StreamBlock.js (JavaScript)

Code before:
    // The control at index n will insert a block at index n
    this.inserters = [];

    // Incrementing counter used to generate block prefixes, also reflected in the
    // 'count' hidden input. This count includes deleted items
    this.blockCounter = 0;
    this.countInput = dom.find('[data-streamfield-stream-count]');

    // Parent element of insert control and block elements (potentially including deleted items,
    // which are left behind as hidden elements with a '-deleted' input so that the
    // server-side form handler knows to skip it)
    this.sequenceContainer = dom.find('[data-streamfield-stream-container]');
    this.setState(initialState || []);
    if (this.blockDef.meta.collapsed) {
      this.children.forEach((block) => {
        block.collapse();
      });
    }

    if (initialError) {
      this.setError(initialError);
    }

    this.initDragNDrop();

    setAttrs(this.container, this.blockDef.meta.attrs || {});
  }

  getBlockGroups() {
    return this.blockDef.groupedChildBlockDefs;
  }

  getBlockCount(type) {
    // Get the block count for a particular type, or if none is provided, the total block count
    if (!type) {
      return this.children.length;
    }
    if (!this.childBlockCounts.has(type)) {
      this._updateBlockCount(type);
    }
    return this.childBlockCounts.get(type) || 0;
  }

  getBlockMax(type) {
    // Get the maximum number of blocks allowable for a particular type, or if none is provided, the total maximum
    if (!type) {
      return this.blockDef.meta.maxNum;
    }
    return this.blockDef.meta.blockCounts[type]?.max_num;
  }


Review comment (suggestion):
I was wondering why TypeScript didn’t raise alarm balls about this. Turns out we’re inside a `.js` file!

Code after:
    // The control at index n will insert a block at index n
    this.inserters = [];

    // Incrementing counter used to generate block prefixes, also reflected in the
    // 'count' hidden input. This count includes deleted items
    this.blockCounter = 0;
    this.countInput = dom.find('[data-streamfield-stream-count]');

    // Parent element of insert control and block elements (potentially including deleted items,
    // which are left behind as hidden elements with a '-deleted' input so that the
    // server-side form handler knows to skip it)
    this.sequenceContainer = dom.find('[data-streamfield-stream-container]');
    this.setState(initialState || []);
    if (this.blockDef.meta.collapsed) {
      this.children.forEach((block) => {
        block.collapse();
      });
    }

    if (initialError) {
      this.setError(initialError);
    }

    this.initDragNDrop();

    setAttrs(this.container[0], this.blockDef.meta.attrs || {});
  }

  getBlockGroups() {
    return this.blockDef.groupedChildBlockDefs;
  }

  getBlockCount(type) {
    // Get the block count for a particular type, or if none is provided, the total block count
    if (!type) {
      return this.children.length;
    }
    if (!this.childBlockCounts.has(type)) {
      this._updateBlockCount(type);
    }
    return this.childBlockCounts.get(type) || 0;
  }

  getBlockMax(type) {
    // Get the maximum number of blocks allowable for a particular type, or if none is provided, the total maximum
    if (!type) {
      return this.blockDef.meta.maxNum;
    }
    return this.blockDef.meta.blockCounts[type]?.max_num;
  }