Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/react/useAtomValue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React, { useDebugValue, useEffect, useReducer } from 'react'
import { INTERNAL_getBuildingBlocksRev3 as INTERNAL_getBuildingBlocks } from '../vanilla/internals.ts'
import {
type INTERNAL_BuildingBlockContext,
INTERNAL_getBuildingBlocksRev3 as INTERNAL_getBuildingBlocks,
} from '../vanilla/internals.ts'
import type { Atom, ExtractAtomValue } from '../vanilla.ts'
import { useStore } from './Provider.ts'

Expand Down Expand Up @@ -63,6 +66,8 @@ const createContinuablePromise = <T>(
getValue: () => PromiseLike<T> | T,
) => {
const buildingBlocks = INTERNAL_getBuildingBlocks(store)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Neat idea with the s prop.
Should we do INTERNAL_getBuildingBlocksContext instead?

const ctx: INTERNAL_BuildingBlockContext = [...buildingBlocks] as never
ctx.s = store
const registerAbortHandler = buildingBlocks[26]
let continuablePromise = continuablePromiseMap.get(promise)
if (!continuablePromise) {
Expand All @@ -85,7 +90,7 @@ const createContinuablePromise = <T>(
continuablePromiseMap.set(nextValue, continuablePromise!)
curr = nextValue
nextValue.then(onFulfilled(nextValue), onRejected(nextValue))
registerAbortHandler(buildingBlocks, nextValue, onAbort)
registerAbortHandler(ctx, nextValue, onAbort)
} else {
resolve(nextValue)
}
Expand All @@ -94,7 +99,7 @@ const createContinuablePromise = <T>(
}
}
promise.then(onFulfilled(promise), onRejected(promise))
registerAbortHandler(buildingBlocks, promise, onAbort)
registerAbortHandler(ctx, promise, onAbort)
})
continuablePromiseMap.set(promise, continuablePromise)
}
Expand Down
Loading
Loading