@contember/bindx-react 0.1.4 → 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/dist/hooks/ContemberBindxProvider.d.ts +25 -30
- package/dist/hooks/ContemberBindxProvider.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useEntity.d.ts +43 -75
- package/dist/hooks/useEntity.d.ts.map +1 -1
- package/dist/hooks/useEntityList.d.ts +28 -47
- package/dist/hooks/useEntityList.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/jsx/collectorProxy.d.ts.map +1 -1
- package/dist/jsx/components/Entity.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/hooks/ContemberBindxProvider.tsx +31 -37
- package/src/hooks/index.ts +9 -9
- package/src/hooks/useEntity.ts +106 -217
- package/src/hooks/useEntityList.ts +61 -100
- package/src/index.ts +9 -9
- package/src/jsx/collectorProxy.ts +2 -0
- package/src/jsx/components/Entity.tsx +15 -9
- package/src/jsx/components/EntityList.tsx +5 -5
package/src/index.ts
CHANGED
|
@@ -186,15 +186,15 @@ export type {
|
|
|
186
186
|
BindxContextValue,
|
|
187
187
|
UseEntityOptions,
|
|
188
188
|
UseEntityListOptions,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
|
109
|
+
if (result.$status === 'loading') {
|
|
110
110
|
return <>{loading ?? <DefaultLoading />}</>
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
if (result
|
|
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(
|
|
116
|
+
return <>{errorFallback(error)}</>
|
|
116
117
|
}
|
|
117
|
-
return <DefaultError error={
|
|
118
|
+
return <DefaultError error={error} />
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
if (result
|
|
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
|
|
275
|
-
() => EntityHandle.
|
|
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
|
-
|
|
280
|
+
const handle = useMemo(
|
|
281
|
+
() => EntityHandle.wrapProxy(rawHandle),
|
|
282
|
+
[rawHandle],
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
useEffect(() => () => { rawHandle.dispose() }, [rawHandle])
|
|
280
286
|
|
|
281
|
-
return <>{children(handle as
|
|
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
|
|
89
|
+
if (result.$status === 'loading') {
|
|
90
90
|
return <>{loading ?? <DefaultLoading />}</>
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
if (result
|
|
93
|
+
if (result.$status === 'error') {
|
|
94
94
|
if (errorFallback) {
|
|
95
|
-
return <>{errorFallback(result
|
|
95
|
+
return <>{errorFallback(result.$error)}</>
|
|
96
96
|
}
|
|
97
|
-
return <DefaultError error={result
|
|
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)}
|