# All files / lib/tasks should-update.js

100% Statements 24/24
100% Branches 7/7
100% Functions 1/1
100% Lines 24/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    252x
    2x
    2x
    2x
    2x
    2x
    2x
    2x
    228x
    228x
    228x
    228x
    228x
    228x
    228x
    228x
    228x
    228x
    228x
    2x
    2x
    226x
    226x
    228x
     import Transaction from "../transaction";

    /**
     * Allows the transaction to terminate early if no contents have changed.
     *
     * @param {Transaction} transaction
     */
    export default function shouldUpdate(transaction) {
      const { mount, input, state: { measure }, config: options } = transaction;
      const prop = options.inner ? 'innerHTML' : 'outerHTML';

      measure('should update');

      const mountAsHTMLEl = /** @type {HTMLElement} */ (mount);

      // If the contents haven't changed, abort the flow. Only support this if
      // the new markup is a string, otherwise it's possible for our object
      // recycling to match twice.
      if (typeof input === 'string' && mountAsHTMLEl[prop]=== input) {
        return transaction.abort(true);
      }

      measure('should update');
    }