New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@infinite-list/data-model

Package Overview
Dependencies
Maintainers
1
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@infinite-list/data-model - npm Package Compare versions

Comparing version 0.2.29-stillness.2 to 0.2.29

3

dist/BaseLayout.d.ts

@@ -18,3 +18,2 @@ import SelectValue from '@x-oasis/select-value';

readonly _fillingMode: FillingMode;
private _recycleBufferedCount;
constructor(props: {

@@ -31,3 +30,2 @@ id: string;

recycleThreshold?: number;
recycleBufferedCount?: number;
recycleEnabled?: boolean;

@@ -38,3 +36,2 @@ });

get reservedIndices(): any[];
get recycleBufferedCount(): number;
updateReservedIndices(): void;

@@ -41,0 +38,0 @@ get persistanceIndices(): Array<number>;

@@ -11,3 +11,2 @@ export declare const DEFAULT_LAYOUT: {

export declare const DISPATCH_METRICS_THRESHOLD = 50;
export declare const RECYCLE_BUFFERED_COUNT = 2;
export declare const ON_END_REACHED_THRESHOLD = 2;

@@ -14,0 +13,0 @@ export declare const WINDOW_SIZE = 5;

@@ -39,3 +39,2 @@ import Batchinator from '@x-oasis/batchinator';

private _offsetTriggerCachedState;
private _stillnessHelper;
private memoizedResolveSpaceState;

@@ -113,30 +112,2 @@ private memoizedResolveRecycleState;

getPosition(rowIndex: number, startIndex: number, endIndex: number): number;
getRecycleReuseOffsetBuilder(props: {
minIndex: number;
topStartOffset: number;
topStartIndex: number;
bottomStartOffset: number;
bottomStartIndex: number;
}): (info: {
currentIndex: number;
length: number;
velocity: number;
}) => number;
resolveSafeRange(props: {
visibleStartIndex: number;
visibleEndIndex: number;
}): {
startIndex: number;
endIndex: number;
};
updateIndices(targetIndices: Array<number>, props: {
safeRange: {
startIndex: number;
endIndex: number;
};
startIndex: number;
maxCount: number;
step: number;
}): number;
resolveRecycleRecycleState(state: ListState<ItemT>): any[];
resolveRecycleState(state: ListState<ItemT>): {

@@ -165,6 +136,4 @@ recycleState: any[];

onEnableDispatchScrollMetrics(): void;
stillnessHandler(): void;
isStill(): void;
updateScrollMetrics(scrollMetrics?: ScrollMetrics, useCache?: boolean): void;
}
export default ListDimensions;

@@ -62,4 +62,2 @@ import BaseDimensions from '../BaseDimensions';

recycleEnabled?: boolean;
recycleBufferedCount?: number;
stillnessThreshold?: number;
dispatchMetricsThreshold?: number;

@@ -182,3 +180,2 @@ } & BaseDimensionsProps & OnEndReachedHelperProps;

targetKey: string;
targetIndex: number;
offset: number;

@@ -185,0 +182,0 @@ } & SpaceStateToken<ItemT>;

33

package.json
{
"name": "@infinite-list/data-model",
"version": "0.2.29-stillness.2",
"version": "0.2.29",
"files": [

@@ -15,21 +15,20 @@ "dist",

"devDependencies": {
"rimraf": "^5.0.1",
"rimraf": "~4.4.0",
"tsdx": "^0.14.1"
},
"dependencies": {
"@x-oasis/batchinate-last": "^0.1.10",
"@x-oasis/batchinator": "0.1.10",
"@x-oasis/capitalize": "0.1.10",
"@x-oasis/default-boolean-value": "^0.1.10",
"@x-oasis/integer-buffer-set": "0.1.10",
"@x-oasis/is-clamped": "0.1.10",
"@x-oasis/layout-equal": "0.1.10",
"@x-oasis/noop": "0.1.10",
"@x-oasis/omit": "0.1.10",
"@x-oasis/prefix-interval-tree": "^0.1.10",
"@x-oasis/resolve-changed": "0.1.10",
"@x-oasis/select-value": "0.1.10",
"@x-oasis/shallow-array-equal": "^0.1.10",
"@x-oasis/shallow-equal": "0.1.10",
"@x-oasis/unique-array-object": "^0.1.10",
"@x-oasis/batchinator": "^0.0.13",
"@x-oasis/capitalize": "^0.0.6",
"@x-oasis/default-boolean-value": "^0.1.4",
"@x-oasis/integer-buffer-set": "^0.0.19",
"@x-oasis/is-clamped": "^0.0.8",
"@x-oasis/layout-equal": "^0.0.8",
"@x-oasis/noop": "^0.0.6",
"@x-oasis/omit": "^0.0.8",
"@x-oasis/prefix-interval-tree": "^0.1.2",
"@x-oasis/resolve-changed": "^0.0.6",
"@x-oasis/select-value": "^0.0.6",
"@x-oasis/shallow-array-equal": "^0.1.6",
"@x-oasis/shallow-equal": "^0.0.6",
"@x-oasis/unique-array-object": "^0.1.2",
"memoize-one": "^6.0.0"

@@ -36,0 +35,0 @@ },

@@ -7,3 +7,2 @@ import {

WINDOW_SIZE,
RECYCLE_BUFFERED_COUNT,
} from './common';

@@ -32,3 +31,2 @@ import SelectValue, {

readonly _fillingMode: FillingMode;
private _recycleBufferedCount: number;

@@ -47,3 +45,2 @@ constructor(props: {

recycleThreshold?: number;
recycleBufferedCount?: number;
recycleEnabled?: boolean;

@@ -60,3 +57,2 @@ }) {

windowSize = WINDOW_SIZE,
recycleBufferedCount = RECYCLE_BUFFERED_COUNT,
maxToRenderPerBatch = MAX_TO_RENDER_PER_BATCH,

@@ -80,3 +76,2 @@ initialNumToRender = INITIAL_NUM_TO_RENDER,

: 0;
this._recycleBufferedCount = recycleBufferedCount;
this._stickyHeaderIndices = stickyHeaderIndices;

@@ -86,3 +81,2 @@ this._maxToRenderPerBatch = maxToRenderPerBatch;

this._onEndReachedThreshold = onEndReachedThreshold;
this._recycleBufferedCount = recycleBufferedCount;
this.persistanceIndices = persistanceIndices;

@@ -104,6 +98,2 @@ this.stickyHeaderIndices = stickyHeaderIndices;

get recycleBufferedCount() {
return this._recycleBufferedCount;
}
updateReservedIndices() {

@@ -110,0 +100,0 @@ const indices = new Set(

@@ -12,3 +12,2 @@ export const DEFAULT_LAYOUT = {

export const DISPATCH_METRICS_THRESHOLD = 50;
export const RECYCLE_BUFFERED_COUNT = 2;

@@ -15,0 +14,0 @@ // 建议 ON_END_REACHED_THRESHOLD * VisibleLength > MAX_TO_RENDER_PER_BATCH * itemLength

@@ -50,3 +50,2 @@ import noop from '@x-oasis/noop';

import shallowArrayEqual from '@x-oasis/shallow-array-equal';
import StillnessHelper from './utils/StillnessHelper';

@@ -97,3 +96,2 @@ class ListDimensions<ItemT extends {} = {}> extends BaseDimensions {

public updateStateBatchinator: Batchinator;
private _recalculateRecycleResultStateBatchinator: Batchinator;

@@ -109,4 +107,2 @@

private _stillnessHelper: StillnessHelper;
private memoizedResolveSpaceState: (

@@ -142,3 +138,2 @@ state: ListState<ItemT>

stillnessThreshold,
onEndReachedTimeoutThreshold,

@@ -170,8 +165,2 @@ distanceFromEndThresholdValue,

this.stillnessHandler = this.stillnessHandler.bind(this);
this._stillnessHelper = new StillnessHelper({
stillnessThreshold,
handler: this.stillnessHandler,
});
this._deps = deps;

@@ -1046,225 +1035,77 @@ this._isActive = this.resolveInitialActiveValue(active);

getRecycleReuseOffsetBuilder(props: {
minIndex: number;
topStartOffset: number;
topStartIndex: number;
bottomStartOffset: number;
bottomStartIndex: number;
}) {
resolveRecycleState(state: ListState<ItemT>) {
const {
minIndex,
topStartOffset: _topStartOffset,
topStartIndex: _topStartIndex,
bottomStartOffset: _bottomStartOffset,
bottomStartIndex: _bottomStartIndex,
} = props;
visibleEndIndex,
bufferedEndIndex,
visibleStartIndex,
bufferedStartIndex,
// actionType,
data,
} = state;
let topStartIndex = _topStartIndex;
let topStartOffset = _topStartOffset;
let bottomStartIndex = _bottomStartIndex;
let bottomStartOffset = _bottomStartOffset;
const targetIndices = this._bufferSet.indices.map((i) => parseInt(i));
const placeOnTop = (length: number) => {
let offset = 0;
if (topStartIndex < minIndex) {
offset = bottomStartOffset + length;
bottomStartIndex += 1;
bottomStartOffset = offset;
} else {
offset = topStartOffset - length;
if (offset >= 0) {
topStartIndex -= 1;
topStartOffset = offset;
}
}
return offset;
};
// const scrolling = actionType === 'scrollDown' || actionType === 'scrollUp';
// const originalPositionSize = this._bufferSet.getSize();
const placeOnBottom = (length: number) => {
let offset = 0;
offset = bottomStartOffset + length;
bottomStartIndex += 1;
bottomStartOffset = offset;
return offset;
};
const recycleEnabled = this._recycleEnabled();
const recycleStateResult = [];
let spaceStateResult = [];
return (info: {
currentIndex: number;
length: number;
velocity: number;
}) => {
const { velocity, currentIndex, length } = info;
// scroll up, preserve start
if (velocity < 0) {
return placeOnTop(length);
} else if (velocity > 0) {
return placeOnBottom(length);
// 只有当recycleEnabled为true的时候,才进行位置替换
if (recycleEnabled) {
if (visibleEndIndex >= 0) {
for (let index = visibleStartIndex; index <= visibleEndIndex; index++) {
const position = this.getPosition(
index,
visibleStartIndex,
visibleEndIndex
);
if (position !== null) targetIndices[position] = index;
}
}
if (currentIndex < _topStartIndex) {
return placeOnTop(length);
}
return placeOnBottom(length);
};
}
resolveSafeRange(props: {
visibleStartIndex: number;
visibleEndIndex: number;
}) {
const { visibleStartIndex, visibleEndIndex } = props;
const velocity = this._scrollMetrics?.velocity || 0;
const visibleSize = Math.max(visibleEndIndex - visibleStartIndex + 1, 0);
const beforeSize = Math.floor((this.recycleThreshold - visibleSize) / 2);
const afterSize = this.recycleThreshold - visibleSize - beforeSize;
if (velocity < 0) {
return {
startIndex: Math.max(
visibleStartIndex - this.recycleBufferedCount * 2,
0
),
endIndex: visibleEndIndex,
};
} else if (velocity > 0) {
return {
startIndex: visibleStartIndex,
endIndex: Math.min(
visibleEndIndex + this.recycleBufferedCount * 2,
this._data.length
),
};
}
return {
startIndex: Math.max(visibleStartIndex - this.recycleBufferedCount, 0),
endIndex: Math.min(
visibleEndIndex + this.recycleBufferedCount,
this._data.length
),
};
}
updateIndices(
targetIndices: Array<number>,
props: {
safeRange: {
startIndex: number;
endIndex: number;
};
startIndex: number;
maxCount: number;
step: number;
}
) {
const { startIndex, safeRange, step, maxCount } = props;
let finalIndex = startIndex;
let count = 0;
for (
let index = startIndex;
step > 0 ? index <= this._data.length - 1 : index >= 0;
index += step
) {
const item = this._data[index];
if (!item) continue;
const itemMeta = this.getItemMeta(item, index);
const itemLayout = itemMeta?.getLayout();
if (count < maxCount || !itemLayout) {
for (
let index = visibleStartIndex, size = beforeSize;
size > 0 && index >= 0 && index >= bufferedStartIndex;
size--, index--
) {
const position = this.getPosition(
index,
safeRange.startIndex,
safeRange.endIndex
visibleStartIndex,
visibleEndIndex
);
finalIndex = index;
if (position !== null) targetIndices[position] = index;
} else {
break;
}
if (index >= this.initialNumToRender) {
count++;
}
}
return finalIndex;
}
resolveRecycleRecycleState(state: ListState<ItemT>) {
const { visibleEndIndex, visibleStartIndex: _visibleStartIndex } = state;
const _targetIndices = this._bufferSet.indices.map((i) => parseInt(i));
const targetIndices = new Array(_targetIndices.length).fill(null);
const recycleStateResult = [];
const velocity = this._scrollMetrics?.velocity || 0;
const visibleStartIndex = Math.max(
_visibleStartIndex,
this.initialNumToRender
);
const safeRange = this.resolveSafeRange({
visibleStartIndex,
visibleEndIndex,
});
if (visibleEndIndex >= 0) {
for (let index = visibleStartIndex; index <= visibleEndIndex; index++) {
for (
let index = visibleEndIndex + 1, size = afterSize;
size > 0 && index <= bufferedEndIndex;
size--, index++
) {
const position = this.getPosition(
index,
safeRange.startIndex,
safeRange.endIndex
visibleStartIndex,
visibleEndIndex
);
if (position !== null) targetIndices[position] = index;
}
}
let topStartIndex = visibleStartIndex;
let bottomStartIndex = visibleEndIndex + 1;
const minValue = this._bufferSet.getMinValue();
const maxValue = this._bufferSet.getMaxValue();
const indexToOffsetMap = this.getIndexRangeOffsetMap(
minValue,
maxValue,
true
);
if (velocity > 0) {
bottomStartIndex = this.updateIndices(targetIndices, {
safeRange,
startIndex: visibleEndIndex + 1,
maxCount: this.recycleBufferedCount * 2,
step: 1,
});
} else if (velocity < 0) {
topStartIndex = this.updateIndices(targetIndices, {
safeRange,
startIndex: visibleStartIndex,
maxCount: this.recycleBufferedCount * 2,
step: -1,
});
} else {
topStartIndex = this.updateIndices(targetIndices, {
safeRange,
startIndex: visibleStartIndex,
maxCount: this.recycleBufferedCount,
step: -1,
});
bottomStartIndex = this.updateIndices(targetIndices, {
safeRange,
startIndex: visibleEndIndex + 1,
maxCount: this.recycleBufferedCount,
step: 1,
});
}
const minValue = this._bufferSet.getMinValue();
const maxValue = this._bufferSet.getMaxValue();
const indexToOffsetMap = this.getIndexRangeOffsetMap(
minValue,
maxValue,
true
);
const getOffset = this.getRecycleReuseOffsetBuilder({
topStartOffset: indexToOffsetMap[Math.max(topStartIndex, 0)] || 0,
bottomStartOffset: indexToOffsetMap[Math.max(bottomStartIndex, 0)] || 0,
minIndex: this.initialNumToRender,
topStartIndex,
bottomStartIndex,
});
targetIndices.forEach((targetIndex, index) => {
if (targetIndex == null) {
targetIndex = _targetIndices[index];
targetIndices.forEach((targetIndex, index) => {
const item = this._data[targetIndex];
if (!item) return;
const itemKey = this.getItemKey(item, targetIndex);

@@ -1276,12 +1117,16 @@ const itemMeta = this.getItemMeta(item, targetIndex);

let offset = 0;
const itemMetaState =
!this._scrollMetrics || !itemMeta?.getLayout()
? itemMeta
? itemMeta.getState()
: {}
: this._configTuple.resolveItemMetaState(
itemMeta,
this._scrollMetrics,
// should add container offset, because indexToOffsetMap containerOffset is
// exclusive.
() => indexToOffsetMap[targetIndex] + this.getContainerOffset()
);
if (this._scrollMetrics && itemLayout) {
const velocity = this._scrollMetrics.velocity;
offset = getOffset({
currentIndex: targetIndex,
length: itemLength,
velocity,
});
}
itemMeta?.setItemMetaState(itemMetaState);

@@ -1291,3 +1136,2 @@ recycleStateResult.push({

targetKey: itemKey,
targetIndex,
length: itemLength,

@@ -1300,60 +1144,13 @@ isSpace: false,

// 如果没有offset,说明item是新增的,那么它渲染就在最开始位置好了
offset: itemLayout ? offset : 0,
offset: itemLength ? indexToOffsetMap[targetIndex] : 0,
position: 'buffered',
});
return;
}
const item = this._data[targetIndex];
if (!item) return;
const itemKey = this.getItemKey(item, targetIndex);
const itemMeta = this.getItemMeta(item, targetIndex);
const itemLayout = itemMeta?.getLayout();
const itemLength =
(itemLayout?.height || 0) + (itemMeta?.getSeparatorLength() || 0);
const itemMetaState =
!this._scrollMetrics || !itemMeta?.getLayout()
? itemMeta
? itemMeta.getState()
: {}
: this._configTuple.resolveItemMetaState(
itemMeta,
this._scrollMetrics,
// should add container offset, because indexToOffsetMap containerOffset is
// exclusive.
() => indexToOffsetMap[targetIndex] + this.getContainerOffset()
);
itemMeta?.setItemMetaState(itemMetaState);
recycleStateResult.push({
key: `recycle_${index}`,
targetKey: itemKey,
targetIndex,
length: itemLength,
isSpace: false,
isSticky: false,
item,
itemMeta,
viewable: itemMeta.getState().viewable,
// 如果没有offset,说明item是新增的,那么它渲染就在最开始位置好了
offset: itemLength ? indexToOffsetMap[targetIndex] : 0,
position: 'buffered',
});
});
return recycleStateResult;
}
}
resolveRecycleState(state: ListState<ItemT>) {
const recycleEnabled = this._recycleEnabled();
// 只有当recycleEnabled为true的时候,才进行位置替换
const recycleStateResult = recycleEnabled
? this.resolveRecycleRecycleState(state)
: [];
const spaceStateResult = this.resolveRecycleSpaceState(state);
spaceStateResult = this.resolveRecycleSpaceState(state);
const stateResult = {
recycleState: recycleStateResult.filter((v) => v),
spaceState: spaceStateResult.filter((v) => v),
recycleState: recycleStateResult,
spaceState: spaceStateResult,
};

@@ -1371,10 +1168,11 @@

if (startIndex >= endIndex) return [];
const createToken = (startIndex: number) => ({
startIndex,
endIndex: startIndex + 1,
isSticky: false,
isReserved: false,
isSpace: true,
});
const tokens = [createToken(startIndex)];
const tokens = [
{
startIndex,
endIndex: startIndex + 1,
isSticky: false,
isReserved: false,
isSpace: true,
},
];

@@ -1389,3 +1187,11 @@ this.reservedIndices.forEach((index) => {

lastToken.isReserved = isReserved;
if (index + 1 !== endIndex) tokens.push(createToken(index + 1));
if (index + 1 !== endIndex) {
tokens.push({
startIndex: index + 1,
endIndex: index + 2,
isSticky: false,
isReserved: false,
isSpace: true,
});
}
} else {

@@ -1400,3 +1206,11 @@ lastToken.endIndex = index;

});
if (index + 1 !== endIndex) tokens.push(createToken(index + 1));
if (index + 1 !== endIndex) {
tokens.push({
startIndex: index + 1,
endIndex: index + 2,
isSticky: false,
isReserved: false,
isSpace: true,
});
}
}

@@ -1621,10 +1435,2 @@ }

stillnessHandler() {
this.dispatchMetrics(this._scrollMetrics);
}
isStill() {
this._stillnessHelper.isStill;
}
/**

@@ -1653,6 +1459,2 @@ * When to trigger updateScrollMetrics..

if (this._scrollMetrics?.offset !== scrollMetrics?.offset) {
// this._stillnessHelper.startClockBatchinateLast.schedule();
}
if (

@@ -1659,0 +1461,0 @@ !this._scrollMetrics ||

@@ -79,7 +79,5 @@ import BaseDimensions from '../BaseDimensions';

recycleThreshold?: number;
recycleEnabled?: boolean;
recycleBufferedCount?: number;
stillnessThreshold?: number;
dispatchMetricsThreshold?: number;

@@ -234,3 +232,2 @@ } & BaseDimensionsProps &

targetKey: string;
targetIndex: number;
offset: number;

@@ -237,0 +234,0 @@ } & SpaceStateToken<ItemT>;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc