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.45-recycle-group.9 to 0.2.45-recycle-group.10

41

dist/ListBaseDimensions.d.ts
import Batchinator from '@x-oasis/batchinator';
import SelectValue from '@x-oasis/select-value';
import { ActionType, ReducerResult } from './state/types';
import { SpaceStateToken, GetItemLayout, ListBaseDimensionsProps, ListRenderState, ListState, OnEndReached, PreStateResult, ScrollMetrics, StateListener, ListStateResult, SpaceStateTokenPosition, FillingMode } from './types';
import { SpaceStateToken, GetItemLayout, ListBaseDimensionsProps, ListRenderState, ListState, OnEndReached, PreStateResult, ScrollMetrics, StateListener, ListStateResult, SpaceStateTokenPosition } from './types';
import OnEndReachedHelper from './viewable/OnEndReachedHelper';
import EnabledSelector from './utils/EnabledSelector';
import ViewabilityConfigTuples from './viewable/ViewabilityConfigTuples';
declare class ListBaseDimensions<ItemT extends {} = {}> {
_selectValue: SelectValue;
import BaseLayout from './BaseLayout';
declare class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
private _getItemLayout;

@@ -31,12 +30,2 @@ private _getItemSeparatorLength;

private _recycler;
private _recycleThreshold;
readonly _onEndReachedThreshold: number;
readonly _fillingMode: FillingMode;
initialNumToRender: number;
private _persistanceIndices;
private _stickyHeaderIndices;
private _reservedIndices;
private _maxToRenderPerBatch;
private _canIUseRIC;
private _itemOffsetBeforeLayoutReady;
_configTuple: ViewabilityConfigTuples;

@@ -50,13 +39,3 @@ private memoizedResolveSpaceState;

constructor(props: ListBaseDimensionsProps<ItemT>);
get itemOffsetBeforeLayoutReady(): number;
get fillingMode(): FillingMode;
get reservedIndices(): any[];
get maxToRenderPerBatch(): number;
get canIUseRIC(): boolean;
updateReservedIndices(): void;
get persistanceIndices(): Array<number>;
set persistanceIndices(indices: Array<number>);
get stickyHeaderIndices(): Array<number>;
set stickyHeaderIndices(indices: Array<number>);
get recycleThreshold(): number;
initializeDefaultRecycleBuffer(): void;
get length(): number;

@@ -74,2 +53,3 @@ get selector(): EnabledSelector;

setActive(): void;
addOnEndReached(onEndReached: OnEndReached): () => void;
resolveInitialState(): {

@@ -89,2 +69,4 @@ visibleStartIndex: number;

getData(): import("./types").ListGroupData[];
getDataLength(): number;
getTotalLength(): number;
getReflowItemsLength(): number;

@@ -97,2 +79,6 @@ getFinalItemKey(item: any): string;

hasUnLayoutItems(): boolean;
computeIndexRange(minOffset: number, maxOffset: number): {
startIndex: number;
endIndex: number;
};
_recycleEnabled(): boolean;

@@ -155,4 +141,7 @@ recalculateRecycleResultState(): void;

isStill(): void;
updateScrollMetrics(scrollMetrics?: ScrollMetrics, useCache?: boolean): void;
updateScrollMetrics(_scrollMetrics?: ScrollMetrics, _options?: {
useCache?: boolean;
flush?: boolean;
}): void;
}
export default ListBaseDimensions;

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

cleanup(): void;
resolveInitialActiveValue(active: boolean): boolean;
getRenderState(): ListRenderState;

@@ -57,0 +56,0 @@ setRenderState(state: ListRenderState): void;

@@ -27,6 +27,4 @@ import Batchinator from '@x-oasis/batchinator';

private _renderStateListeners;
private _renderStateListenersCleaner;
private _onBatchLayoutFinished;
private _onUpdateDimensionItemsMetaChangeBatchinator;
private _updateScrollMetricsWithCacheBatchinator;
recalculateDimensionsIntervalTreeBatchinator: Batchinator;

@@ -161,3 +159,2 @@ private _heartBeatingIndexKeys;

onUpdateDimensionItemsMetaChange(itemsMeta: Array<ItemMeta>, scrollMetrics: ScrollMetrics): void;
updateScrollMetricsWithCache(scrollMetrics?: ScrollMetrics): void;
dispatchScrollMetricsEnabled(): boolean;

@@ -168,5 +165,3 @@ updateScrollMetrics(_scrollMetrics?: ScrollMetrics, _options?: {

}): void;
addRenderStateListener(fn: Function): () => void;
cleanRenderStateListeners(): void;
}
export default ListGroupDimensions;

@@ -27,2 +27,4 @@ import Batchinator from '@x-oasis/batchinator';

setHandler(onEndReached: OnEndReached): void;
hasHandler(): boolean;
addHandler(onEndReached: OnEndReached): () => void;
perform(scrollMetrics?: ScrollMetrics, positive?: boolean): {

@@ -29,0 +31,0 @@ distanceFromEnd: number;

{
"name": "@infinite-list/data-model",
"version": "0.2.45-recycle-group.9",
"version": "0.2.45-recycle-group.10",
"files": [

@@ -5,0 +5,0 @@ "dist",

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

ITEM_OFFSET_BEFORE_LAYOUT_READY,
DEFAULT_RECYCLER_TYPE,
} from './common';

@@ -51,2 +52,3 @@ import resolveChanged from '@x-oasis/resolve-changed';

import Recycler from './Recycler';
import BaseLayout from './BaseLayout';

@@ -58,4 +60,4 @@ /**

*/
class ListBaseDimensions<ItemT extends {} = {}> {
public _selectValue: SelectValue;
class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
// public _selectValue: SelectValue;
private _getItemLayout: GetItemLayout<ItemT>;

@@ -99,13 +101,2 @@ private _getItemSeparatorLength: GetItemSeparatorLength<ItemT>;

private _recycleThreshold: number;
readonly _onEndReachedThreshold: number;
readonly _fillingMode: FillingMode;
initialNumToRender: number;
private _persistanceIndices = [];
private _stickyHeaderIndices = [];
private _reservedIndices = [];
private _maxToRenderPerBatch: number;
private _canIUseRIC: boolean;
private _itemOffsetBeforeLayoutReady: number;
_configTuple: ViewabilityConfigTuples;

@@ -129,2 +120,3 @@

constructor(props: ListBaseDimensionsProps<ItemT>) {
super(props)
const {

@@ -174,5 +166,5 @@ store,

this._getData = getData;
this._maxToRenderPerBatch = maxToRenderPerBatch;
this._itemOffsetBeforeLayoutReady = itemOffsetBeforeLayoutReady;
this._canIUseRIC = canIUseRIC;
// this._maxToRenderPerBatch = maxToRenderPerBatch;
// this._itemOffsetBeforeLayoutReady = itemOffsetBeforeLayoutReady;
// this._canIUseRIC = canIUseRIC;

@@ -205,3 +197,2 @@ // `_approximateMode` is enabled on default

});
// this._onBatchLayoutFinished = onBatchLayoutFinished;

@@ -212,9 +203,2 @@ this._selectValue = horizontal

this._fillingMode = recycleEnabled
? FillingMode.RECYCLE
: FillingMode.SPACE;
this._recycleThreshold = recycleEnabled
? recycleThreshold || maxToRenderPerBatch * 2
: 0;
this._configTuple = new ViewabilityConfigTuples({

@@ -279,53 +263,59 @@ viewabilityConfig,

);
}
get itemOffsetBeforeLayoutReady() {
return this._itemOffsetBeforeLayoutReady;
this.initializeDefaultRecycleBuffer()
}
get fillingMode() {
return this._fillingMode;
initializeDefaultRecycleBuffer() {
this._recycler.addBuffer(DEFAULT_RECYCLER_TYPE)
}
get reservedIndices() {
return this._reservedIndices;
}
// get itemOffsetBeforeLayoutReady() {
// return this._itemOffsetBeforeLayoutReady;
// }
get maxToRenderPerBatch() {
return this._maxToRenderPerBatch;
}
// get fillingMode() {
// return this._fillingMode;
// }
get canIUseRIC() {
return this._canIUseRIC;
}
// get reservedIndices() {
// return this._reservedIndices;
// }
updateReservedIndices() {
const indices = new Set(
[].concat(this.persistanceIndices, this.stickyHeaderIndices)
);
this._reservedIndices = Array.from(indices).sort((a, b) => a - b);
}
// get maxToRenderPerBatch() {
// return this._maxToRenderPerBatch;
// }
get persistanceIndices() {
return this._persistanceIndices;
}
// get canIUseRIC() {
// return this._canIUseRIC;
// }
set persistanceIndices(indices: Array<number>) {
this._persistanceIndices = indices.sort((a, b) => a - b);
this.updateReservedIndices();
}
// updateReservedIndices() {
// const indices = new Set(
// [].concat(this.persistanceIndices, this.stickyHeaderIndices)
// );
// this._reservedIndices = Array.from(indices).sort((a, b) => a - b);
// }
get stickyHeaderIndices() {
return this._stickyHeaderIndices;
}
// get persistanceIndices() {
// return this._persistanceIndices;
// }
set stickyHeaderIndices(indices: Array<number>) {
this._stickyHeaderIndices = indices.sort((a, b) => a - b);
this.updateReservedIndices();
}
// set persistanceIndices(indices: Array<number>) {
// this._persistanceIndices = indices.sort((a, b) => a - b);
// this.updateReservedIndices();
// }
get recycleThreshold() {
return this._recycleThreshold;
}
// get stickyHeaderIndices() {
// return this._stickyHeaderIndices;
// }
// set stickyHeaderIndices(indices: Array<number>) {
// this._stickyHeaderIndices = indices.sort((a, b) => a - b);
// this.updateReservedIndices();
// }
// get recycleThreshold() {
// return this._recycleThreshold;
// }
get length() {

@@ -390,2 +380,6 @@ return this._data.length;

addOnEndReached(onEndReached: OnEndReached) {
return this.onEndReachedHelper.addHandler(onEndReached);
}
resolveInitialState() {

@@ -428,3 +422,4 @@ if (!this.initialNumToRender || !this._data.length || !this._isActive)

getContainerOffset(): number {
return 0;
return this._provider.getContainerOffset()
// return 0;
// if (this._listGroupDimension) {

@@ -448,2 +443,10 @@ // return (

getDataLength() {
return this._provider.getDataLength()
}
getTotalLength() {
return this._provider.getTotalLength()
}
getReflowItemsLength() {

@@ -476,2 +479,6 @@ return this._provider.getReflowItemsLength();

computeIndexRange(minOffset: number, maxOffset: number) {
return this._provider.computeIndexRange(minOffset, maxOffset)
}
_recycleEnabled() {

@@ -1008,7 +1015,4 @@ if (this.fillingMode !== FillingMode.RECYCLE) return false;

const oldData = this._state.data;
const newData = this._data
const newData = this._data.slice(0, nextDataLength);
const { isEqual } = resolveChanged(oldData, newData);
const shouldSetState =

@@ -1018,3 +1022,3 @@ shallowDiffers(

omit(newState, omitKeys)
) || !isEqual;
) || !(resolveChanged(oldData, newData).isEqual);

@@ -1024,3 +1028,3 @@ if (shouldSetState) {

...newState,
data: this._data.slice(0, nextDataLength),
data: newData
};

@@ -1043,3 +1047,10 @@

if (isEmpty(state)) return state;
// this.setState({
// ...state,
// // @ts-ignore
// data: this.getData(),
// })
this.updateState(state, scrollMetrics);
return state;

@@ -1080,13 +1091,14 @@ }

/**
* When to trigger updateScrollMetrics..
* - on scroll
* - layout change.
* - In rn, use contentSizeChanged. `setIntervalTreeValue` has remove update scroll logic.
* - In web, maybe `setIntervalTreeValue` to trigger state updating..
*/
updateScrollMetrics(
scrollMetrics: ScrollMetrics = this._scrollMetrics,
useCache = true
_scrollMetrics?: ScrollMetrics,
_options?: {
useCache?: boolean;
flush?: boolean;
}
) {
const scrollMetrics = _scrollMetrics || this._scrollMetrics;
// const useCache = defaultBooleanValue(_options?.useCache, true);
const flush = defaultBooleanValue(_options?.flush, false);
if (!scrollMetrics) return;

@@ -1098,31 +1110,10 @@ if (!this.dispatchScrollMetricsEnabled()) {

if (!useCache) {
this._scrollMetrics = scrollMetrics;
this._scrollMetrics = scrollMetrics;
if (flush) {
this._dispatchMetricsBatchinator.flush(scrollMetrics);
} else {
this._dispatchMetricsBatchinator.schedule(scrollMetrics);
return;
}
if (this._scrollMetrics?.offset !== scrollMetrics?.offset) {
// this._stillnessHelper.startClockBatchinateLast.schedule();
}
if (
!this._scrollMetrics ||
scrollMetrics.contentLength !== this._scrollMetrics.contentLength ||
scrollMetrics.offset !== this._scrollMetrics.offset ||
scrollMetrics.visibleLength !== this._scrollMetrics.visibleLength
) {
this._scrollMetrics = scrollMetrics;
this._dispatchMetricsBatchinator.schedule(scrollMetrics);
} else if (scrollMetrics.offset !== this._offsetTriggerCachedState) {
this._scrollMetrics = scrollMetrics;
this._dispatchMetricsBatchinator.schedule(scrollMetrics);
} else {
this._dispatchMetricsBatchinator.dispose({
abort: true,
});
this.updateState(this._state, scrollMetrics);
}
this._scrollMetrics = scrollMetrics;
return
}

@@ -1129,0 +1120,0 @@ }

@@ -198,21 +198,21 @@ import noop from '@x-oasis/noop';

if (this._listGroupDimension && this.initialNumToRender) {
if (process.env.NODE_ENV === 'development')
console.warn(
'[Spectrum warning] : As a `ListGroup` child list, List Props ' +
' initialNumToRender value should be controlled' +
'by `ListGroup` commander. So value is reset to `0`.'
);
this.initialNumToRender = 0;
}
// if (this._listGroupDimension && this.initialNumToRender) {
// if (process.env.NODE_ENV === 'development')
// console.warn(
// '[Spectrum warning] : As a `ListGroup` child list, List Props ' +
// ' initialNumToRender value should be controlled' +
// 'by `ListGroup` commander. So value is reset to `0`.'
// );
// this.initialNumToRender = 0;
// }
if (this._listGroupDimension && persistanceIndices) {
if (process.env.NODE_ENV === 'development')
console.warn(
'[Spectrum warning] : As a `ListGroup` child list, List Props ' +
' persistanceIndices value should be controlled' +
'by `ListGroup` commander. So value is reset to `[]`.'
);
this.persistanceIndices = [];
}
// if (this._listGroupDimension && persistanceIndices) {
// if (process.env.NODE_ENV === 'development')
// console.warn(
// '[Spectrum warning] : As a `ListGroup` child list, List Props ' +
// ' persistanceIndices value should be controlled' +
// 'by `ListGroup` commander. So value is reset to `[]`.'
// );
// this.persistanceIndices = [];
// }

@@ -288,24 +288,24 @@ this.updateInitialNumDueToListGroup(data);

resolveInitialActiveValue(active: boolean) {
if (this._deps.length) {
let isActive = true;
for (let index = 0; index < this._deps.length; index++) {
const listKey = this._deps[index];
const listHandler = manager.getKeyList(listKey);
if (!listHandler) continue;
// resolveInitialActiveValue(active: boolean) {
// if (this._deps.length) {
// let isActive = true;
// for (let index = 0; index < this._deps.length; index++) {
// const listKey = this._deps[index];
// const listHandler = manager.getKeyList(listKey);
// if (!listHandler) continue;
if (
listHandler.getRenderState() !== ListRenderState.ON_RENDER_FINISHED
) {
this._renderStateListenersCleaner.push(
listHandler.addRenderStateListener(this.handleDeps.bind(this))
);
isActive = false;
}
}
return isActive;
}
// if (
// listHandler.getRenderState() !== ListRenderState.ON_RENDER_FINISHED
// ) {
// this._renderStateListenersCleaner.push(
// listHandler.addRenderStateListener(this.handleDeps.bind(this))
// );
// isActive = false;
// }
// }
// return isActive;
// }
return active;
}
// return active;
// }

@@ -363,8 +363,2 @@ getRenderState() {

return this._offsetInListGroup;
// return (
// this._listGroupDimension.getContainerOffset() + this._offsetInListGroup
// );
// return (
// this._listGroupDimension.getContainerOffset() + this._offsetInListGroup
// );
}

@@ -371,0 +365,0 @@ const layout = this.getContainerLayout();

@@ -66,6 +66,5 @@ import Batchinator from '@x-oasis/batchinator';

private _renderStateListeners: Array<Function> = [];
private _renderStateListenersCleaner: Array<Function> = [];
private _onBatchLayoutFinished: () => boolean;
private _onUpdateDimensionItemsMetaChangeBatchinator: Batchinator;
private _updateScrollMetricsWithCacheBatchinator: Batchinator;
// private _updateScrollMetricsWithCacheBatchinator: Batchinator;
// private _updateChildPersistanceIndicesBatchinator: Batchinator;

@@ -159,6 +158,6 @@ public recalculateDimensionsIntervalTreeBatchinator: Batchinator;

);
this._updateScrollMetricsWithCacheBatchinator = new Batchinator(
this.updateScrollMetricsWithCache.bind(this),
50
);
// this._updateScrollMetricsWithCacheBatchinator = new Batchinator(
// this.updateScrollMetricsWithCache.bind(this),
// 50
// );

@@ -184,2 +183,3 @@ this._heartBeatResolveChangedBatchinator = new Batchinator(

this._listBaseDimension = new ListBaseDimensions({
...props,
keyExtractor: () => null,

@@ -570,2 +570,8 @@ id: 'listGroupDimensions',

let onEndReachedCleaner = null
if (listDimensionsProps.onEndReached) {
onEndReachedCleaner = this._listBaseDimension.addOnEndReached(listDimensionsProps.onEndReached)
}
// this.calculateDimensionsIndexRange();

@@ -591,2 +597,3 @@ // this.calculateReflowItemsLength();

this.removeListDimensions(listKey);
if (onEndReachedCleaner) onEndReachedCleaner()
},

@@ -801,4 +808,2 @@ };

const { recyclerType } = itemDimensionsProps
this.startInspection()
const dimensions = new Dimension({

@@ -813,2 +818,3 @@ id: key,

});
this.startInspection()

@@ -890,3 +896,3 @@ this.setDimension(key, dimensions);

if (
[KeysChangedType.Add, KeysChangedType.Remove].indexOf(changedType) !==
[KeysChangedType.Add, KeysChangedType.Remove, KeysChangedType.Append].indexOf(changedType) !==
-1

@@ -1281,2 +1287,12 @@ ) {

});
const {
isEndReached,
distanceFromEnd
} = state
this.onEndReachedHelper.performEndReached({
isEndReached,
distanceFromEnd,
});
return;

@@ -1295,47 +1311,47 @@ }

updateScrollMetricsWithCache(
scrollMetrics: ScrollMetrics = this._scrollMetrics
) {
// 之所以这么处理,是因为有可能数据的item值发生了变化,这个时候要重新刷一下
// 嵌套的子item。
const { bufferedMetaRanges, visibleMetaRanges } = this._rangeResult;
bufferedMetaRanges.forEach((range) => {
const { listKey, value } = range;
const dimension = this.getDimension(listKey);
// updateScrollMetricsWithCache(
// scrollMetrics: ScrollMetrics = this._scrollMetrics
// ) {
// // 之所以这么处理,是因为有可能数据的item值发生了变化,这个时候要重新刷一下
// // 嵌套的子item。
// const { bufferedMetaRanges, visibleMetaRanges } = this._rangeResult;
// bufferedMetaRanges.forEach((range) => {
// const { listKey, value } = range;
// const dimension = this.getDimension(listKey);
const visibleMetaRange = visibleMetaRanges.find(
(v) => v.listKey === listKey
);
// const visibleMetaRange = visibleMetaRanges.find(
// (v) => v.listKey === listKey
// );
if (dimension instanceof ListDimensions) {
if (visibleMetaRange) {
dimension.updateState(
{
...this._dispatchedMetricsResult,
visibleStartIndex: visibleMetaRange
? visibleMetaRange.value.startIndex
: -1,
visibleEndIndex: visibleMetaRange
? visibleMetaRange.value.endIndex
: -1,
bufferedEndIndex: value.endIndex,
bufferedStartIndex: value.startIndex,
},
scrollMetrics
);
} else {
dimension.updateStateBatchinator.schedule(
{
...this._dispatchedMetricsResult,
visibleStartIndex: -1,
visibleEndIndex: -1,
bufferedEndIndex: value.endIndex,
bufferedStartIndex: value.startIndex,
},
scrollMetrics
);
}
}
});
}
// if (dimension instanceof ListDimensions) {
// if (visibleMetaRange) {
// dimension.updateState(
// {
// ...this._dispatchedMetricsResult,
// visibleStartIndex: visibleMetaRange
// ? visibleMetaRange.value.startIndex
// : -1,
// visibleEndIndex: visibleMetaRange
// ? visibleMetaRange.value.endIndex
// : -1,
// bufferedEndIndex: value.endIndex,
// bufferedStartIndex: value.startIndex,
// },
// scrollMetrics
// );
// } else {
// dimension.updateStateBatchinator.schedule(
// {
// ...this._dispatchedMetricsResult,
// visibleStartIndex: -1,
// visibleEndIndex: -1,
// bufferedEndIndex: value.endIndex,
// bufferedStartIndex: value.startIndex,
// },
// scrollMetrics
// );
// }
// }
// });
// }

@@ -1357,74 +1373,9 @@ dispatchScrollMetricsEnabled() {

const scrollMetrics = _scrollMetrics || this._scrollMetrics;
const useCache = defaultBooleanValue(_options?.useCache, true);
const flush = defaultBooleanValue(_options?.flush, false);
if (!scrollMetrics) return;
if (!this.dispatchScrollMetricsEnabled()) {
this._scrollMetrics = scrollMetrics;
return;
}
this._scrollMetrics = scrollMetrics;
if (flush) {
this._dispatchMetricsBatchinator.flush(scrollMetrics);
} else {
this._dispatchMetricsBatchinator.schedule(scrollMetrics);
}
return
// if (
// !useCache ||
// // 刚开始时,this._scrollMetrics是不存在的
// !this._scrollMetrics ||
// scrollMetrics.contentLength !== this._scrollMetrics.contentLength ||
// scrollMetrics.offset !== this._scrollMetrics.offset ||
// scrollMetrics.visibleLength !== this._scrollMetrics.visibleLength
// ) {
// this._scrollMetrics = scrollMetrics;
// if (flush) {
// this._dispatchMetricsBatchinator.flush(scrollMetrics);
// } else {
// this._dispatchMetricsBatchinator.schedule(scrollMetrics);
// }
// } else if (this._rangeResult && this._dispatchedMetricsResult) {
// this._scrollMetrics = scrollMetrics;
// // 缓存的优先级,永远不如不使用缓存的;比如前面的list data发生了变化,
// // 但是后续的list并没有发生变化,这个时候要自行自定义的
// if (!this._dispatchMetricsBatchinator.inSchedule()) {
// if (flush) {
// this._updateScrollMetricsWithCacheBatchinator.flush(scrollMetrics);
// } else {
// this._updateScrollMetricsWithCacheBatchinator.schedule(scrollMetrics);
// }
// } else {
// // 刷新scrollMetrics的值
// if (flush) {
// this._dispatchMetricsBatchinator.flush(scrollMetrics);
// } else {
// this._dispatchMetricsBatchinator.schedule(scrollMetrics);
// }
// }
// }
this._listBaseDimension.updateScrollMetrics(
_scrollMetrics,
_options
)
}
addRenderStateListener(fn: Function) {
if (typeof fn === 'function') {
this._renderStateListeners.push(fn);
return () => {
const index = this._renderStateListeners.findIndex((s) => s === fn);
if (index !== -1) this._renderStateListeners.splice(index, 1);
};
}
return noop;
}
cleanRenderStateListeners() {
this._renderStateListenersCleaner.forEach((cleaner) => cleaner());
}
}
export default ListGroupDimensions;
import BaseDimensions from '../../BaseDimensions';
import ListBaseDimensions from '../../ListBaseDimensions';
import ListGroupDimensions from '../../ListGroupDimensions';

@@ -14,3 +15,7 @@ import { ActionPayload, Ctx, ReducerResult } from '../types';

maxIndex = dimension.length - 1;
} else if (dimension instanceof ListGroupDimensions) {
} else if (
(dimension instanceof ListGroupDimensions) ||
// @ts-ignore
(dimension instanceof ListBaseDimensions)
) {
maxIndex = dimension.getDataLength() - 1;

@@ -17,0 +22,0 @@ }

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

private onEndReached: OnEndReached;
private onEndReached: OnEndReached | Array<OnEndReached>;
private _scrollMetrics: ScrollMetrics;

@@ -85,2 +85,24 @@ private _maxCountOfHandleOnEndReachedAfterStillness: number;

hasHandler() {
return Array.isArray(this.onEndReached) || (typeof this.onEndReached === 'function')
}
addHandler(onEndReached: OnEndReached) {
if (typeof onEndReached === 'function') {
const handler = Array.isArray(this.onEndReached) ? this.onEndReached : (
this.onEndReached ? [this.onEndReached] : []
)
const index = handler.findIndex(v => v === onEndReached)
if (index === -1) handler.push(onEndReached)
this.onEndReached = handler
}
return () => {
if (Array.isArray(this.onEndReached)) {
const index = this.onEndReached.findIndex(v => v === onEndReached)
if (index !== -1) this.onEndReached.splice(index, 1)
}
}
}
/**

@@ -211,3 +233,3 @@ *

if (typeof this.onEndReached !== 'function') return;
if (!this.hasHandler()) return;
if (isEndReached && !this.isConsecutiveDistance(distanceFromEnd)) {

@@ -262,3 +284,3 @@ if (

onEndReachedHandler(opts: { distanceFromEnd: number }) {
if (typeof this.onEndReached !== 'function') return;
if (!this.hasHandler()) return
if (this._waitingForDataChangedSinceEndReached) return;

@@ -277,7 +299,17 @@ this._waitingForDataChangedSinceEndReached = true;

this.onEndReached({
distanceFromEnd,
cb: this.releaseHandlerMutex(this._currentMutexMS),
releaseHandlerMutex: this.releaseHandlerMutex(this._currentMutexMS),
});
if (Array.isArray(this.onEndReached)) {
this.onEndReached.forEach(handler => {
handler({
distanceFromEnd,
cb: this.releaseHandlerMutex(this._currentMutexMS),
releaseHandlerMutex: this.releaseHandlerMutex(this._currentMutexMS),
})
})
} else {
this.onEndReached({
distanceFromEnd,
cb: this.releaseHandlerMutex(this._currentMutexMS),
releaseHandlerMutex: this.releaseHandlerMutex(this._currentMutexMS),
});
}
}

@@ -284,0 +316,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

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