|
1 | | -import { Derived } from '@tanstack/store' |
| 1 | +import { createStore } from '@tanstack/store' |
2 | 2 | import { concatenatePaths, getBy, makePathArray } from './utils' |
| 3 | +import type { ReadonlyStore } from '@tanstack/store' |
3 | 4 | import type { Updater } from './utils' |
4 | 5 | import type { |
5 | 6 | FormApi, |
@@ -225,7 +226,7 @@ export class FieldGroupApi< |
225 | 226 | return newProps |
226 | 227 | } |
227 | 228 |
|
228 | | - store: Derived<FieldGroupState<TFieldGroupData>> |
| 229 | + store: ReadonlyStore<FieldGroupState<TFieldGroupData>> |
229 | 230 |
|
230 | 231 | get state() { |
231 | 232 | return this.store.state |
@@ -275,38 +276,35 @@ export class FieldGroupApi< |
275 | 276 | this.fieldsMap = opts.fields |
276 | 277 | } |
277 | 278 |
|
278 | | - this.store = new Derived({ |
279 | | - deps: [this.form.store], |
280 | | - fn: ({ currDepVals }) => { |
281 | | - const currFormStore = currDepVals[0] |
282 | | - let values: TFieldGroupData |
283 | | - if (typeof this.fieldsMap === 'string') { |
284 | | - // all values live at that name, so we can directly fetch it |
285 | | - values = getBy(currFormStore.values, this.fieldsMap) |
286 | | - } else { |
287 | | - // we need to fetch the values from all places where they were mapped from |
288 | | - values = {} as never |
289 | | - const fields: Record<keyof TFieldGroupData, string> = this |
290 | | - .fieldsMap as never |
291 | | - for (const key in fields) { |
292 | | - values[key] = getBy(currFormStore.values, fields[key]) |
293 | | - } |
| 279 | + this.store = createStore(() => { |
| 280 | + const currFormStore = this.form.store.get() |
| 281 | + let values: TFieldGroupData |
| 282 | + if (typeof this.fieldsMap === 'string') { |
| 283 | + // all values live at that name, so we can directly fetch it |
| 284 | + values = getBy(currFormStore.values, this.fieldsMap) |
| 285 | + } else { |
| 286 | + // we need to fetch the values from all places where they were mapped from |
| 287 | + values = {} as never |
| 288 | + const fields: Record<keyof TFieldGroupData, string> = this |
| 289 | + .fieldsMap as never |
| 290 | + for (const key in fields) { |
| 291 | + values[key] = getBy(currFormStore.values, fields[key]) |
294 | 292 | } |
| 293 | + } |
295 | 294 |
|
296 | | - return { |
297 | | - values, |
298 | | - } |
299 | | - }, |
| 295 | + return { |
| 296 | + values, |
| 297 | + } |
300 | 298 | }) |
301 | 299 | } |
302 | 300 |
|
303 | 301 | /** |
304 | 302 | * Mounts the field group instance to listen to value changes. |
| 303 | + * |
| 304 | + * TODO: Remove |
305 | 305 | */ |
306 | 306 | mount = () => { |
307 | | - const cleanup = this.store.mount() |
308 | | - |
309 | | - return cleanup |
| 307 | + return () => {} |
310 | 308 | } |
311 | 309 |
|
312 | 310 | /** |
|
0 commit comments