Skip to content

Commit 7d13064

Browse files
authored
fix(bindx): support direct field access on PlaceholderHandle proxy (#7)
PlaceholderHandle.wrapProxy used createAliasProxy which only strips the $ prefix but does not delegate unknown properties to target.fields. This caused entity.fieldName to return undefined for placeholder entities (e.g. when creating new entities via HasOne). Switch to createHandleProxy so that direct field access (entity.name) resolves through the fields proxy, matching EntityHandle behavior. Also transition disconnected relations to 'creating' state when SET_PLACEHOLDER_DATA is dispatched, ensuring placeholder data is properly tracked for new entities.
1 parent 40de784 commit 7d13064

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

packages/bindx/src/core/ActionDispatcher.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,15 @@ export class ActionDispatcher {
265265
action.fieldPath,
266266
action.value,
267267
)
268+
// When setting placeholder data on a disconnected relation, transition to 'creating'
269+
const stateUpdate = (!relation || relation.state === 'disconnected')
270+
? { state: 'creating' as const, placeholderData: newPlaceholderData }
271+
: { placeholderData: newPlaceholderData }
268272
this.store.setRelation(
269273
action.entityType,
270274
action.entityId,
271275
action.fieldName,
272-
{ placeholderData: newPlaceholderData },
276+
stateUpdate,
273277
)
274278
break
275279
}

packages/bindx/src/handles/PlaceholderHandle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
EntityPersistedEvent,
1919
EntityPersistingEvent,
2020
} from '../events/types.js'
21-
import { createAliasProxy } from './proxyFactory.js'
21+
import { createHandleProxy } from './proxyFactory.js'
2222
import type { SchemaRegistry } from '../schema/SchemaRegistry.js'
2323

2424
/**
@@ -77,7 +77,7 @@ export class PlaceholderHandle<TEntity extends object = object, TSelected = TEnt
7777
}
7878

7979
static wrapProxy<TEntity extends object, TSelected>(handle: PlaceholderHandle<TEntity, TSelected>): EntityAccessor<TEntity, TSelected> {
80-
return createAliasProxy<PlaceholderHandle<TEntity, TSelected>, EntityAccessor<TEntity, TSelected>>(handle)
80+
return createHandleProxy<PlaceholderHandle<TEntity, TSelected>, EntityAccessor<TEntity, TSelected>>(handle, (target) => target.fields)
8181
}
8282

8383
/**

0 commit comments

Comments
 (0)