@contember/binding 1.1.0-alpha.0 → 1.1.0-alpha.3
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/development/accessorPropagation/useEntityListSubTree.js +4 -2
- package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useEntitySubTree.js +4 -2
- package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useExtendTree.js +27 -0
- package/dist/development/accessorPropagation/useExtendTree.js.map +1 -0
- package/dist/development/accessorTree/AccessorTree.js +9 -4
- package/dist/development/accessorTree/AccessorTree.js.map +1 -1
- package/dist/development/accessorTree/AccessorTreeStateContext.js +6 -0
- package/dist/development/accessorTree/AccessorTreeStateContext.js.map +1 -0
- package/dist/development/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/development/accessorTree/RuntimeId.js +17 -4
- package/dist/development/accessorTree/RuntimeId.js.map +1 -1
- package/dist/development/accessorTree/useAccessorTreeState.js +5 -0
- package/dist/development/accessorTree/useAccessorTreeState.js.map +1 -0
- package/dist/development/accessors/EntityAccessor.js +0 -32
- package/dist/development/accessors/EntityAccessor.js.map +1 -1
- package/dist/development/accessors/EntityListAccessor.js +1 -1
- package/dist/development/accessors/EntityListAccessor.js.map +1 -1
- package/dist/development/core/AccessorErrorManager.js +3 -0
- package/dist/development/core/AccessorErrorManager.js.map +1 -1
- package/dist/development/core/DataBinding.js +7 -6
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/DirtinessTracker.js +4 -13
- package/dist/development/core/DirtinessTracker.js.map +1 -1
- package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/development/core/EventManager.js +12 -7
- package/dist/development/core/EventManager.js.map +1 -1
- package/dist/development/core/MutationGenerator.js +100 -94
- package/dist/development/core/MutationGenerator.js.map +1 -1
- package/dist/development/core/RequestResponseNormalizer.js +27 -31
- package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/development/core/StateInitializer.js +23 -26
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/TreeAugmenter.js +10 -10
- package/dist/development/core/TreeAugmenter.js.map +1 -1
- package/dist/development/core/TreeFilterGenerator.js +2 -2
- package/dist/development/core/TreeFilterGenerator.js.map +1 -1
- package/dist/development/core/TreeStore.js +5 -5
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/operations/EntityOperations.js +12 -11
- package/dist/development/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/core/operations/FieldOperations.js +2 -2
- package/dist/development/core/operations/FieldOperations.js.map +1 -1
- package/dist/development/core/operations/ListOperations.js +3 -3
- package/dist/development/core/operations/ListOperations.js.map +1 -1
- package/dist/development/core/operations/OperationsHelpers.js +2 -2
- package/dist/development/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/development/core/requestAliases/MutationAlias.js +5 -3
- package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/development/core/schema/SchemaPreprocessor.js +1 -1
- package/dist/development/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/development/dao/Environment.js +12 -2
- package/dist/development/dao/Environment.js.map +1 -1
- package/dist/development/dao/TreeNodeEnvironmentFactory.js +2 -2
- package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/development/helperComponents/DeferredSubTrees.js +4 -2
- package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/development/helperComponents/If.js +39 -0
- package/dist/development/helperComponents/If.js.map +1 -0
- package/dist/development/helperComponents/SugaredField.js +1 -1
- package/dist/development/helperComponents/helpers/FilterEvaluator.js +38 -0
- package/dist/development/helperComponents/helpers/FilterEvaluator.js.map +1 -0
- package/dist/development/helperComponents/helpers/FilterFieldsCollector.js +41 -0
- package/dist/development/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
- package/dist/development/helperComponents/helpers/evaluateCondition.js +46 -0
- package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -0
- package/dist/development/index.js +4 -1
- package/dist/development/index.js.map +1 -1
- package/dist/development/markers/EntityListSubTreeMarker.js +1 -1
- package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/development/markers/EntitySubTreeMarker.js +1 -1
- package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/development/markers/PlaceholderGenerator.js +4 -4
- package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/development/utils/Hashing.js +21 -6
- package/dist/development/utils/Hashing.js.map +1 -1
- package/dist/production/accessorPropagation/useEntityListSubTree.js +4 -2
- package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useEntitySubTree.js +4 -2
- package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useExtendTree.js +27 -0
- package/dist/production/accessorPropagation/useExtendTree.js.map +1 -0
- package/dist/production/accessorTree/AccessorTree.js +9 -4
- package/dist/production/accessorTree/AccessorTree.js.map +1 -1
- package/dist/production/accessorTree/AccessorTreeStateContext.js +6 -0
- package/dist/production/accessorTree/AccessorTreeStateContext.js.map +1 -0
- package/dist/production/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/production/accessorTree/RuntimeId.js +17 -4
- package/dist/production/accessorTree/RuntimeId.js.map +1 -1
- package/dist/production/accessorTree/useAccessorTreeState.js +5 -0
- package/dist/production/accessorTree/useAccessorTreeState.js.map +1 -0
- package/dist/production/accessors/EntityAccessor.js +0 -32
- package/dist/production/accessors/EntityAccessor.js.map +1 -1
- package/dist/production/accessors/EntityListAccessor.js +1 -1
- package/dist/production/accessors/EntityListAccessor.js.map +1 -1
- package/dist/production/core/AccessorErrorManager.js +3 -0
- package/dist/production/core/AccessorErrorManager.js.map +1 -1
- package/dist/production/core/DataBinding.js +7 -6
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/DirtinessTracker.js +4 -13
- package/dist/production/core/DirtinessTracker.js.map +1 -1
- package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/production/core/EventManager.js +11 -6
- package/dist/production/core/EventManager.js.map +1 -1
- package/dist/production/core/MutationGenerator.js +100 -94
- package/dist/production/core/MutationGenerator.js.map +1 -1
- package/dist/production/core/RequestResponseNormalizer.js +27 -31
- package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/production/core/StateInitializer.js +23 -26
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/TreeAugmenter.js +10 -10
- package/dist/production/core/TreeAugmenter.js.map +1 -1
- package/dist/production/core/TreeFilterGenerator.js +2 -2
- package/dist/production/core/TreeFilterGenerator.js.map +1 -1
- package/dist/production/core/TreeStore.js +5 -5
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/operations/EntityOperations.js +12 -11
- package/dist/production/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/core/operations/FieldOperations.js.map +1 -1
- package/dist/production/core/operations/ListOperations.js +3 -3
- package/dist/production/core/operations/ListOperations.js.map +1 -1
- package/dist/production/core/operations/OperationsHelpers.js +2 -2
- package/dist/production/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/production/core/requestAliases/MutationAlias.js +5 -3
- package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/production/core/schema/SchemaPreprocessor.js +1 -1
- package/dist/production/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/production/dao/Environment.js +12 -2
- package/dist/production/dao/Environment.js.map +1 -1
- package/dist/production/dao/TreeNodeEnvironmentFactory.js +2 -2
- package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/production/helperComponents/DeferredSubTrees.js +4 -2
- package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/production/helperComponents/If.js +39 -0
- package/dist/production/helperComponents/If.js.map +1 -0
- package/dist/production/helperComponents/SugaredField.js +1 -1
- package/dist/production/helperComponents/helpers/FilterEvaluator.js +38 -0
- package/dist/production/helperComponents/helpers/FilterEvaluator.js.map +1 -0
- package/dist/production/helperComponents/helpers/FilterFieldsCollector.js +41 -0
- package/dist/production/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
- package/dist/production/helperComponents/helpers/evaluateCondition.js +46 -0
- package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -0
- package/dist/production/index.js +4 -1
- package/dist/production/index.js.map +1 -1
- package/dist/production/markers/EntityListSubTreeMarker.js +1 -1
- package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/production/markers/EntitySubTreeMarker.js +1 -1
- package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/production/markers/PlaceholderGenerator.js +4 -4
- package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/production/utils/Hashing.js +21 -6
- package/dist/production/utils/Hashing.js.map +1 -1
- package/dist/types/accessorPropagation/index.d.ts +1 -0
- package/dist/types/accessorPropagation/index.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntityListSubTree.d.ts +2 -1
- package/dist/types/accessorPropagation/useEntityListSubTree.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntitySubTree.d.ts +2 -1
- package/dist/types/accessorPropagation/useEntitySubTree.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useExtendTree.d.ts +5 -0
- package/dist/types/accessorPropagation/useExtendTree.d.ts.map +1 -0
- package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -1
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts +4 -0
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts.map +1 -0
- package/dist/types/accessorTree/MutationRequestResponse.d.ts +5 -1
- package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts +4 -4
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -1
- package/dist/types/accessorTree/PersistResult.d.ts +2 -1
- package/dist/types/accessorTree/PersistResult.d.ts.map +1 -1
- package/dist/types/accessorTree/QueryRequestResponse.d.ts +11 -10
- package/dist/types/accessorTree/QueryRequestResponse.d.ts.map +1 -1
- package/dist/types/accessorTree/RuntimeId.d.ts +16 -6
- package/dist/types/accessorTree/RuntimeId.d.ts.map +1 -1
- package/dist/types/accessorTree/index.d.ts +1 -0
- package/dist/types/accessorTree/index.d.ts.map +1 -1
- package/dist/types/accessorTree/useAccessorTreeState.d.ts +2 -0
- package/dist/types/accessorTree/useAccessorTreeState.d.ts.map +1 -0
- package/dist/types/accessors/EntityAccessor.d.ts +1 -3
- package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
- package/dist/types/accessors/EntityListAccessor.d.ts +2 -2
- package/dist/types/accessors/EntityListAccessor.d.ts.map +1 -1
- package/dist/types/core/AccessorErrorManager.d.ts.map +1 -1
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/core/DirtinessTracker.d.ts +2 -5
- package/dist/types/core/DirtinessTracker.d.ts.map +1 -1
- package/dist/types/core/ErrorsPreprocessor.d.ts +2 -2
- package/dist/types/core/ErrorsPreprocessor.d.ts.map +1 -1
- package/dist/types/core/EventManager.d.ts +1 -1
- package/dist/types/core/EventManager.d.ts.map +1 -1
- package/dist/types/core/MutationGenerator.d.ts.map +1 -1
- package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -1
- package/dist/types/core/StateInitializer.d.ts +1 -5
- package/dist/types/core/StateInitializer.d.ts.map +1 -1
- package/dist/types/core/TreeStore.d.ts +3 -3
- package/dist/types/core/TreeStore.d.ts.map +1 -1
- package/dist/types/core/operations/EntityOperations.d.ts.map +1 -1
- package/dist/types/core/operations/ListOperations.d.ts +2 -1
- package/dist/types/core/operations/ListOperations.d.ts.map +1 -1
- package/dist/types/core/requestAliases/MutationAlias.d.ts.map +1 -1
- package/dist/types/core/schema/RawSchemaEntity.d.ts +3 -2
- package/dist/types/core/schema/RawSchemaEntity.d.ts.map +1 -1
- package/dist/types/core/schema/SchemaEntity.d.ts +1 -1
- package/dist/types/core/schema/SchemaEntity.d.ts.map +1 -1
- package/dist/types/dao/Environment.d.ts +7 -5
- package/dist/types/dao/Environment.d.ts.map +1 -1
- package/dist/types/helperComponents/If.d.ts +14 -0
- package/dist/types/helperComponents/If.d.ts.map +1 -0
- package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts +9 -0
- package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts.map +1 -0
- package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts +10 -0
- package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts.map +1 -0
- package/dist/types/helperComponents/helpers/evaluateCondition.d.ts +4 -0
- package/dist/types/helperComponents/helpers/evaluateCondition.d.ts.map +1 -0
- package/dist/types/helperComponents/index.d.ts +1 -0
- package/dist/types/helperComponents/index.d.ts.map +1 -1
- package/dist/types/markers/PlaceholderGenerator.d.ts +3 -2
- package/dist/types/markers/PlaceholderGenerator.d.ts.map +1 -1
- package/dist/types/treeParameters/primitives/EntityId.d.ts +1 -1
- package/dist/types/treeParameters/primitives/EntityId.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/Hashing.d.ts +3 -2
- package/dist/types/utils/Hashing.d.ts.map +1 -1
- package/package.json +7 -5
- package/src/accessorPropagation/index.ts +1 -0
- package/src/accessorPropagation/useEntityListSubTree.ts +8 -1
- package/src/accessorPropagation/useEntitySubTree.ts +8 -1
- package/src/accessorPropagation/useExtendTree.ts +30 -0
- package/src/accessorTree/AccessorTree.tsx +18 -12
- package/src/accessorTree/AccessorTreeStateContext.ts +6 -0
- package/src/accessorTree/MutationRequestResponse.ts +3 -1
- package/src/accessorTree/NormalizedPersistedData.ts +4 -4
- package/src/accessorTree/PersistResult.ts +2 -1
- package/src/accessorTree/QueryRequestResponse.ts +17 -14
- package/src/accessorTree/RuntimeId.ts +27 -6
- package/src/accessorTree/index.ts +1 -0
- package/src/accessorTree/useAccessorTreeState.ts +4 -0
- package/src/accessors/EntityAccessor.ts +2 -51
- package/src/accessors/EntityListAccessor.ts +3 -3
- package/src/core/AccessorErrorManager.ts +3 -0
- package/src/core/DataBinding.ts +6 -7
- package/src/core/DirtinessTracker.ts +4 -16
- package/src/core/ErrorsPreprocessor.ts +2 -2
- package/src/core/EventManager.ts +14 -8
- package/src/core/MutationGenerator.ts +137 -130
- package/src/core/RequestResponseNormalizer.ts +37 -38
- package/src/core/StateInitializer.ts +35 -42
- package/src/core/TreeAugmenter.ts +11 -11
- package/src/core/TreeFilterGenerator.ts +5 -5
- package/src/core/TreeStore.ts +14 -6
- package/src/core/operations/EntityOperations.ts +12 -13
- package/src/core/operations/FieldOperations.ts +2 -2
- package/src/core/operations/ListOperations.ts +6 -5
- package/src/core/operations/OperationsHelpers.ts +2 -2
- package/src/core/requestAliases/MutationAlias.ts +5 -3
- package/src/core/schema/RawSchemaEntity.ts +1 -2
- package/src/core/schema/SchemaEntity.ts +1 -1
- package/src/core/schema/SchemaPreprocessor.ts +1 -1
- package/src/dao/Environment.ts +18 -7
- package/src/dao/TreeNodeEnvironmentFactory.ts +2 -2
- package/src/helperComponents/DeferredSubTrees.tsx +4 -4
- package/src/helperComponents/If.tsx +71 -0
- package/src/helperComponents/helpers/FilterEvaluator.ts +48 -0
- package/src/helperComponents/helpers/FilterFieldsCollector.ts +49 -0
- package/src/helperComponents/helpers/evaluateCondition.ts +52 -0
- package/src/helperComponents/index.ts +1 -0
- package/src/markers/EntityListSubTreeMarker.ts +1 -1
- package/src/markers/EntitySubTreeMarker.ts +1 -1
- package/src/markers/PlaceholderGenerator.ts +5 -2
- package/src/treeParameters/primitives/EntityId.ts +1 -1
- package/src/utils/Hashing.ts +23 -8
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/binding",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "1.1.0-alpha.
|
|
4
|
+
"version": "1.1.0-alpha.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
],
|
|
20
20
|
"typings": "./dist/types/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@contember/client": "1.1.0-alpha.
|
|
23
|
-
"@contember/react-client": "1.1.0-alpha.
|
|
24
|
-
"@contember/react-multipass-rendering": "1.1.0-alpha.
|
|
25
|
-
"@contember/react-utils": "1.1.0-alpha.
|
|
22
|
+
"@contember/client": "1.1.0-alpha.3",
|
|
23
|
+
"@contember/react-client": "1.1.0-alpha.3",
|
|
24
|
+
"@contember/react-multipass-rendering": "1.1.0-alpha.3",
|
|
25
|
+
"@contember/react-utils": "1.1.0-alpha.3",
|
|
26
26
|
"chevrotain": "6.5.0",
|
|
27
27
|
"fast-deep-equal": "^3.1.3",
|
|
28
28
|
"js-levenshtein": "1.1.6",
|
|
@@ -42,6 +42,8 @@
|
|
|
42
42
|
"build": "pnpm run build:js:dev && pnpm run build:js:prod",
|
|
43
43
|
"build:js:dev": "vite build --mode development",
|
|
44
44
|
"build:js:prod": "vite build --mode production",
|
|
45
|
+
"ae:build": "api-extractor run --local",
|
|
46
|
+
"ae:test": "api-extractor run",
|
|
45
47
|
"test": "vitest"
|
|
46
48
|
}
|
|
47
49
|
}
|
|
@@ -20,6 +20,7 @@ export * from './useEntityListSubTreeParameters'
|
|
|
20
20
|
export * from './useEntitySubTree'
|
|
21
21
|
export * from './useEntitySubTreeParameters'
|
|
22
22
|
export * from './useEnvironment'
|
|
23
|
+
export * from './useExtendTree'
|
|
23
24
|
export * from './useField'
|
|
24
25
|
export * from './useGetEntityByKey'
|
|
25
26
|
export * from './useGetEntityListSubTree'
|
|
@@ -4,13 +4,20 @@ import type { Alias, SugaredQualifiedEntityList, SugaredUnconstrainedQualifiedEn
|
|
|
4
4
|
import { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription'
|
|
5
5
|
import { useEntityListSubTreeParameters } from './useEntityListSubTreeParameters'
|
|
6
6
|
import { useGetEntityListSubTree } from './useGetEntityListSubTree'
|
|
7
|
+
import { TreeRootId } from '../treeParameters'
|
|
7
8
|
|
|
8
9
|
export const useEntityListSubTree = (
|
|
9
10
|
qualifiedEntityList: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,
|
|
11
|
+
...treeId: [TreeRootId | undefined] | []
|
|
10
12
|
): EntityListAccessor => {
|
|
11
13
|
const getSubTree = useGetEntityListSubTree()
|
|
12
14
|
const parameters = useEntityListSubTreeParameters(qualifiedEntityList)
|
|
13
|
-
const
|
|
15
|
+
const hasTreeId = treeId.length > 0
|
|
16
|
+
const treeIdVal = treeId[0]
|
|
17
|
+
const getAccessor = useCallback(
|
|
18
|
+
() => getSubTree(parameters, ...(hasTreeId ? [treeIdVal] : [])),
|
|
19
|
+
[getSubTree, hasTreeId, parameters, treeIdVal],
|
|
20
|
+
)
|
|
14
21
|
|
|
15
22
|
// if (typeof parameters !== 'string' && parameters.value.hasOneRelationPath.length) {
|
|
16
23
|
// throw new BindingError(`useEntityListSubTree: cannot use hasOneRelationPath!`)
|
|
@@ -4,13 +4,20 @@ import type { Alias, SugaredQualifiedSingleEntity, SugaredUnconstrainedQualified
|
|
|
4
4
|
import { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription'
|
|
5
5
|
import { useEntitySubTreeParameters } from './useEntitySubTreeParameters'
|
|
6
6
|
import { useGetEntitySubTree } from './useGetEntitySubTree'
|
|
7
|
+
import { TreeRootId } from '../treeParameters'
|
|
7
8
|
|
|
8
9
|
export const useEntitySubTree = (
|
|
9
10
|
qualifiedSingleEntity: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,
|
|
11
|
+
...treeId: [TreeRootId | undefined] | []
|
|
10
12
|
): EntityAccessor => {
|
|
11
13
|
const getSubTree = useGetEntitySubTree()
|
|
12
14
|
const parameters = useEntitySubTreeParameters(qualifiedSingleEntity)
|
|
13
|
-
const
|
|
15
|
+
const hasTreeId = treeId.length > 0
|
|
16
|
+
const treeIdVal = treeId[0]
|
|
17
|
+
const getAccessor = useCallback(
|
|
18
|
+
() => getSubTree(parameters, ...(hasTreeId ? [treeIdVal] : [])),
|
|
19
|
+
[getSubTree, hasTreeId, parameters, treeIdVal],
|
|
20
|
+
)
|
|
14
21
|
|
|
15
22
|
// if (typeof parameters !== 'string' && parameters.hasOneRelationPath.length) {
|
|
16
23
|
// throw new BindingError(`useEntitySubTree: cannot use hasOneRelationPath!`)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ReactNode, useCallback } from 'react'
|
|
2
|
+
import { useAbortController, useIsMounted } from '@contember/react-utils'
|
|
3
|
+
import { useBindingOperations } from './useBindingOperations'
|
|
4
|
+
import { TreeRootId } from '../treeParameters'
|
|
5
|
+
import { ExtendTreeOptions } from '../accessors'
|
|
6
|
+
import { DataBindingExtendAborted } from '../core'
|
|
7
|
+
import { useEnvironment } from './useEnvironment'
|
|
8
|
+
|
|
9
|
+
export const useExtendTree = () => {
|
|
10
|
+
const abort = useAbortController()
|
|
11
|
+
const { extendTree } = useBindingOperations()
|
|
12
|
+
const isMountedRef = useIsMounted()
|
|
13
|
+
const environment = useEnvironment()
|
|
14
|
+
return useCallback(async (newFragment: ReactNode, options?: Omit<ExtendTreeOptions, 'signal'>): Promise<TreeRootId | undefined> => {
|
|
15
|
+
try {
|
|
16
|
+
const newTreeRootId = await extendTree(newFragment,
|
|
17
|
+
{ environment, ...options, signal: abort() },
|
|
18
|
+
)
|
|
19
|
+
if (!isMountedRef.current) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
return newTreeRootId
|
|
23
|
+
} catch (e) {
|
|
24
|
+
if (e === DataBindingExtendAborted) {
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
throw e
|
|
28
|
+
}
|
|
29
|
+
}, [abort, environment, extendTree, isMountedRef])
|
|
30
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react'
|
|
2
2
|
import { BindingOperationsProvider } from '../accessorPropagation'
|
|
3
3
|
import type { AccessorTreeState } from './AccessorTreeState'
|
|
4
|
+
import { AccessorTreeStateContext } from './AccessorTreeStateContext'
|
|
4
5
|
import { DirtinessContext } from './DirtinessContext'
|
|
5
6
|
import { MutationStateContext } from './MutationStateContext'
|
|
6
7
|
|
|
@@ -14,21 +15,26 @@ export function AccessorTree({ state, children }: AccessorTreeProps) {
|
|
|
14
15
|
// remounts.
|
|
15
16
|
if (state.name === 'initialized') {
|
|
16
17
|
return (
|
|
17
|
-
<
|
|
18
|
-
<
|
|
19
|
-
<
|
|
20
|
-
{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
<AccessorTreeStateContext.Provider value={state}>
|
|
19
|
+
<DirtinessContext.Provider value={state.data.hasUnpersistedChanges}>
|
|
20
|
+
<MutationStateContext.Provider value={state.data.isMutating}>
|
|
21
|
+
<BindingOperationsProvider bindingOperations={state.data.bindingOperations}>
|
|
22
|
+
{children}
|
|
23
|
+
</BindingOperationsProvider>
|
|
24
|
+
</MutationStateContext.Provider>
|
|
25
|
+
</DirtinessContext.Provider>
|
|
26
|
+
</AccessorTreeStateContext.Provider>
|
|
24
27
|
)
|
|
25
28
|
}
|
|
26
29
|
return (
|
|
27
|
-
<
|
|
28
|
-
<
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
<AccessorTreeStateContext.Provider value={state}>
|
|
31
|
+
<DirtinessContext.Provider value={false}>
|
|
32
|
+
<MutationStateContext.Provider value={false}>
|
|
33
|
+
<BindingOperationsProvider bindingOperations={undefined}>{children}</BindingOperationsProvider>
|
|
34
|
+
</MutationStateContext.Provider>
|
|
35
|
+
</DirtinessContext.Provider>
|
|
36
|
+
</AccessorTreeStateContext.Provider>
|
|
32
37
|
)
|
|
33
38
|
}
|
|
39
|
+
|
|
34
40
|
AccessorTree.displayName = 'AccessorTree'
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Result } from '@contember/client'
|
|
2
2
|
import type { ReceivedEntityData } from './QueryRequestResponse'
|
|
3
3
|
|
|
4
|
+
type WithType<V, Type extends string> = V & { __typename: Type }
|
|
5
|
+
|
|
4
6
|
export interface FieldPathErrorFragment {
|
|
5
7
|
__typename: '_FieldPathFragment'
|
|
6
8
|
field: string
|
|
@@ -47,7 +49,7 @@ export interface MutationDataResponse {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
export interface MutationTransactionResponse {
|
|
50
|
-
transaction: MutationDataResponse | null
|
|
52
|
+
transaction: WithType<MutationDataResponse, 'MutationTransaction'> | null
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
export interface MutationRequestResponse {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { EntityId, PlaceholderName, Scalar } from '../treeParameters'
|
|
2
|
-
import type {
|
|
2
|
+
import type { ServerId, UniqueEntityId } from './RuntimeId'
|
|
3
3
|
|
|
4
4
|
// HasMany relations are encoded as sets of entity ids.
|
|
5
5
|
// HasOne relations are encoded as BoxedSingleEntityId just to make them different from actual strings.
|
|
6
6
|
// Not sure whether that is a reasonable precaution or just pure overhead.
|
|
7
|
-
export type EntityFieldPersistedData = Scalar |
|
|
7
|
+
export type EntityFieldPersistedData = Scalar | ServerId | EntityListPersistedData
|
|
8
8
|
|
|
9
9
|
export type SingleEntityPersistedData = Map<PlaceholderName, EntityFieldPersistedData>
|
|
10
10
|
|
|
11
11
|
export type EntityListPersistedData = Set<EntityId>
|
|
12
12
|
|
|
13
|
-
export type PersistedEntityDataStore = Map<
|
|
13
|
+
export type PersistedEntityDataStore = Map<UniqueEntityId, SingleEntityPersistedData>
|
|
14
14
|
|
|
15
15
|
// The key is the subTree placeholder name
|
|
16
|
-
export type SubTreeDataStore = Map<PlaceholderName,
|
|
16
|
+
export type SubTreeDataStore = Map<PlaceholderName, ServerId | EntityListPersistedData>
|
|
17
17
|
|
|
18
18
|
export class NormalizedPersistedData {
|
|
19
19
|
public constructor(
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RequestError } from './RequestError'
|
|
2
2
|
import { ErrorAccessor } from '../accessors'
|
|
3
|
+
import { EntityId } from '../treeParameters'
|
|
3
4
|
|
|
4
5
|
export interface NothingToPersistPersistResult {
|
|
5
6
|
type: 'nothingToPersist'
|
|
@@ -7,7 +8,7 @@ export interface NothingToPersistPersistResult {
|
|
|
7
8
|
|
|
8
9
|
export interface JustSuccessPersistResult {
|
|
9
10
|
type: 'justSuccess'
|
|
10
|
-
persistedEntityIds:
|
|
11
|
+
persistedEntityIds: EntityId[]
|
|
11
12
|
afterPersistError?: any
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import type { Scalar } from '../treeParameters'
|
|
1
|
+
import type { EntityId, Scalar } from '../treeParameters'
|
|
2
2
|
|
|
3
|
-
export type ReceivedFieldData
|
|
4
|
-
export type ReceivedEntityData<A = never> =
|
|
5
|
-
| A
|
|
6
|
-
| {
|
|
7
|
-
id: string
|
|
8
|
-
__typename: string
|
|
9
|
-
[fieldName: string]: ReceivedFieldData<A>
|
|
10
|
-
}
|
|
11
|
-
export type ReceivedData<A = never> = A | ReceivedEntityData<A> | ReceivedEntityData<A>[]
|
|
3
|
+
export type ReceivedFieldData = Scalar | ReceivedEntityData | Array<ReceivedEntityData>
|
|
12
4
|
|
|
13
|
-
export
|
|
14
|
-
|
|
5
|
+
export type ReceivedEntityData =
|
|
6
|
+
& {
|
|
7
|
+
__typename: string
|
|
8
|
+
id: EntityId
|
|
9
|
+
}
|
|
10
|
+
& {
|
|
11
|
+
[fieldName: string]: ReceivedFieldData
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ReceivedData = ReceivedEntityData | ReceivedEntityData[]
|
|
15
|
+
|
|
16
|
+
export interface ReceivedDataTree {
|
|
17
|
+
[treeId: string]: ReceivedData | null
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
export interface QueryRequestResponse
|
|
18
|
-
data: ReceivedDataTree
|
|
20
|
+
export interface QueryRequestResponse {
|
|
21
|
+
data: ReceivedDataTree
|
|
19
22
|
errors?: { message: string, path?: string[] }[]
|
|
20
23
|
}
|
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import { generateEnumerabilityPreventingEntropy } from '../utils'
|
|
2
|
+
import { EntityId } from '../treeParameters'
|
|
3
|
+
|
|
4
|
+
export type UniqueEntityId = string & { __type: 'UniqueEntityId' }
|
|
2
5
|
|
|
3
6
|
export interface RuntimeIdSpec {
|
|
4
7
|
existsOnServer: boolean
|
|
5
|
-
value:
|
|
8
|
+
value: EntityId
|
|
9
|
+
uniqueValue: UniqueEntityId
|
|
6
10
|
}
|
|
7
11
|
|
|
8
|
-
export class
|
|
12
|
+
export class ServerId implements RuntimeIdSpec {
|
|
9
13
|
public get existsOnServer(): true {
|
|
10
14
|
return true
|
|
11
15
|
}
|
|
12
|
-
public constructor(public readonly value: string) {
|
|
16
|
+
public constructor(public readonly value: EntityId, public readonly entityName: string) {
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get uniqueValue() {
|
|
20
|
+
return ServerId.formatUniqueValue(this.value, this.entityName)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static formatUniqueValue(id: EntityId, entityName: string): UniqueEntityId {
|
|
24
|
+
return `${entityName}_${id}` as UniqueEntityId
|
|
25
|
+
}
|
|
13
26
|
}
|
|
14
27
|
|
|
15
28
|
export class ClientGeneratedUuid implements RuntimeIdSpec {
|
|
@@ -17,6 +30,10 @@ export class ClientGeneratedUuid implements RuntimeIdSpec {
|
|
|
17
30
|
return false
|
|
18
31
|
}
|
|
19
32
|
public constructor(public readonly value: string) {}
|
|
33
|
+
|
|
34
|
+
get uniqueValue() {
|
|
35
|
+
return this.value as UniqueEntityId
|
|
36
|
+
}
|
|
20
37
|
}
|
|
21
38
|
|
|
22
39
|
export class UnpersistedEntityDummyId implements RuntimeIdSpec {
|
|
@@ -41,9 +58,13 @@ export class UnpersistedEntityDummyId implements RuntimeIdSpec {
|
|
|
41
58
|
|
|
42
59
|
private static entropyLength = 5
|
|
43
60
|
private static dummyIdRegex = new RegExp(`^adminOnlyDummyId-\\d{${UnpersistedEntityDummyId.entropyLength}}-\\d+$`)
|
|
44
|
-
public static matchesDummyId(candidate:
|
|
45
|
-
return UnpersistedEntityDummyId.dummyIdRegex.test(candidate)
|
|
61
|
+
public static matchesDummyId(candidate: EntityId): boolean {
|
|
62
|
+
return typeof candidate === 'string' && UnpersistedEntityDummyId.dummyIdRegex.test(candidate)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get uniqueValue() {
|
|
66
|
+
return this.value as UniqueEntityId
|
|
46
67
|
}
|
|
47
68
|
}
|
|
48
69
|
|
|
49
|
-
export type RuntimeId =
|
|
70
|
+
export type RuntimeId = ServerId | ClientGeneratedUuid | UnpersistedEntityDummyId
|
|
@@ -13,6 +13,7 @@ export * from './PersistResult'
|
|
|
13
13
|
export * from './QueryRequestResponse'
|
|
14
14
|
export * from './RequestError'
|
|
15
15
|
export * from './RuntimeId'
|
|
16
|
+
export * from './useAccessorTreeState'
|
|
16
17
|
export * from './useDataBinding'
|
|
17
18
|
export * from './useDirtinessState'
|
|
18
19
|
export * from './useMutationState'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RuntimeId,
|
|
1
|
+
import { RuntimeId, SingleEntityPersistedData } from '../accessorTree'
|
|
2
2
|
import { BindingError } from '../BindingError'
|
|
3
3
|
import type { EntityOperations } from '../core/operations'
|
|
4
4
|
import type { Environment } from '../dao'
|
|
@@ -42,7 +42,7 @@ class EntityAccessor implements Errorable {
|
|
|
42
42
|
public readonly getAccessor: EntityAccessor.GetEntityAccessor,
|
|
43
43
|
) {}
|
|
44
44
|
|
|
45
|
-
public get idOnServer():
|
|
45
|
+
public get idOnServer(): EntityId | undefined {
|
|
46
46
|
return this.runtimeId.existsOnServer ? this.runtimeId.value : undefined
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -116,21 +116,6 @@ class EntityAccessor implements Errorable {
|
|
|
116
116
|
return this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment))
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
public getKeyConnectedOnServer(entity: SugaredRelativeSingleEntity | string): string | null {
|
|
120
|
-
const desugared = QueryLanguage.desugarRelativeSingleEntity(entity, this.environment)
|
|
121
|
-
const lastHasOne = desugared.hasOneRelationPath[desugared.hasOneRelationPath.length - 1]
|
|
122
|
-
const lastHasOnePlaceholder = PlaceholderGenerator.getHasOneRelationPlaceholder(lastHasOne)
|
|
123
|
-
|
|
124
|
-
let containingAccessor: EntityAccessor = this
|
|
125
|
-
|
|
126
|
-
if (desugared.hasOneRelationPath.length > 1) {
|
|
127
|
-
containingAccessor = this.getRelativeSingleEntity({
|
|
128
|
-
hasOneRelationPath: desugared.hasOneRelationPath.slice(0, -1),
|
|
129
|
-
})
|
|
130
|
-
}
|
|
131
|
-
return containingAccessor.getPersistedKeyByPlaceholder(lastHasOnePlaceholder)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
119
|
//
|
|
135
120
|
|
|
136
121
|
/**
|
|
@@ -173,40 +158,6 @@ class EntityAccessor implements Errorable {
|
|
|
173
158
|
}
|
|
174
159
|
return record.getAccessor()
|
|
175
160
|
}
|
|
176
|
-
|
|
177
|
-
private getPersistedKeyByPlaceholder(placeholderName: string): string | null {
|
|
178
|
-
if (this.dataFromServer === undefined) {
|
|
179
|
-
return null
|
|
180
|
-
}
|
|
181
|
-
const key = this.dataFromServer.get(placeholderName)
|
|
182
|
-
|
|
183
|
-
if (key instanceof ServerGeneratedUuid) {
|
|
184
|
-
return key.value
|
|
185
|
-
}
|
|
186
|
-
if (key === null) {
|
|
187
|
-
// TODO this also returns null and fails to throw when placeholderName points to a regular scalar field that
|
|
188
|
-
// happens to be also null.
|
|
189
|
-
return null
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// From now on, we're past the happy path, way into error land.
|
|
193
|
-
if (key === undefined) {
|
|
194
|
-
throw new BindingError(
|
|
195
|
-
`EntityAccessor.getKeyConnectedOnServer: unknown placeholder '${placeholderName}'. Unless this is just ` +
|
|
196
|
-
`a typo, this typically happens when a has-one relation hasn't been registered during static render.`,
|
|
197
|
-
)
|
|
198
|
-
}
|
|
199
|
-
if (key instanceof Set) {
|
|
200
|
-
throw new BindingError(
|
|
201
|
-
`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a has-many relation, ` +
|
|
202
|
-
`not a has-one. This method is meant exclusively for has-one relations.`,
|
|
203
|
-
)
|
|
204
|
-
}
|
|
205
|
-
throw new BindingError(
|
|
206
|
-
`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a scalar field, not a` +
|
|
207
|
-
`has-one relation. This method is meant exclusively for has-one relations.`,
|
|
208
|
-
)
|
|
209
|
-
}
|
|
210
161
|
}
|
|
211
162
|
|
|
212
163
|
namespace EntityAccessor {
|
|
@@ -16,7 +16,7 @@ class EntityListAccessor implements Errorable {
|
|
|
16
16
|
private readonly stateKey: EntityListState,
|
|
17
17
|
private readonly operations: ListOperations,
|
|
18
18
|
private readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,
|
|
19
|
-
private readonly _idsPersistedOnServer: ReadonlySet<
|
|
19
|
+
private readonly _idsPersistedOnServer: ReadonlySet<EntityId>,
|
|
20
20
|
public readonly hasUnpersistedChanges: boolean,
|
|
21
21
|
public readonly errors: ErrorAccessor | undefined,
|
|
22
22
|
public readonly environment: Environment,
|
|
@@ -42,7 +42,7 @@ class EntityListAccessor implements Errorable {
|
|
|
42
42
|
* This will only contain the ids that the server knows about. Not necessarily the ids that have been added on
|
|
43
43
|
* the list since the last server query.
|
|
44
44
|
*/
|
|
45
|
-
public get idsPersistedOnServer(): Set<
|
|
45
|
+
public get idsPersistedOnServer(): Set<EntityId> {
|
|
46
46
|
return new Set(this._idsPersistedOnServer)
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -65,7 +65,7 @@ class EntityListAccessor implements Errorable {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
public hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean {
|
|
68
|
-
if (typeof entityOrItsId === 'string') {
|
|
68
|
+
if (typeof entityOrItsId === 'string' || typeof entityOrItsId === 'number') {
|
|
69
69
|
return this.idsPersistedOnServer.has(entityOrItsId)
|
|
70
70
|
}
|
|
71
71
|
const idOnServer = entityOrItsId.idOnServer
|
|
@@ -134,6 +134,9 @@ export class AccessorErrorManager {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
for (const [childKey, child] of errors.children) {
|
|
137
|
+
if (typeof childKey !== 'string') {
|
|
138
|
+
continue
|
|
139
|
+
}
|
|
137
140
|
if (child.nodeType === 'leaf') {
|
|
138
141
|
const fieldState = state.children.get(childKey)
|
|
139
142
|
|
package/src/core/DataBinding.ts
CHANGED
|
@@ -89,7 +89,6 @@ export class DataBinding {
|
|
|
89
89
|
this.stateInitializer = new StateInitializer(
|
|
90
90
|
this.accessorErrorManager,
|
|
91
91
|
this.batchUpdatesOptions,
|
|
92
|
-
this.config,
|
|
93
92
|
this.eventManager,
|
|
94
93
|
this.treeStore,
|
|
95
94
|
)
|
|
@@ -171,15 +170,15 @@ export class DataBinding {
|
|
|
171
170
|
errors: mutationResponse.errors,
|
|
172
171
|
})
|
|
173
172
|
}
|
|
174
|
-
|
|
175
|
-
const mutationData = mutationResponse.data?.transaction ?? {}
|
|
176
|
-
const aliases = Object.keys(mutationData)
|
|
177
|
-
if (!mutationResponse.data) {
|
|
173
|
+
if (!mutationResponse.data?.transaction) {
|
|
178
174
|
throw {
|
|
179
|
-
errors:
|
|
175
|
+
errors: [],
|
|
180
176
|
type: 'invalidResponse',
|
|
181
177
|
}
|
|
182
|
-
}
|
|
178
|
+
}
|
|
179
|
+
const { __typename, ...mutationData } = mutationResponse.data.transaction
|
|
180
|
+
const aliases = Object.keys(mutationData)
|
|
181
|
+
if (aliases.every(item => mutationData[item].ok)) {
|
|
183
182
|
const persistedEntityIds = aliases.map(alias => mutationData[alias].node?.id).filter(id => id !== undefined)
|
|
184
183
|
const result: SuccessfulPersistResult = {
|
|
185
184
|
type: 'justSuccess',
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
export class DirtinessTracker {
|
|
2
2
|
private changesCount = 0
|
|
3
|
-
private
|
|
3
|
+
private touchedCount = 0
|
|
4
4
|
|
|
5
|
-
public
|
|
6
|
-
return this.
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public getTotalChangesCount() {
|
|
10
|
-
return this.totalChangesCount
|
|
5
|
+
public getTotalTouchCount() {
|
|
6
|
+
return this.touchedCount
|
|
11
7
|
}
|
|
12
8
|
|
|
13
9
|
public hasChanges() {
|
|
@@ -18,16 +14,8 @@ export class DirtinessTracker {
|
|
|
18
14
|
this.changesCount = 0
|
|
19
15
|
}
|
|
20
16
|
|
|
21
|
-
public increment() {
|
|
22
|
-
this.totalChangesCount++
|
|
23
|
-
this.changesCount++
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public decrement() {
|
|
27
|
-
this.changesCount--
|
|
28
|
-
}
|
|
29
|
-
|
|
30
17
|
public increaseBy(delta: number) {
|
|
31
18
|
this.changesCount += delta
|
|
19
|
+
this.touchedCount++
|
|
32
20
|
}
|
|
33
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ErrorAccessor } from '../accessors'
|
|
2
2
|
import type { ExecutionError, MutationDataResponse, MutationResponse, ValidationError } from '../accessorTree'
|
|
3
|
-
import type { PlaceholderName } from '../treeParameters'
|
|
3
|
+
import type { EntityId, FieldName, PlaceholderName } from '../treeParameters'
|
|
4
4
|
import { assertNever } from '../utils'
|
|
5
5
|
import { MutationAlias, mutationOperationSubTreeType } from './requestAliases'
|
|
6
6
|
|
|
@@ -227,7 +227,7 @@ namespace ErrorsPreprocessor {
|
|
|
227
227
|
|
|
228
228
|
export interface ErrorINode extends BaseErrorNode {
|
|
229
229
|
nodeType: 'iNode'
|
|
230
|
-
children: Map<
|
|
230
|
+
children: Map<FieldName | EntityId, ErrorNode>
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
export type ErrorNode = ErrorINode | LeafErrorNode
|
package/src/core/EventManager.ts
CHANGED
|
@@ -346,9 +346,12 @@ export class EventManager {
|
|
|
346
346
|
|
|
347
347
|
for (const [state, callback] of callbackQueue) {
|
|
348
348
|
correspondingStates.push(state)
|
|
349
|
+
const changesCountBefore = this.dirtinessTracker.getTotalTouchCount()
|
|
350
|
+
let validateChanges = false
|
|
349
351
|
try {
|
|
350
352
|
const result = callback(state.getAccessor as any, options as any) // TS can't quite handle this but this is sound.
|
|
351
353
|
if (result instanceof Promise) {
|
|
354
|
+
validateChanges = true
|
|
352
355
|
promiseReturns.push(result)
|
|
353
356
|
} else {
|
|
354
357
|
promiseReturns.push(Promise.resolve(result))
|
|
@@ -356,10 +359,15 @@ export class EventManager {
|
|
|
356
359
|
} catch (e) {
|
|
357
360
|
promiseReturns.push(Promise.reject(e))
|
|
358
361
|
}
|
|
362
|
+
if (validateChanges) {
|
|
363
|
+
this.validateWithoutChanges(changesCountBefore, eventType)
|
|
364
|
+
}
|
|
359
365
|
}
|
|
360
366
|
// TODO timeout
|
|
361
367
|
|
|
362
|
-
const
|
|
368
|
+
const changesCountBefore = this.dirtinessTracker.getTotalTouchCount()
|
|
369
|
+
const newCallbacks = await Promise.allSettled(promiseReturns)
|
|
370
|
+
this.validateWithoutChanges(changesCountBefore, eventType)
|
|
363
371
|
|
|
364
372
|
callbackQueue.length = 0 // Empties the queue
|
|
365
373
|
|
|
@@ -561,20 +569,18 @@ export class EventManager {
|
|
|
561
569
|
}
|
|
562
570
|
}
|
|
563
571
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
const changesCountAfter = this.dirtinessTracker.getTotalChangesCount()
|
|
572
|
+
|
|
573
|
+
private validateWithoutChanges(initialCount: number, eventType: string): void {
|
|
574
|
+
const changesCountAfter = this.dirtinessTracker.getTotalTouchCount()
|
|
568
575
|
if (import.meta.env.DEV) {
|
|
569
|
-
if (
|
|
576
|
+
if (initialCount !== changesCountAfter) {
|
|
570
577
|
// This isn't bulletproof. They could e.g. undo a change and make another one which would
|
|
571
578
|
// slip through this detection. But for most cases, it should be good enough and not too expensive.
|
|
572
579
|
throw new BindingError(
|
|
573
580
|
`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. ` +
|
|
574
|
-
|
|
581
|
+
`To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,
|
|
575
582
|
)
|
|
576
583
|
}
|
|
577
584
|
}
|
|
578
|
-
return result
|
|
579
585
|
}
|
|
580
586
|
}
|