Skip to content

Commit

Permalink
Merge pull request anse-app#107 from hswmartin/ddiu
Browse files Browse the repository at this point in the history
lodash节流
  • Loading branch information
ddiu8081 committed Mar 6, 2023
2 parents c33c118 + b2dc3fe commit 468b4d1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"highlight.js": "^11.7.0",
"js-sha256": "^0.9.0",
"katex": "^0.6.0",
"lodash": "^4.17.21",
"markdown-it": "^13.0.1",
"markdown-it-highlightjs": "^4.0.1",
"markdown-it-katex": "^2.0.3",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/components/Generator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createSignal, Index, Show } from 'solid-js'
import IconClear from './icons/Clear'
import MessageItem from './MessageItem'
import SystemRoleSettings from './SystemRoleSettings'
import _ from 'lodash'
import { generateSignature } from '@/utils/auth'

export default () => {
Expand Down Expand Up @@ -31,7 +32,12 @@ export default () => {
])
requestWithLatestMessage()
}

const throttle =_.throttle(function(){
window.scrollTo({top: document.body.scrollHeight, behavior: 'smooth'})
}, 300, {
leading: true,
trailing: false
})
const requestWithLatestMessage = async () => {
setLoading(true)
setCurrentAssistantMessage('')
Expand Down Expand Up @@ -79,7 +85,7 @@ export default () => {
if (char) {
setCurrentAssistantMessage(currentAssistantMessage() + char)
}
window.scrollTo({top: document.body.scrollHeight, behavior: 'smooth'})
throttle()
}
done = readerDone
}
Expand Down

0 comments on commit 468b4d1

Please sign in to comment.