Skip to content

Commit

Permalink
feat: Create a new instance for each new useProgress instance (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
RenaudRohlinger authored Feb 5, 2021
1 parent a08d7e8 commit 214ee27
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/core/useProgress.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DefaultLoadingManager } from 'three'
import { LoadingManager } from 'three'
import create from 'zustand'

type Data = {
Expand All @@ -11,12 +11,12 @@ type Data = {
}

const useProgress = create<Data>((set) => {
DefaultLoadingManager.onStart = (item, loaded, total) =>
set({ active: true, item, loaded, total, progress: (loaded / total) * 100 })
DefaultLoadingManager.onLoad = () => set({ active: false })
DefaultLoadingManager.onError = (item) => set((state) => ({ errors: [...state.errors, item] }))
DefaultLoadingManager.onProgress = (item, loaded, total) =>
set({ item, loaded, total, progress: (loaded / total) * 100 })
const loader = new LoadingManager()

loader.onStart = (item, loaded, total) => set({ active: true, item, loaded, total, progress: (loaded / total) * 100 })
loader.onLoad = () => set({ active: false })
loader.onError = (item) => set((state) => ({ errors: [...state.errors, item] }))
loader.onProgress = (item, loaded, total) => set({ item, loaded, total, progress: (loaded / total) * 100 })

return {
errors: [],
Expand Down

1 comment on commit 214ee27

@vercel
Copy link

@vercel vercel bot commented on 214ee27 Feb 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.