Huge News!Announcing our $40M Series B led by Abstract Ventures.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.17-stillness.0 to 0.2.18

1

dist/common.d.ts

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

export declare const ON_END_REACHED_HANDLER_TIMEOUT_THRESHOLD = 1000;
export declare const DISPATCH_METRICS_THRESHOLD = 50;
export declare const ON_END_REACHED_THRESHOLD = 2;

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

4

dist/ListDimensions.d.ts

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

private _offsetTriggerCachedState;
private _stillnessHelper;
private memoizedResolveSpaceState;

@@ -99,2 +98,3 @@ private memoizedResolveRecycleState;

addStateListener(listener: StateListener<ItemT>): () => void;
applyStateResult(stateResult: ListStateResult<ItemT>): void;
setState(state: ListState<ItemT>, force?: boolean): void;

@@ -134,6 +134,4 @@ createSpaceStateToken(options?: Partial<SpaceStateToken<ItemT>>): {

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

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

recycleEnabled?: boolean;
stillnessThreshold?: number;
dispatchMetricsThreshold?: number;
} & BaseDimensionsProps & OnEndReachedHelperProps;

@@ -170,5 +168,3 @@ export declare type ItemsDimensionsProps = BaseDimensionsProps;

export declare type SpaceStateTokenPosition = 'before' | 'buffered' | 'after';
export declare type SpaceStateToken<ItemT, ViewabilityState = {
viewable: boolean;
}> = {
export declare type SpaceStateToken<ItemT> = {
item: ItemT;

@@ -181,21 +177,12 @@ key: string;

position: SpaceStateTokenPosition;
} & ViewabilityState;
export declare type RecycleStateToken<ItemT, ViewabilityState = {
viewable: boolean;
}> = {
};
export declare type RecycleStateToken<ItemT> = {
targetKey: string;
targetIndex: number;
offset: number;
} & SpaceStateToken<ItemT, ViewabilityState>;
export declare type SpaceStateResult<ItemT, ViewabilityState = {
viewable: boolean;
}> = Array<SpaceStateToken<ItemT, ViewabilityState>>;
export declare type RecycleState<ItemT, ViewabilityState = {
viewable: boolean;
}> = Array<RecycleStateToken<ItemT, ViewabilityState>>;
export declare type RecycleStateResult<ItemT, ViewabilityState = {
viewable: boolean;
}> = {
spaceState: SpaceStateResult<ItemT, ViewabilityState>;
recycleState: RecycleState<ItemT, ViewabilityState>;
} & SpaceStateToken<ItemT>;
export declare type SpaceStateResult<ItemT> = Array<SpaceStateToken<ItemT>>;
export declare type RecycleState<ItemT> = Array<RecycleStateToken<ItemT>>;
export declare type RecycleStateResult<ItemT> = {
spaceState: SpaceStateResult<ItemT>;
recycleState: RecycleState<ItemT>;
};

@@ -202,0 +189,0 @@ export declare type ListStateResult<ItemT> = SpaceStateResult<ItemT> | RecycleStateResult<ItemT>;

{
"name": "@infinite-list/data-model",
"version": "0.2.17-stillness.0",
"version": "0.2.18",
"files": [

@@ -30,3 +30,3 @@ "dist",

"@x-oasis/select-value": "^0.0.6",
"@x-oasis/shallow-array-equal": "^0.0.6",
"@x-oasis/shallow-array-equal": "^0.1.6",
"@x-oasis/shallow-equal": "^0.0.6",

@@ -33,0 +33,0 @@ "@x-oasis/unique-array-object": "^0.1.2",

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

export const DISPATCH_METRICS_THRESHOLD = 50;
// 建议 ON_END_REACHED_THRESHOLD * VisibleLength > MAX_TO_RENDER_PER_BATCH * itemLength

@@ -16,0 +14,0 @@ // 这样可以在滚动停止的时候,自动获取一屏幕

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

buildStateTokenIndexKey,
DISPATCH_METRICS_THRESHOLD,
} from './common';

@@ -49,3 +48,4 @@ import resolveChanged from '@x-oasis/resolve-changed';

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

@@ -104,4 +104,2 @@ class ListDimensions<ItemT extends {} = {}> extends BaseDimensions {

private _stillnessHelper: StillnessHelper;
private memoizedResolveSpaceState: (

@@ -133,6 +131,4 @@ state: ListState<ItemT>

persistanceIndices,
stillnessThreshold,
onEndReachedTimeoutThreshold,
onEndReachedHandlerTimeoutThreshold,
dispatchMetricsThreshold = DISPATCH_METRICS_THRESHOLD,
} = props;

@@ -147,3 +143,3 @@ this._keyExtractor = keyExtractor;

this.dispatchMetrics.bind(this),
dispatchMetricsThreshold
50
);

@@ -158,8 +154,2 @@ this.onEndReachedHelper = new OnEndReachedHelper({

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

@@ -869,2 +859,33 @@ this._isActive = this.resolveInitialActiveValue(active);

applyStateResult(stateResult: ListStateResult<ItemT>) {
let shouldStateUpdate = false;
if (!this._stateResult && stateResult) {
shouldStateUpdate = true;
} else if (this.fillingMode === FillingMode.SPACE) {
shouldStateUpdate = !shallowEqual(stateResult, this._stateResult);
} else if (this.fillingMode === FillingMode.RECYCLE) {
const _stateResult = stateResult as RecycleStateResult<ItemT>;
const _oldStateResult = this._stateResult as RecycleStateResult<ItemT>;
shouldStateUpdate = !(
shallowArrayEqual(
_stateResult.recycleState,
_oldStateResult.recycleState,
shallowEqual
) &&
shallowArrayEqual(
_stateResult.spaceState,
_oldStateResult.spaceState,
shallowEqual
)
);
}
if (shouldStateUpdate && typeof this._stateListener === 'function') {
this._stateListener(stateResult, this._stateResult);
}
this._stateResult = stateResult;
}
setState(state: ListState<ItemT>, force = false) {

@@ -875,6 +896,3 @@ if (this.fillingMode === FillingMode.SPACE) {

: this.memoizedResolveSpaceState(state);
if (typeof this._stateListener === 'function') {
this._stateListener(stateResult, this._stateResult);
}
this._stateResult = stateResult;
this.applyStateResult(stateResult);
} else if (this.fillingMode === FillingMode.RECYCLE) {

@@ -884,6 +902,3 @@ const stateResult = force

: this.memoizedResolveRecycleState(state);
if (typeof this._stateListener === 'function') {
this._stateListener(stateResult, this._stateResult);
}
this._stateResult = stateResult;
this.applyStateResult(stateResult);
}

@@ -965,4 +980,3 @@ }

const _targetIndices = this._bufferSet.indices.map((i) => parseInt(i));
const targetIndices = new Array(_targetIndices.length).fill(null);
const targetIndices = this._bufferSet.indices.map((i) => parseInt(i));

@@ -982,4 +996,4 @@ // const scrolling = actionType === 'scrollDown' || actionType === 'scrollUp';

index,
visibleStartIndex - 2,
visibleEndIndex + 2
visibleStartIndex,
visibleEndIndex
);

@@ -994,4 +1008,2 @@ if (position !== null) targetIndices[position] = index;

let _beforeCount = 0;
for (

@@ -1002,24 +1014,11 @@ let index = visibleStartIndex, size = beforeSize;

) {
const item = data[index];
if (!item) continue;
const itemMeta = this.getItemMeta(item, index);
const itemLayout = itemMeta?.getLayout();
const position = this.getPosition(
index,
bufferedStartIndex,
visibleStartIndex
);
if (_beforeCount < 2 || !itemLayout) {
const position = this.getPosition(
index,
visibleStartIndex - 2,
visibleStartIndex
);
if (position !== null) targetIndices[position] = index;
}
if (index >= this.initialNumToRender) {
_beforeCount++;
}
if (position !== null) targetIndices[position] = index;
}
let _afterCount = 0;
for (

@@ -1030,19 +1029,8 @@ let index = visibleEndIndex + 1, size = afterSize;

) {
const item = data[index];
if (!item) continue;
const itemMeta = this.getItemMeta(item, index);
const itemLayout = itemMeta?.getLayout();
if (_afterCount < 2 || !itemLayout) {
const position = this.getPosition(
index,
visibleEndIndex + 1,
visibleEndIndex + 2
);
if (position !== null) targetIndices[position] = index;
}
if (index >= this.initialNumToRender) {
_afterCount++;
}
const position = this.getPosition(
index,
visibleEndIndex + 1,
bufferedEndIndex
);
if (position !== null) targetIndices[position] = index;
}

@@ -1058,35 +1046,3 @@

let negativeStartIndex = visibleStartIndex - 3;
let positiveStartIndex = visibleEndIndex + 3;
targetIndices.forEach((targetIndex, index) => {
const prevStateResult = this._stateResult as RecycleStateResult<ItemT>;
// targetIndex is null or undefined
if (targetIndex == null) {
if (prevStateResult?.recycleState) {
const _result = prevStateResult.recycleState[index];
if (_result) {
const { item, targetKey } = _result;
// maybe item has been deleted
if (item === this._data[this.getKeyIndex(targetKey)]) {
const { targetIndex, offset: _offset } =
prevStateResult.recycleState[index];
if (targetIndex < visibleStartIndex) {
const offset = indexToOffsetMap[negativeStartIndex--];
recycleStateResult.push({
...prevStateResult.recycleState[index],
offset: offset || _offset,
});
} else if (targetIndex > visibleStartIndex) {
const offset = indexToOffsetMap[positiveStartIndex++];
recycleStateResult.push({
...prevStateResult.recycleState[index],
offset: offset || _offset,
});
}
}
}
}
return;
}
const item = data[targetIndex];

@@ -1119,3 +1075,2 @@ if (!item) return;

targetKey: itemKey,
targetIndex,
length: itemLength,

@@ -1136,4 +1091,4 @@ isSpace: false,

const stateResult = {
recycleState: recycleStateResult.filter((v) => v),
spaceState: spaceStateResult.filter((v) => v),
recycleState: recycleStateResult,
spaceState: spaceStateResult,
};

@@ -1308,3 +1263,3 @@

length: itemLength,
...itemMetaState,
// ...itemMetaState,
});

@@ -1408,10 +1363,2 @@ });

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

@@ -1440,6 +1387,2 @@ * When to trigger updateScrollMetrics..

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

@@ -1446,0 +1389,0 @@ !this._scrollMetrics ||

@@ -81,6 +81,2 @@ import BaseDimensions from '../BaseDimensions';

recycleEnabled?: boolean;
stillnessThreshold?: number;
dispatchMetricsThreshold?: number;
} & BaseDimensionsProps &

@@ -118,5 +114,2 @@ OnEndReachedHelperProps;

// export interface PseudoListDimensionsInterface
// extends CommonListDimensionsInterface {}
export type PseudoListDimensionsProps = {

@@ -135,3 +128,2 @@ indexKeys: Array<string>;

// export type ContainerOffsetGetter = () => { length: number };
export type ContainerLayoutGetter = () => {

@@ -228,8 +220,3 @@ x: number;

export type SpaceStateToken<
ItemT,
ViewabilityState = {
viewable: boolean;
}
> = {
export type SpaceStateToken<ItemT> = {
item: ItemT;

@@ -242,35 +229,15 @@ key: string;

position: SpaceStateTokenPosition;
} & ViewabilityState;
export type RecycleStateToken<
ItemT,
ViewabilityState = {
viewable: boolean;
}
> = {
};
export type RecycleStateToken<ItemT> = {
targetKey: string;
targetIndex: number;
offset: number;
} & SpaceStateToken<ItemT, ViewabilityState>;
} & SpaceStateToken<ItemT>;
export type SpaceStateResult<
ItemT,
ViewabilityState = {
viewable: boolean;
}
> = Array<SpaceStateToken<ItemT, ViewabilityState>>;
export type RecycleState<
ItemT,
ViewabilityState = {
viewable: boolean;
}
> = Array<RecycleStateToken<ItemT, ViewabilityState>>;
export type SpaceStateResult<ItemT> = Array<SpaceStateToken<ItemT>>;
export type RecycleState<ItemT> = Array<RecycleStateToken<ItemT>>;
export type RecycleStateResult<
ItemT,
ViewabilityState = {
viewable: boolean;
}
> = {
spaceState: SpaceStateResult<ItemT, ViewabilityState>;
recycleState: RecycleState<ItemT, ViewabilityState>;
export type RecycleStateResult<ItemT> = {
spaceState: SpaceStateResult<ItemT>;
recycleState: RecycleState<ItemT>;
};

@@ -277,0 +244,0 @@

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