Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuever committed Sep 18, 2023
1 parent 1eb8d98 commit d729c36
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
51 changes: 22 additions & 29 deletions packages/data-model/src/ListBaseDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ import noop from '@x-oasis/noop';
import Batchinator from '@x-oasis/batchinator';
import ListGroupDimensions from './ListGroupDimensions';
import omit from '@x-oasis/omit';
import SelectValue, {
import {
selectHorizontalValue,
selectVerticalValue,
} from '@x-oasis/select-value';
import {
isEmpty,
shallowDiffers,
INITIAL_NUM_TO_RENDER,
MAX_TO_RENDER_PER_BATCH,
buildStateTokenIndexKey,
DISPATCH_METRICS_THRESHOLD,
DEFAULT_ITEM_APPROXIMATE_LENGTH,
ITEM_OFFSET_BEFORE_LAYOUT_READY,
DEFAULT_RECYCLER_TYPE,
} from './common';
import resolveChanged from '@x-oasis/resolve-changed';
Expand Down Expand Up @@ -113,18 +111,14 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
private _provider: ListGroupDimensions;

constructor(props: ListBaseDimensionsProps<ItemT>) {
super(props)
super(props);
const {
store,
getData,
horizontal,

provider,
canIUseRIC,
recycleThreshold,
maxToRenderPerBatch = MAX_TO_RENDER_PER_BATCH,
initialNumToRender = INITIAL_NUM_TO_RENDER,
itemOffsetBeforeLayoutReady = ITEM_OFFSET_BEFORE_LAYOUT_READY,

recyclerBufferSize,
recyclerReservedBufferPerBatch,
Expand All @@ -134,7 +128,7 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
viewabilityConfigCallbackPairs,

recycleEnabled,
recyclerTypes = ['default_recycler'],
recyclerTypes,
deps = [],
getItemLayout,
onEndReached,
Expand Down Expand Up @@ -253,11 +247,11 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
50
);

this.initializeDefaultRecycleBuffer()
this.initializeDefaultRecycleBuffer();
}

initializeDefaultRecycleBuffer() {
this._recycler.addBuffer(DEFAULT_RECYCLER_TYPE)
this._recycler.addBuffer(DEFAULT_RECYCLER_TYPE);
}

// get itemOffsetBeforeLayoutReady() {
Expand Down Expand Up @@ -409,7 +403,7 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
* @returns TODO: temp
*/
getContainerOffset(): number {
return this._provider.getContainerOffset()
return this._provider.getContainerOffset();
// return 0;
// if (this._listGroupDimension) {
// return (
Expand All @@ -430,11 +424,11 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
}

getDataLength() {
return this._provider.getDataLength()
return this._provider.getDataLength();
}

getTotalLength() {
return this._provider.getTotalLength()
return this._provider.getTotalLength();
}

getReflowItemsLength() {
Expand Down Expand Up @@ -465,7 +459,7 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
}

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

_recycleEnabled() {
Expand Down Expand Up @@ -733,7 +727,7 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {

targetIndices
.filter((v) => v)
.forEach((info, index) => {
.forEach((info) => {
const { itemMeta, targetIndex, recycleKey } = info;
const item = this.getData()[targetIndex];
const itemLayout = itemMeta?.getLayout();
Expand All @@ -756,7 +750,7 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
itemMeta?.setItemMetaState(itemMetaState);

recycleStateResult.push({
key: `recycle_${index}`,
key: recycleKey,
targetKey: itemMeta.getKey(),
targetIndex,
length: itemLength,
Expand Down Expand Up @@ -999,18 +993,18 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
);

const oldData = this._state.data;
const newData = this._data
const newData = this._data;

const shouldSetState =
shallowDiffers(
omit(this._state || {}, omitKeys),
omit(newState, omitKeys)
) || !(resolveChanged(oldData, newData).isEqual);
) || !resolveChanged(oldData, newData).isEqual;

if (shouldSetState) {
const state = {
...newState,
data: newData
data: newData,
};

// @ts-ignore
Expand All @@ -1028,13 +1022,14 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
scrollMetrics,
});
if (isEmpty(state)) return state;
// this.setState({
// ...state,
// // @ts-ignore
// data: this.getData(),
// })
this.setState({
...state,
// @ts-ignore
data: this.getData(),
});

this.updateState(state, scrollMetrics);
// maybe itemMeta approximateLayout change, but will not trigger update...
// this.updateState(state, scrollMetrics);

return state;
}
Expand Down Expand Up @@ -1078,9 +1073,7 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
flush?: boolean;
}
) {

const scrollMetrics = _scrollMetrics || this._scrollMetrics;
// const useCache = defaultBooleanValue(_options?.useCache, true);
const flush = defaultBooleanValue(_options?.flush, false);

if (!scrollMetrics) return;
Expand All @@ -1096,7 +1089,7 @@ class ListBaseDimensions<ItemT extends {} = {}> extends BaseLayout {
this._dispatchMetricsBatchinator.schedule(scrollMetrics);
}

return
return;
}
}

Expand Down
5 changes: 2 additions & 3 deletions packages/data-model/src/ListDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ class ListDimensions<ItemT extends {} = {}> extends BaseDimensions {
correctionValue: LAYOUT_EQUAL_CORRECTION_VALUE,
})
) {
meta.isApproximateLayout = false
meta.isApproximateLayout = false;
const currentLength = this._selectValue.selectLength(
meta.getLayout() || {}
);
Expand All @@ -979,6 +979,7 @@ class ListDimensions<ItemT extends {} = {}> extends BaseDimensions {
return true;
}
} else if (meta.isApproximateLayout) {
meta.isApproximateLayout = false;
// 比如换了一个item的话,不会触发更新
if (this._listGroupDimension) {
this._listGroupDimension.recalculateDimensionsIntervalTreeBatchinator.schedule();
Expand All @@ -987,8 +988,6 @@ class ListDimensions<ItemT extends {} = {}> extends BaseDimensions {
}
}

meta.isApproximateLayout = false

return false;
}

Expand Down

0 comments on commit d729c36

Please sign in to comment.