@contember/binding 1.1.0-alpha.14 → 1.1.0-alpha.16
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/accessorTree/useDataBinding.js +9 -6
- package/dist/development/accessorTree/useDataBinding.js.map +1 -1
- package/dist/development/core/Config.js +1 -2
- package/dist/development/core/Config.js.map +1 -1
- package/dist/development/core/DataBinding.js +114 -129
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/TreeAugmenter.js +5 -1
- package/dist/development/core/TreeAugmenter.js.map +1 -1
- package/dist/development/coreComponents/DataBindingProvider.js +2 -5
- package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
- package/dist/production/accessorTree/useDataBinding.js +9 -6
- package/dist/production/accessorTree/useDataBinding.js.map +1 -1
- package/dist/production/core/Config.js +1 -2
- package/dist/production/core/Config.js.map +1 -1
- package/dist/production/core/DataBinding.js +114 -129
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/TreeAugmenter.js +5 -1
- package/dist/production/core/TreeAugmenter.js.map +1 -1
- package/dist/production/coreComponents/DataBindingProvider.js +1 -4
- package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
- package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts +2 -1
- package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts.map +1 -1
- package/dist/types/accessorTree/PersistResult.d.ts +1 -4
- package/dist/types/accessorTree/PersistResult.d.ts.map +1 -1
- package/dist/types/accessorTree/useDataBinding.d.ts +1 -1
- package/dist/types/accessorTree/useDataBinding.d.ts.map +1 -1
- package/dist/types/accessors/BindingConfig.d.ts +0 -1
- package/dist/types/accessors/BindingConfig.d.ts.map +1 -1
- package/dist/types/accessors/PersistErrorOptions.d.ts +0 -2
- package/dist/types/accessors/PersistErrorOptions.d.ts.map +1 -1
- package/dist/types/core/Config.d.ts.map +1 -1
- package/dist/types/core/DataBinding.d.ts +9 -1
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/core/TreeAugmenter.d.ts +2 -1
- package/dist/types/core/TreeAugmenter.d.ts.map +1 -1
- package/dist/types/coreComponents/DataBindingProvider.d.ts +2 -5
- package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/accessorTree/AccessorTreeStateOptions.ts +2 -1
- package/src/accessorTree/PersistResult.ts +1 -5
- package/src/accessorTree/useDataBinding.ts +9 -6
- package/src/accessors/BindingConfig.ts +0 -1
- package/src/accessors/PersistErrorOptions.ts +0 -2
- package/src/core/Config.ts +0 -1
- package/src/core/DataBinding.ts +131 -140
- package/src/core/TreeAugmenter.ts +4 -1
- package/src/coreComponents/DataBindingProvider.tsx +4 -9
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.16",
|
|
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.16",
|
|
23
|
+
"@contember/react-client": "1.1.0-alpha.16",
|
|
24
|
+
"@contember/react-multipass-rendering": "1.1.0-alpha.16",
|
|
25
|
+
"@contember/react-utils": "1.1.0-alpha.16",
|
|
26
26
|
"chevrotain": "6.5.0",
|
|
27
27
|
"fast-deep-equal": "^3.1.3",
|
|
28
28
|
"js-levenshtein": "1.1.6",
|
|
@@ -22,10 +22,6 @@ export interface InvalidResponseResult {
|
|
|
22
22
|
errors: any // todo
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export interface GivenUpPersistResult {
|
|
26
|
-
type: 'givenUp'
|
|
27
|
-
}
|
|
28
|
-
|
|
29
25
|
export type SuccessfulPersistResult = NothingToPersistPersistResult | JustSuccessPersistResult
|
|
30
26
|
|
|
31
|
-
export type ErrorPersistResult = InvalidInputPersistResult |
|
|
27
|
+
export type ErrorPersistResult = InvalidInputPersistResult | RequestError | InvalidResponseResult
|
|
@@ -17,8 +17,9 @@ import { TreeStore } from '../core/TreeStore'
|
|
|
17
17
|
import { useIsMounted } from '@contember/react-utils'
|
|
18
18
|
|
|
19
19
|
export const useDataBinding = ({
|
|
20
|
-
|
|
21
|
-
refreshOnPersist
|
|
20
|
+
children,
|
|
21
|
+
refreshOnPersist,
|
|
22
|
+
skipStateUpdateAfterPersist,
|
|
22
23
|
}: AccessorTreeStateOptions): AccessorTreeState => {
|
|
23
24
|
const contentClient = useCurrentContentGraphQlClient()
|
|
24
25
|
const systemClient = useCurrentSystemGraphQlClient()
|
|
@@ -51,9 +52,11 @@ export const useDataBinding = ({
|
|
|
51
52
|
currentTreeStore.current = new TreeStore(environment.getSchema())
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
const binding = new DataBinding(contentClient, systemClient, tenantClient, currentTreeStore.current, environment, onUpdate, onError, onPersistSuccess
|
|
55
|
+
const binding = new DataBinding(contentClient, systemClient, tenantClient, currentTreeStore.current, environment, onUpdate, onError, onPersistSuccess, {
|
|
56
|
+
skipStateUpdateAfterPersist: skipStateUpdateAfterPersist ?? false,
|
|
57
|
+
})
|
|
55
58
|
dispatch({ type: 'reset', binding, environment })
|
|
56
|
-
}, [contentClient, systemClient, tenantClient, isMountedRef, refreshOnPersist])
|
|
59
|
+
}, [contentClient, systemClient, tenantClient, isMountedRef, refreshOnPersist, skipStateUpdateAfterPersist])
|
|
57
60
|
|
|
58
61
|
const [state, dispatch] = useReducer(accessorTreeStateReducer, {
|
|
59
62
|
name: 'initializing',
|
|
@@ -73,8 +76,8 @@ export const useDataBinding = ({
|
|
|
73
76
|
}, [resetDataBinding, schema, environment])
|
|
74
77
|
|
|
75
78
|
useEffect(() => {
|
|
76
|
-
state.binding?.extendTree(
|
|
77
|
-
}, [
|
|
79
|
+
state.binding?.extendTree(children)
|
|
80
|
+
}, [children, state.binding])
|
|
78
81
|
|
|
79
82
|
return state
|
|
80
83
|
}
|
|
@@ -7,6 +7,4 @@ export interface ScheduleAnotherPersistOptions {
|
|
|
7
7
|
export type ScheduleAnotherPersist = (options?: ScheduleAnotherPersistOptions) => void
|
|
8
8
|
|
|
9
9
|
export interface PersistErrorOptions extends AsyncBatchUpdatesOptions {
|
|
10
|
-
attemptNumber: number
|
|
11
|
-
tryAgain: ScheduleAnotherPersist
|
|
12
10
|
}
|
package/src/core/Config.ts
CHANGED
package/src/core/DataBinding.ts
CHANGED
|
@@ -5,12 +5,13 @@ import {
|
|
|
5
5
|
BatchUpdatesOptions,
|
|
6
6
|
BindingOperations,
|
|
7
7
|
ExtendTreeOptions,
|
|
8
|
-
PersistErrorOptions,
|
|
8
|
+
PersistErrorOptions, PersistOptions,
|
|
9
9
|
PersistSuccessOptions,
|
|
10
10
|
TreeRootAccessor,
|
|
11
11
|
} from '../accessors'
|
|
12
12
|
import {
|
|
13
|
-
|
|
13
|
+
ErrorPersistResult,
|
|
14
|
+
metadataToRequestError, MutationDataResponse,
|
|
14
15
|
MutationRequestResponse,
|
|
15
16
|
QueryRequestResponse,
|
|
16
17
|
RequestError,
|
|
@@ -27,7 +28,7 @@ import { EventManager } from './EventManager'
|
|
|
27
28
|
import { createBatchUpdatesOptions } from './factories'
|
|
28
29
|
import { MarkerMerger } from './MarkerMerger'
|
|
29
30
|
import { MarkerTreeGenerator } from './MarkerTreeGenerator'
|
|
30
|
-
import { MutationGenerator } from './MutationGenerator'
|
|
31
|
+
import { MutationGenerator, SubMutationOperation } from './MutationGenerator'
|
|
31
32
|
import { QueryGenerator } from './QueryGenerator'
|
|
32
33
|
import { StateIterator } from './state'
|
|
33
34
|
import { StateInitializer } from './StateInitializer'
|
|
@@ -63,6 +64,9 @@ export class DataBinding {
|
|
|
63
64
|
private readonly onUpdate: (newData: TreeRootAccessor, binding: DataBinding) => void,
|
|
64
65
|
private readonly onError: (error: RequestError, binding: DataBinding) => void,
|
|
65
66
|
private readonly onPersistSuccess: (result: SuccessfulPersistResult, binding: DataBinding) => void,
|
|
67
|
+
private readonly options: {
|
|
68
|
+
skipStateUpdateAfterPersist: boolean
|
|
69
|
+
},
|
|
66
70
|
) {
|
|
67
71
|
this.config = new Config()
|
|
68
72
|
this.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)
|
|
@@ -88,7 +92,7 @@ export class DataBinding {
|
|
|
88
92
|
this.eventManager,
|
|
89
93
|
this.treeStore,
|
|
90
94
|
)
|
|
91
|
-
this.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore)
|
|
95
|
+
this.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore, options.skipStateUpdateAfterPersist)
|
|
92
96
|
|
|
93
97
|
// TODO move this elsewhere
|
|
94
98
|
this.bindingOperations = Object.freeze<BindingOperations>({
|
|
@@ -101,153 +105,140 @@ export class DataBinding {
|
|
|
101
105
|
this.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))
|
|
102
106
|
},
|
|
103
107
|
extendTree: async (...args) => await this.extendTree(...args),
|
|
104
|
-
persist: async
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
// TODO if the tree is in an inconsistent state, wait for lock releases
|
|
108
|
-
|
|
109
|
-
this.eventManager.syncTransaction(() => {
|
|
110
|
-
this.accessorErrorManager.clearErrors()
|
|
111
|
-
})
|
|
112
|
-
await this.eventManager.triggerOnBeforePersist()
|
|
113
|
-
|
|
114
|
-
let shouldTryAgain = false
|
|
115
|
-
const proposedBackOffs: number[] = []
|
|
116
|
-
const persistErrorOptions: PersistErrorOptions = {
|
|
117
|
-
...this.bindingOperations,
|
|
118
|
-
tryAgain: options => {
|
|
119
|
-
shouldTryAgain = true
|
|
120
|
-
if (options?.proposedBackoff !== undefined && options.proposedBackoff > 0) {
|
|
121
|
-
proposedBackOffs.push(options.proposedBackoff)
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
attemptNumber,
|
|
125
|
-
}
|
|
108
|
+
persist: async options => await this.persist(options),
|
|
109
|
+
})
|
|
110
|
+
}
|
|
126
111
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
112
|
+
private async persist({ onPersistError, onPersistSuccess, signal }: PersistOptions = {}) {
|
|
113
|
+
return await this.eventManager.persistOperation(async () => {
|
|
114
|
+
// TODO if the tree is in an inconsistent state, wait for lock releases
|
|
130
115
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
116
|
+
this.eventManager.syncTransaction(() => {
|
|
117
|
+
this.accessorErrorManager.clearErrors()
|
|
118
|
+
})
|
|
119
|
+
await this.eventManager.triggerOnBeforePersist()
|
|
134
120
|
|
|
135
|
-
|
|
136
|
-
errors: this.accessorErrorManager.getErrors(),
|
|
137
|
-
type: 'invalidInput',
|
|
138
|
-
}
|
|
139
|
-
}
|
|
121
|
+
await this.checkErrorsBeforePersist(onPersistError)
|
|
140
122
|
|
|
141
|
-
|
|
142
|
-
|
|
123
|
+
const generator = new MutationGenerator(this.treeStore)
|
|
124
|
+
const mutationResult = generator.getPersistMutation()
|
|
143
125
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
await this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)
|
|
151
|
-
await onPersistSuccess?.(persistSuccessOptions)
|
|
126
|
+
if (mutationResult === undefined) {
|
|
127
|
+
await this.processEmptyPersistMutation(onPersistSuccess)
|
|
128
|
+
return {
|
|
129
|
+
type: 'nothingToPersist',
|
|
130
|
+
}
|
|
131
|
+
}
|
|
152
132
|
|
|
153
|
-
|
|
154
|
-
type: 'nothingToPersist',
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
const { query, operations } = mutationResult
|
|
133
|
+
const { query, operations } = mutationResult
|
|
158
134
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (mutationResponse.errors !== undefined && mutationResponse.errors.length > 0) {
|
|
164
|
-
this.onError({
|
|
165
|
-
type: 'gqlError',
|
|
166
|
-
query,
|
|
167
|
-
errors: mutationResponse.errors,
|
|
168
|
-
}, this)
|
|
169
|
-
}
|
|
170
|
-
if (!mutationResponse.data?.transaction) {
|
|
171
|
-
throw {
|
|
172
|
-
errors: [],
|
|
173
|
-
type: 'invalidResponse',
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const { __typename, ok, errorMessage, ...mutationData } = mutationResponse.data.transaction
|
|
177
|
-
const aliases = Object.keys(mutationData)
|
|
178
|
-
if (aliases.every(item => mutationData[item].ok)) {
|
|
179
|
-
const persistedEntityIds = aliases.map(alias => mutationData[alias].node?.id).filter(id => id !== undefined)
|
|
180
|
-
const result: SuccessfulPersistResult = {
|
|
181
|
-
type: 'justSuccess',
|
|
182
|
-
persistedEntityIds,
|
|
183
|
-
}
|
|
135
|
+
const mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(query, {
|
|
136
|
+
signal,
|
|
137
|
+
})
|
|
184
138
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (errorMessage) {
|
|
219
|
-
console.error(errorMessage)
|
|
220
|
-
}
|
|
221
|
-
this.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData, operations))
|
|
222
|
-
await this.eventManager.triggerOnPersistError(persistErrorOptions)
|
|
223
|
-
await onPersistError?.(persistErrorOptions)
|
|
224
|
-
if (shouldTryAgain) {
|
|
225
|
-
if (proposedBackOffs.length) {
|
|
226
|
-
const geometricMean = Math.round(
|
|
227
|
-
Math.pow(
|
|
228
|
-
proposedBackOffs.reduce((a, b) => a * b, 1),
|
|
229
|
-
1 / proposedBackOffs.length,
|
|
230
|
-
),
|
|
231
|
-
)
|
|
232
|
-
await new Promise(resolve => setTimeout(resolve, geometricMean))
|
|
233
|
-
}
|
|
234
|
-
continue
|
|
235
|
-
}
|
|
236
|
-
throw {
|
|
237
|
-
errors: this.accessorErrorManager.getErrors(),
|
|
238
|
-
type: 'invalidInput',
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
// Max attempts exceeded
|
|
243
|
-
// TODO fire persist error
|
|
244
|
-
throw {
|
|
245
|
-
type: 'givenUp',
|
|
246
|
-
}
|
|
247
|
-
}),
|
|
139
|
+
if (mutationResponse.errors !== undefined && mutationResponse.errors.length > 0) {
|
|
140
|
+
this.onError({
|
|
141
|
+
type: 'gqlError',
|
|
142
|
+
query,
|
|
143
|
+
errors: mutationResponse.errors,
|
|
144
|
+
}, this)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!mutationResponse.data?.transaction) {
|
|
148
|
+
this.persistFail({
|
|
149
|
+
errors: [],
|
|
150
|
+
type: 'invalidResponse',
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const { __typename, ok, errorMessage, ...mutationData } = mutationResponse.data.transaction
|
|
155
|
+
if (Object.values(mutationData).every(it => it.ok)) {
|
|
156
|
+
return await this.processSuccessfulPersistResult(mutationData, operations, onPersistSuccess)
|
|
157
|
+
} else {
|
|
158
|
+
if (errorMessage) {
|
|
159
|
+
console.error(errorMessage)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
this.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData, operations))
|
|
163
|
+
|
|
164
|
+
await this.eventManager.triggerOnPersistError(this.bindingOperations)
|
|
165
|
+
await onPersistError?.(this.bindingOperations)
|
|
166
|
+
this.persistFail({
|
|
167
|
+
errors: this.accessorErrorManager.getErrors(),
|
|
168
|
+
type: 'invalidInput',
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
}
|
|
248
172
|
})
|
|
249
173
|
}
|
|
250
174
|
|
|
175
|
+
private async checkErrorsBeforePersist(onPersistError: PersistOptions['onPersistError']) {
|
|
176
|
+
if (this.accessorErrorManager.hasErrors()) {
|
|
177
|
+
await this.eventManager.triggerOnPersistError(this.bindingOperations)
|
|
178
|
+
await onPersistError?.(this.bindingOperations)
|
|
179
|
+
this.persistFail({
|
|
180
|
+
errors: this.accessorErrorManager.getErrors(),
|
|
181
|
+
type: 'invalidInput',
|
|
182
|
+
},
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private async processEmptyPersistMutation(onPersistSuccess: PersistOptions['onPersistSuccess']): Promise<void> {
|
|
188
|
+
this.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.
|
|
189
|
+
const persistSuccessOptions: PersistSuccessOptions = {
|
|
190
|
+
...this.bindingOperations,
|
|
191
|
+
successType: 'nothingToPersist',
|
|
192
|
+
}
|
|
193
|
+
await this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)
|
|
194
|
+
await onPersistSuccess?.(persistSuccessOptions)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private async processSuccessfulPersistResult(mutationData: MutationDataResponse, operations: SubMutationOperation[], onPersistSuccess: PersistOptions['onPersistSuccess']) {
|
|
198
|
+
const persistedEntityIds = Object.values(mutationData).map(it => it.node?.id).filter(id => id !== undefined)
|
|
199
|
+
const result: SuccessfulPersistResult = {
|
|
200
|
+
type: 'justSuccess',
|
|
201
|
+
persistedEntityIds,
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
await this.eventManager.asyncTransaction(async () => {
|
|
206
|
+
this.resetTreeAfterSuccessfulPersist()
|
|
207
|
+
this.treeAugmenter.updatePersistedData(
|
|
208
|
+
Object.fromEntries(
|
|
209
|
+
Object.entries(mutationData).map(([placeholderName, subTreeResponse]) => [
|
|
210
|
+
placeholderName,
|
|
211
|
+
subTreeResponse.node,
|
|
212
|
+
]),
|
|
213
|
+
),
|
|
214
|
+
operations,
|
|
215
|
+
)
|
|
216
|
+
const persistSuccessOptions: PersistSuccessOptions = {
|
|
217
|
+
...this.bindingOperations,
|
|
218
|
+
successType: result.type,
|
|
219
|
+
}
|
|
220
|
+
await this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)
|
|
221
|
+
await onPersistSuccess?.(persistSuccessOptions)
|
|
222
|
+
|
|
223
|
+
this.treeAugmenter.resetCreatingSubTrees()
|
|
224
|
+
})
|
|
225
|
+
} catch (e) {
|
|
226
|
+
console.error(e)
|
|
227
|
+
const resultWithError = {
|
|
228
|
+
...result,
|
|
229
|
+
afterPersistError: e,
|
|
230
|
+
}
|
|
231
|
+
this.onPersistSuccess(resultWithError, this)
|
|
232
|
+
return resultWithError
|
|
233
|
+
}
|
|
234
|
+
this.onPersistSuccess(result, this)
|
|
235
|
+
return result
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private persistFail(error: ErrorPersistResult): never {
|
|
239
|
+
throw error
|
|
240
|
+
}
|
|
241
|
+
|
|
251
242
|
private resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {
|
|
252
243
|
this.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this)
|
|
253
244
|
}
|
|
@@ -22,6 +22,7 @@ export class TreeAugmenter {
|
|
|
22
22
|
private readonly eventManager: EventManager,
|
|
23
23
|
private readonly stateInitializer: StateInitializer,
|
|
24
24
|
private readonly treeStore: TreeStore,
|
|
25
|
+
private readonly skipStateUpdateAfterPersist: boolean = false,
|
|
25
26
|
) {}
|
|
26
27
|
|
|
27
28
|
public extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {
|
|
@@ -43,7 +44,9 @@ export class TreeAugmenter {
|
|
|
43
44
|
|
|
44
45
|
public updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {
|
|
45
46
|
this.treeStore.mergeInMutationResponse(response, operations)
|
|
46
|
-
|
|
47
|
+
if (this.skipStateUpdateAfterPersist) {
|
|
48
|
+
return
|
|
49
|
+
}
|
|
47
50
|
this.eventManager.syncTransaction(() => {
|
|
48
51
|
for (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {
|
|
49
52
|
// for (const rootPlaceholder in response) {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ComponentType, createElement, memo, ReactElement, ReactNode } from 'react'
|
|
2
|
-
import { AccessorTree, AccessorTreeState, useDataBinding } from '../accessorTree'
|
|
2
|
+
import { AccessorTree, AccessorTreeState, AccessorTreeStateOptions, useDataBinding } from '../accessorTree'
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
refreshOnPersist?: boolean
|
|
7
|
-
}
|
|
4
|
+
export type DataBindingProviderBaseProps =
|
|
5
|
+
& AccessorTreeStateOptions
|
|
8
6
|
|
|
9
7
|
export interface DataBindingStateComponentProps {
|
|
10
8
|
accessorTreeState: AccessorTreeState
|
|
@@ -23,10 +21,7 @@ export type DataBindingProviderProps<StateProps> = DataBindingProviderBaseProps
|
|
|
23
21
|
export const DataBindingProvider = memo(function DataBindingProvider<StateProps extends DataBindingStateComponentProps>(
|
|
24
22
|
props: DataBindingProviderProps<StateProps>,
|
|
25
23
|
) {
|
|
26
|
-
const accessorTreeState = useDataBinding(
|
|
27
|
-
nodeTree: props.children,
|
|
28
|
-
refreshOnPersist: props.refreshOnPersist ?? false,
|
|
29
|
-
})
|
|
24
|
+
const accessorTreeState = useDataBinding(props)
|
|
30
25
|
|
|
31
26
|
const children =
|
|
32
27
|
'stateComponent' in props && props.stateComponent
|