@contember/bindx-react 0.1.5 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -186,15 +186,15 @@ export type {
186
186
  BindxContextValue,
187
187
  UseEntityOptions,
188
188
  UseEntityListOptions,
189
- LoadingEntityAccessor,
190
- ErrorEntityAccessor,
191
- NotFoundEntityAccessor,
192
- ReadyEntityAccessor,
193
- EntityAccessorResult,
194
- LoadingEntityListAccessor,
195
- ErrorEntityListAccessor,
196
- ReadyEntityListAccessor,
197
- EntityListAccessorResult,
189
+ LoadingEntityResult,
190
+ ErrorEntityResult,
191
+ NotFoundEntityResult,
192
+ ReadyEntityResult,
193
+ UseEntityResult,
194
+ LoadingEntityListResult,
195
+ ErrorEntityListResult,
196
+ ReadyEntityListResult,
197
+ UseEntityListResult,
198
198
  // Persistence hook types
199
199
  PersistApi,
200
200
  EntityPersistApi,
@@ -47,6 +47,7 @@ export function createCollectorProxy<T>(
47
47
  $fields: fieldsProxy,
48
48
  $data: null,
49
49
  $isDirty: false,
50
+ $isPersisting: false,
50
51
  $persistedId: null,
51
52
  $isNew: true,
52
53
  __entityType: undefined as unknown as T,
@@ -226,6 +227,7 @@ function createCollectorFieldRef(
226
227
  // EntityRef-compatible properties (for HasOneAccessor = EntityAccessor compatibility)
227
228
  id: placeholderId,
228
229
  $data: null,
230
+ $isPersisting: false,
229
231
  $isNew: false,
230
232
  $persistedId: null,
231
233
  __entityName: targetEntityName ?? '',
@@ -106,18 +106,19 @@ function EntityByMode({
106
106
  })
107
107
 
108
108
  // Render based on status
109
- if (result.status === 'loading') {
109
+ if (result.$status === 'loading') {
110
110
  return <>{loading ?? <DefaultLoading />}</>
111
111
  }
112
112
 
113
- if (result.status === 'error') {
113
+ if (result.$status === 'error') {
114
+ const error: FieldError = result.$error ?? { source: 'load', message: 'Unknown error', category: 'unknown', retryable: false }
114
115
  if (errorFallback) {
115
- return <>{errorFallback(result.error)}</>
116
+ return <>{errorFallback(error)}</>
116
117
  }
117
- return <DefaultError error={result.error} />
118
+ return <DefaultError error={error} />
118
119
  }
119
120
 
120
- if (result.status === 'not_found') {
121
+ if (result.$status === 'not_found') {
121
122
  return <>{notFound ?? <DefaultNotFound entityType={entityType} by={by} />}</>
122
123
  }
123
124
 
@@ -271,14 +272,19 @@ function EntityHandleRenderer({
271
272
 
272
273
  const version = useSyncExternalStore(subscribe, getSnapshot, getSnapshot)
273
274
 
274
- const handle = useMemo(
275
- () => EntityHandle.create(entityId, entityType, store, dispatcher, schemaRegistry, undefined, selection),
275
+ const rawHandle = useMemo(
276
+ () => EntityHandle.createRaw(entityId, entityType, store, dispatcher, schemaRegistry, undefined, selection),
276
277
  [entityId, entityType, store, dispatcher, schemaRegistry, selection, version],
277
278
  )
278
279
 
279
- useEffect(() => () => { handle.dispose() }, [handle])
280
+ const handle = useMemo(
281
+ () => EntityHandle.wrapProxy(rawHandle),
282
+ [rawHandle],
283
+ )
284
+
285
+ useEffect(() => () => { rawHandle.dispose() }, [rawHandle])
280
286
 
281
- return <>{children(handle as unknown as EntityAccessor<unknown>)}</>
287
+ return <>{children(handle as EntityAccessor<unknown>)}</>
282
288
  }
283
289
 
284
290
  // ==================== Main Entity Component ====================
@@ -86,15 +86,15 @@ function EntityListComponent<TRoleMap extends Record<string, object>>({
86
86
  })
87
87
 
88
88
  // Render based on status
89
- if (result.status === 'loading') {
89
+ if (result.$status === 'loading') {
90
90
  return <>{loading ?? <DefaultLoading />}</>
91
91
  }
92
92
 
93
- if (result.status === 'error') {
93
+ if (result.$status === 'error') {
94
94
  if (errorFallback) {
95
- return <>{errorFallback(result.error)}</>
95
+ return <>{errorFallback(result.$error)}</>
96
96
  }
97
- return <DefaultError error={result.error} />
97
+ return <DefaultError error={result.$error} />
98
98
  }
99
99
 
100
100
  // Empty state
@@ -103,7 +103,7 @@ function EntityListComponent<TRoleMap extends Record<string, object>>({
103
103
  }
104
104
 
105
105
  // Phase 3: Runtime render — items are already EntityAccessors from the hook
106
- const items = result.items.map((item, index) => {
106
+ const items = result.items.map((item: (typeof result.items)[number], index: number) => {
107
107
  return (
108
108
  <React.Fragment key={item.id}>
109
109
  {children(item as unknown as EntityAccessor<CommonEntity<TRoleMap>>, index)}