@@ -205,9 +205,21 @@ function inferHeightAxisType(axisType: ColumnAxisType, units): ColumnAxisType {
205205 return null ;
206206}
207207
208- const columnTypeAtom = atom < "section" | "column" | null > ( ) ;
208+ interface ColumnInfo {
209+ col_id : number ;
210+ col_type : "section" | "column" ;
211+ units : ExtUnit [ ] ;
212+ }
213+
214+ const columnInfoAtom = atom < ColumnInfo > ( ) ;
215+
216+ const columnTypeAtom = atom < "section" | "column" > ( ( get ) => {
217+ return get ( columnInfoAtom ) . col_type ;
218+ } ) ;
209219
210- const unitsAtom = atom < ExtUnit [ ] > ( ) ;
220+ const unitsAtom = atom < ExtUnit [ ] > ( ( get ) => {
221+ return get ( columnInfoAtom ) . units ;
222+ } ) ;
211223
212224const defaultAxisTypeAtom = atom < ColumnAxisType > ( ( get ) => {
213225 const columnType = get ( columnTypeAtom ) ;
@@ -226,25 +238,31 @@ const heightAxisTypeAtom = atom<ColumnAxisType>((get) => {
226238 return inferHeightAxisType ( inferredAxisType , units ) ;
227239} ) ;
228240
241+ function useUpdateAtoms ( atomsWithValues : [ WritableAtom < any , any , any > , any ] [ ] ) {
242+ useHydrateAtoms ( atomsWithValues ) ;
243+ const setAtoms = atomsWithValues . map ( ( [ atom ] ) => useSetAtom ( atom ) ) ;
244+ useEffect (
245+ ( ) => {
246+ atomsWithValues . forEach ( ( [ atom , value ] , i ) => {
247+ setAtoms [ i ] ( value ) ;
248+ } ) ;
249+ } ,
250+ atomsWithValues . map ( ( [ , value ] ) => value )
251+ ) ;
252+ }
253+
229254function ColumnPageInner ( { columnInfo, linkPrefix = "/" , projectID } ) {
230255 const { units, col_id } = columnInfo ;
231256
232257 const isSection = columnInfo . col_type == "section" ;
233258
234- useHydrateAtoms ( [
235- [ columnTypeAtom , columnInfo . col_type ] ,
236- [ unitsAtom , units ] ,
237- ] ) ;
259+ useUpdateAtoms ( [ [ columnInfoAtom , columnInfo ] ] ) ;
238260
239- const setUnits = useSetAtom ( unitsAtom ) ;
240- const setColumnType = useSetAtom ( columnTypeAtom ) ;
241261 const validateSelectedUnitID = useSetAtom ( validateSelectedUnitIDAtom ) ;
242262
243263 const pixelScale = useAtomValue ( pixelScaleAtom ) ;
244264
245265 useEffect ( ( ) => {
246- setUnits ( units ) ;
247- setColumnType ( columnInfo . col_type ) ;
248266 validateSelectedUnitID ( ) ;
249267 } , [ col_id ] ) ;
250268
0 commit comments