Skip to content

Commit

Permalink
fix(binding): in connectEntityAtField require marker for input state …
Browse files Browse the repository at this point in the history
…only
matej21 committed Jul 1, 2024
1 parent 05d4512 commit 3a387e3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/binding/src/core/operations/EntityOperations.ts
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ export class EntityOperations {
}

for (const state of StateIterator.eachSiblingRealm(outerState)) {
const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'connect')
const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'connect', state === outerState)
for (const targetHasOneMarker of targetHasOneMarkers) {
const previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)

@@ -165,7 +165,7 @@ export class EntityOperations {
const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)

for (const state of StateIterator.eachSiblingRealm(outerState)) {
const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'disconnect')
const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'disconnect', state === outerState)
for (const targetHasOneMarker of targetHasOneMarkers) {
const stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)

@@ -286,10 +286,14 @@ export class EntityOperations {
container: EntityFieldMarkersContainer,
field: FieldName,
type: 'connect' | 'disconnect',
mustExists: boolean,
): IterableIterator<HasOneRelationMarker> {
const placeholders = container.placeholders.get(field)

if (placeholders === undefined) {
if (!mustExists) {
return
}
throw new BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`)
}
const normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]

0 comments on commit 3a387e3

Please sign in to comment.