Maybe just make this `type: (replacing ? "elementReplace" : "elementInsert")` and eliminate the `if` below?