-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lazy load a viewer component from lib-subject-viewers (#6402)
* use lazy and Suspense with VolumetricViewer * modularize lib-subject-viewers * build simplified ProtoViewer example * add @zooniverse/subject-viewers build:es6 to ci-build
- Loading branch information
1 parent
860f09f
commit b4008d2
Showing
34 changed files
with
166 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/lib-subject-viewers/src/ProtoViewer/ProtoViewer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import asyncStates from '@zooniverse/async-states' | ||
import { useEffect } from 'react' | ||
|
||
const DEFAULT_HANDLER = () => {} | ||
|
||
const defaultSubject = { | ||
id: '', | ||
locations: [] | ||
} | ||
|
||
const defaultTarget = { | ||
clientHeight: 0, | ||
clientWidth: 0, | ||
naturalHeight: 0, | ||
naturalWidth: 0 | ||
} | ||
|
||
export default function ProtoViewer({ | ||
/* | ||
loadingState is defined in SubjectViewerStore.js. onReady and onError affect it | ||
and then it's used below to choose rendering options | ||
*/ | ||
loadingState = asyncStates.initialized, | ||
/* | ||
onError is defined in lib-classifier's SubjectViewerStore.js. When called, it sets | ||
SubjectViewerStore's loadingState to error. | ||
*/ | ||
onError = DEFAULT_HANDLER, | ||
/* | ||
onReady is defined in lib-classifier's SubjectViewerStore.js as onSubjectReady(). | ||
It sets the loadingState on the SubjectViewerStore to success. That success triggers | ||
an update of subjectReadyState in SubjectViewer.js which is passed as loadingState to | ||
the Viewer *and* the TaskArea, preventing users from making classifications when a subject | ||
viewer is not ready. | ||
*/ | ||
onReady = DEFAULT_HANDLER, | ||
subject = defaultSubject | ||
}) { | ||
/* | ||
Here's where unique handling of subject data happens every time the subject changes. | ||
Examples are useSubjectImage() or useSubjectJSON() hooks in lib-classifier. | ||
*/ | ||
useEffect( | ||
function onSubjectChange() { | ||
function handleSubject() {} // etc, fetch more subject data if needed | ||
onReady(defaultTarget) | ||
}, | ||
[subject] | ||
) | ||
|
||
/* | ||
These are the render options. First catch an error if needed, | ||
then render subject viewer as long as the loadingState says it's okay. | ||
*/ | ||
if (loadingState === asyncStates.error) { | ||
return <p>Something went wrong.</p> | ||
} | ||
|
||
if (loadingState !== asyncStates.initialized) { | ||
return ( | ||
<div>This is the ProtoViewer. Here's the subject ID: {subject.id}</div> | ||
) | ||
} | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './ProtoViewer.js' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './VolumetricViewer.js' |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export { default as VolumetricViewer } from './components/VolumetricViewer/VolumetricViewer.js' | ||
export { VolumetricViewerData } from './components/VolumetricViewer/VolumetricViewer.js' | ||
export { default as VolumetricViewer } from './VolumetricViewer/VolumetricViewer.js' | ||
export { default as ProtoViewer } from './ProtoViewer' | ||
|
||
export { VolumetricViewerData } from './VolumetricViewer/VolumetricViewer.js' |