Skip to content

Commit

Permalink
Feat(Network): Add recycle scrolling to imporove performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maizify committed Oct 27, 2022
1 parent beaa94c commit 52d32de
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 22 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
English | [简体中文](./CHANGELOG_CN.md)

## 3.15.0-rc (2022-10-??)
## 3.15.0-rc (2022-11-??)

- `Feat(Log)` Add recycle scrolling and scroll to top/bottom. (PR #570)
- `Feat(Log)` Add recycle scrolling to imporove performance, and add scroll to top/bottom buttons. (PR #570)
- `Feat(Log)` Add support for `console.group(), console.groupCollapsed(), console.groupEnd()`. (issue #545)
- `Feat(Network)` Add recycle scrolling to imporove performance.
- `Feat(Network)` Add "Start Time" of a request.
- `Feat(Network)` Use `curl` instead of `url` as the copy value of a request. (issue #410)

Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG_CN.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[English](./CHANGELOG.md) | 简体中文

## 3.15.0-rc (2022-10-??)
## 3.15.0-rc (2022-11-??)

- `Feat(Log)` 新增虚拟滚动列表以提升性能,并支持快速滚动到顶部/底部。 (PR #570)
- `Feat(Log)` 新增对 `console.group(), console.groupCollapsed(), console.groupEnd()` 方法的支持。 (issue #545)
- `Feat(Network)` 新增虚拟滚动列表以提升性能。
- `Feat(Network)` 新增 request 的 "Start Time"(发起时间)。
- `Feat(Network)` 使用 `curl` 格式作为 request 的复制内容,而非 `url`。 (issue #410)

Expand Down
1 change: 1 addition & 0 deletions src/component/recycleScroller/recycleScroller.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

.vc-scroller-items {
will-change: height;
position: relative;
}

.vc-scroller-item {
Expand Down
31 changes: 27 additions & 4 deletions src/component/recycleScroller/recycleScroller.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
export let end = 0;
// local state
let header: HTMLElement | undefined;
let footer: HTMLElement | undefined;
let viewport: HTMLElement | undefined;
let contents: HTMLElement | undefined;
let frame: HTMLElement | undefined;
let headerHeight = 0;
let footerHeight = 0;
let viewportHeight = 0;
let frameHeight = 0;
Expand All @@ -39,7 +41,7 @@
const updateVisible = createRecycleManager()
const getScrollExtent = () =>
Math.max(0, frameHeight + footerHeight - viewportHeight);
Math.max(0, frameHeight + headerHeight + footerHeight - viewportHeight);
let isOnBottom = true;
let avoidRefresh = false;
Expand All @@ -53,6 +55,7 @@
isOnBottom = Math.abs(pos - scrollExtent) <= 1;
contents.style.transform = `translateY(${-pos}px) translateZ(0)`;
// (window as any)._vcOrigConsole.log('pos', pos);
refreshScrollbar();
if (avoidRefresh) {
Expand All @@ -66,7 +69,7 @@
const refreshScrollbar = () => {
const pos = scrollHandler.getPosition();
const fac = 100 / (frameHeight + footerHeight);
const fac = 100 / (frameHeight + headerHeight + footerHeight);
scrollbarThumbPos = pos * fac;
scrollbarThumbHeight = viewportHeight * fac;
};
Expand Down Expand Up @@ -120,8 +123,9 @@
topMap[i] = y;
y += heightMap[i];
}
frameHeight = Math.max(y, viewportHeight - footerHeight);
frameHeight = Math.max(y, viewportHeight - headerHeight - footerHeight);
// (window as any)._vcOrigConsole.log("init(): frameHeight", frameHeight);
// (window as any)._vcOrigConsole.log("heightMap", heightMap);
// (window as any)._vcOrigConsole.log("reuseHeightCount", reuseHeightCount);
// (window as any)._vcOrigConsole.log(
Expand Down Expand Up @@ -210,6 +214,7 @@
// setTimeout to avoid ResizeObserver loop limit exceeded error
await new Promise((resolve) => setTimeout(resolve, 0));
initItems(items);
refresh(items, scrollHandler.getPosition(), viewportHeight);
if (viewportHeight !== 0) scrollToBottom(isOnBottom && stickToBottom);
refreshScrollbar();
Expand All @@ -223,11 +228,24 @@
// ;(window as any)._vcOrigConsole.log('footer height resize', height);
// no need to fresh
footerHeight = height;
initItems(items);
if (viewportHeight !== 0) scrollToBottom(isOnBottom && stickToBottom);
refreshScrollbar();
}
);
registerHeightObserver(
() => header,
(height) => {
if (headerHeight === height) return;
// ;(window as any)._vcOrigConsole.log('header height resize', height);
// no need to fresh
headerHeight = height;
initItems(items);
refreshScrollbar();
}
);
const onRowResize = async (index: number, height: number) => {
if (heightMap[index] === height || viewportHeight === 0) return;
Expand All @@ -247,7 +265,7 @@
}
frameHeight = Math.max(
topMap[n - 1] + heightMap[n - 1],
viewportHeight - footerHeight
viewportHeight - headerHeight - footerHeight
);
const scrollPos = scrollHandler.getPosition();
Expand Down Expand Up @@ -315,6 +333,11 @@
class="vc-scroller-viewport"
>
<div bind:this={contents} class="vc-scroller-contents">
{#if $$slots.header}
<div bind:this={header} class="vc-scroller-header">
<slot name="header" />
</div>
{/if}
<div bind:this={frame} class="vc-scroller-items">
{#if items.length}
{#each visible as row, i (row.key)}
Expand Down
1 change: 1 addition & 0 deletions src/core/style/theme.less
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

// table
.vc-table {
height: 100%;

.vc-table-row {
line-height: 1.5;
Expand Down
75 changes: 61 additions & 14 deletions src/network/network.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import IconCopy from '../component/iconCopy.svelte';
import { requestList } from './network.model';
import Style from './network.less';
import RecycleScroller from '../component/recycleScroller/recycleScroller.svelte';
import type { VConsoleNetworkRequestItem } from './requestItem';
import type { IVConsoleTabOptions } from "../lib/plugin";
let reqCount = 0;
const updateReqCount = (list: typeof $requestList) => {
Expand All @@ -13,6 +15,15 @@
const unsubscribe = requestList.subscribe(updateReqCount);
updateReqCount($requestList);
export const options: IVConsoleTabOptions = {
fixedHeight: true,
};
let reqList = [];
$: {
reqList = Object.values($requestList);
}
const onTapPreview = (reqId: string) => {
$requestList[reqId].actived = !$requestList[reqId].actived;
};
Expand All @@ -26,6 +37,10 @@
return `${curl} '${req.url}'`;
};
const stopTuochPropagation = (e: Event) => {
e.stopPropagation();
};
onMount(() => {
Style.use();
});
Expand All @@ -44,17 +59,29 @@
</script>

<div class="vc-table">

<dl class="vc-table-row">
<dd class="vc-table-col vc-table-col-4">Name {#if reqCount > 0}({reqCount}){/if}</dd>
<dd class="vc-table-col">Method</dd>
<dd class="vc-table-col">Status</dd>
<dd class="vc-table-col">Time</dd>
</dl>

<div class="vc-plugin-content">
{#each Object.entries($requestList) as [reqId, req]}
<div class="vc-group" class:vc-actived="{req.actived}" id="{req.id}">
<RecycleScroller
items={reqList}
itemKey="id"
itemHeight={30}
buffer={100}
stickToBottom
scrollbar
>

<svelte:fragment slot="header">
<dl class="vc-table-row">
<dd class="vc-table-col vc-table-col-4">Name {#if reqCount > 0}({reqCount}){/if}</dd>
<dd class="vc-table-col">Method</dd>
<dd class="vc-table-col">Status</dd>
<dd class="vc-table-col">Time</dd>
</dl>
</svelte:fragment>

<div slot="empty" class="vc-plugin-empty">Empty</div>

<div slot="item" let:item={req} class="vc-group" class:vc-actived="{req.actived}" id="{req.id}">
<dl class="vc-table-row vc-group-preview" class:vc-table-row-error="{req.status >= 400}" on:click={() => onTapPreview(req.id)}>
<dd class="vc-table-col vc-table-col-4">{req.name}</dd>
<dd class="vc-table-col">{req.method}</dd>
Expand Down Expand Up @@ -132,13 +159,27 @@
</dl>
{#if (typeof req.postData === 'string')}
<div class="vc-table-row vc-left-border vc-small">
<pre class="vc-table-col vc-table-col-value vc-max-height-line">{req.postData}</pre>
<pre
class="vc-table-col vc-table-col-value vc-max-height-line"
on:touchstart={stopTuochPropagation}
on:touchmove={stopTuochPropagation}
on:touchend={stopTuochPropagation}
on:touchcancel={stopTuochPropagation}
on:wheel={stopTuochPropagation}
>{req.postData}</pre>
</div>
{:else}
{#each Object.entries(req.postData) as [key, item]}
<div class="vc-table-row vc-left-border vc-small">
<div class="vc-table-col vc-table-col-2">{key}</div>
<div class="vc-table-col vc-table-col-4 vc-table-col-value vc-max-height-line">{prettyStringify(item)}</div>
<div
class="vc-table-col vc-table-col-4 vc-table-col-value vc-max-height-line"
on:touchstart={stopTuochPropagation}
on:touchmove={stopTuochPropagation}
on:touchend={stopTuochPropagation}
on:touchcancel={stopTuochPropagation}
on:wheel={stopTuochPropagation}
>{prettyStringify(item)}</div>
</div>
{/each}
{/if}
Expand Down Expand Up @@ -174,12 +215,18 @@
</div>
{/if}
<div class="vc-table-row vc-left-border vc-small">
<pre class="vc-table-col vc-max-height vc-min-height">{req.response || ''}</pre>
<pre
class="vc-table-col vc-max-height vc-min-height"
on:touchstart={stopTuochPropagation}
on:touchmove={stopTuochPropagation}
on:touchend={stopTuochPropagation}
on:touchcancel={stopTuochPropagation}
on:wheel={stopTuochPropagation}
>{req.response || ''}</pre>
</div>
</div>
</div>
</div>
{/each}

</RecycleScroller>
</div>
</div>
2 changes: 1 addition & 1 deletion src/storage/storage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@
</div>
</div>
{:else}
<div class="vc-plugin-empty"></div>
<div class="vc-plugin-empty">Empty</div>
{/each}
</div>

0 comments on commit 52d32de

Please sign in to comment.