Skip to content

Commit e6f496f

Browse files
committed
add extra param to sync for ansyc
1 parent 2141c50 commit e6f496f

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/utils/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ function genUuid () {
120120
* @param {DomElement} table - will have a tr for each thing
121121
* @param {Array<NamedNode>} things - ORDERED array of NamedNode objects
122122
* @param {function({NamedNode})} createNewRow(thing) returns a TR table row for a new thing
123+
* @param {function(DomElement, NamedNode)} updateExistingRow(row, thing) optional hook for refreshing matched rows
123124
*
124125
* Tolerates out of order elements but puts new ones in order.
125126
* Can be used for any element type; does not have to be a table and tr.
126127
*/
127-
function syncTableToArray (table, things, createNewRow) {
128+
function syncTableToArray (table, things, createNewRow, updateExistingRow) {
128129
let foundOne
129130
let row
130131
let i
@@ -141,6 +142,14 @@ function syncTableToArray (table, things, createNewRow) {
141142
for (i = 0; i < table.children.length; i++) {
142143
row = table.children[i]
143144
if (row.subject && row.subject.sameTerm(thing)) {
145+
if (updateExistingRow) {
146+
const replacement = updateExistingRow(row, thing)
147+
if (replacement && replacement !== row) {
148+
row.parentNode.replaceChild(replacement, row)
149+
replacement.subject = thing
150+
row = replacement
151+
}
152+
}
144153
row.trashMe = false
145154
foundOne = true
146155
break

0 commit comments

Comments
 (0)