@srfnstack/fntags 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/fntags.mjs +6 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srfnstack/fntags",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "author": "Robert Kempton <r@snow87.com>",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/srfnstack/fntags",
package/src/fntags.mjs CHANGED
@@ -277,7 +277,7 @@ function doSubscribe (callback) {
277
277
 
278
278
  const subscribeSelect = (ctx, callback) => {
279
279
  const parentCtx = ctx.state.parentCtx
280
- const key = keyMapper(parentCtx.mapKey, ctx.currentValue)
280
+ const key = keyMapper(parentCtx.mapKey, ctx.currentValue, 0)
281
281
  if (parentCtx.selectObservers[key] === undefined) {
282
282
  parentCtx.selectObservers[key] = []
283
283
  }
@@ -410,7 +410,7 @@ function doBindChildren (parent, element) {
410
410
  }
411
411
  if (typeof ctx.mapKey !== 'function') {
412
412
  console.warn('Using value index as key, may not work correctly when moving items...')
413
- ctx.mapKey = (o, i) => i
413
+ ctx.mapKey = (_, i) => i
414
414
  }
415
415
 
416
416
  if (!Array.isArray(ctx.currentValue)) {
@@ -541,13 +541,13 @@ function reconcile (ctx, oldState) {
541
541
  }
542
542
  }
543
543
 
544
- function keyMapper (mapKey, value) {
544
+ function keyMapper (mapKey, value, i) {
545
545
  if (typeof value !== 'object') {
546
546
  return value
547
547
  } else if (typeof mapKey !== 'function') {
548
548
  return 0
549
549
  } else {
550
- return mapKey(value)
550
+ return mapKey(value, i)
551
551
  }
552
552
  }
553
553
 
@@ -585,7 +585,7 @@ function arrangeElements (ctx, bindContext, oldState) {
585
585
  for (let i = 0; i < ctx.currentValue.length; i++) {
586
586
  const rawValue = ctx.currentValue[i]
587
587
  // Use the raw value to get the key
588
- const key = keyMapper(ctx.mapKey, rawValue)
588
+ const key = keyMapper(ctx.mapKey, rawValue, i)
589
589
 
590
590
  if (keys[key]) {
591
591
  if (oldState) ctx.state(oldState)
@@ -610,7 +610,7 @@ function arrangeElements (ctx, bindContext, oldState) {
610
610
  if (!Array.isArray(currentArr)) return
611
611
 
612
612
  // find the element dynamically because sorting/filtering might have shifted the index
613
- const idx = currentArr.findIndex(item => keyMapper(ctx.mapKey, item) === key)
613
+ const idx = currentArr.findIndex((item, i) => keyMapper(ctx.mapKey, item, i) === key)
614
614
 
615
615
  if (idx > -1 && currentArr[idx] !== newItem) {
616
616
  currentArr[idx] = newItem