Skip to content

Commit bebd998

Browse files
committed
fix: release
RELEASE_ALL
1 parent 884235f commit bebd998

File tree

5 files changed

+207
-128
lines changed

5 files changed

+207
-128
lines changed

packages/form-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
"build:types": "tsc --build"
2828
},
2929
"dependencies": {
30-
"@tanstack/store": "0.0.1-beta.88"
30+
"@tanstack/store": "0.0.1-beta.89"
3131
}
3232
}

packages/form-core/src/FieldApi.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export class FieldApi<TData, TFormData> {
8181
name!: DeepKeys<TFormData>
8282
store!: Store<FieldState<TData>>
8383
state!: FieldState<TData>
84+
#prevState!: FieldState<TData>
8485
options: FieldOptions<TData, TFormData> = {} as any
8586

8687
constructor(opts: FieldApiOptions<TData, TFormData>) {
@@ -105,32 +106,33 @@ export class FieldApi<TData, TFormData> {
105106
},
106107
},
107108
{
108-
onUpdate: (next) => {
109-
next.meta.touchedError = next.meta.isTouched
110-
? next.meta.error
111-
: undefined
109+
onUpdate: () => {
110+
const state = this.store.state
112111

113-
const prev = this.state
114-
this.state = next
112+
state.meta.touchedError = state.meta.isTouched
113+
? state.meta.error
114+
: undefined
115115

116-
if (next.value !== prev.value) {
117-
this.validate('change', next.value)
116+
if (state.value !== this.#prevState.value) {
117+
this.validate('change', state.value)
118118
}
119119

120-
return this.state
120+
this.#prevState = state
121+
this.state = state
121122
},
122123
},
123124
)
124125

125126
this.state = this.store.state
127+
this.#prevState = this.state
126128
this.update(opts)
127129
}
128130

129131
mount = () => {
130132
const info = this.getInfo()
131133
info.instances[this.uid] = this
132134

133-
const unsubscribe = this.form.store.subscribe((next) => {
135+
const unsubscribe = this.form.store.subscribe(() => {
134136
this.store.batch(() => {
135137
const nextValue = this.getValue()
136138
const nextMeta = this.getMeta()

packages/form-core/src/FormApi.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@ export class FormApi<TFormData> {
116116
isFormValid: true,
117117
}),
118118
{
119-
onUpdate: (next) => {
119+
onUpdate: () => {
120+
let { state } = this.store
120121
// Computed state
121-
const fieldMetaValues = Object.values(next.fieldMeta) as (
122+
const fieldMetaValues = Object.values(state.fieldMeta) as (
122123
| FieldMeta
123124
| undefined
124125
)[]
@@ -131,15 +132,15 @@ export class FormApi<TFormData> {
131132

132133
const isTouched = fieldMetaValues.some((field) => field?.isTouched)
133134

134-
const isValidating = isFieldsValidating || next.isFormValidating
135-
const isFormValid = !next.formError
135+
const isValidating = isFieldsValidating || state.isFormValidating
136+
const isFormValid = !state.formError
136137
const isValid = isFieldsValid && isFormValid
137138
const canSubmit =
138-
(next.submissionAttempts === 0 && !isTouched) ||
139-
(!isValidating && !next.isSubmitting && isValid)
139+
(state.submissionAttempts === 0 && !isTouched) ||
140+
(!isValidating && !state.isSubmitting && isValid)
140141

141-
next = {
142-
...next,
142+
state = {
143+
...state,
143144
isFieldsValidating,
144145
isFieldsValid,
145146
isFormValid,
@@ -148,10 +149,8 @@ export class FormApi<TFormData> {
148149
isTouched,
149150
}
150151

151-
// Create a shortcut for the state
152-
// Write it back to the store
153-
this.store.state = next
154-
this.state = next
152+
this.store.state = state
153+
this.state = state
155154
},
156155
},
157156
)
@@ -176,10 +175,7 @@ export class FormApi<TFormData> {
176175
}
177176

178177
if (options.defaultValues !== this.options.defaultValues) {
179-
this.store.setState((prev) => ({
180-
...prev,
181-
values: options.defaultValues as TFormData,
182-
}))
178+
this.store.setState(() => getDefaultFormState(options.defaultValues!))
183179
}
184180
})
185181

packages/react-form/src/useForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {
5757
selector,
5858
) => {
5959
// eslint-disable-next-line react-hooks/rules-of-hooks
60-
return useStore(api.store, selector as any) as any
60+
return useStore(api.store, selector) as any
6161
}
6262
api.Subscribe = (
6363
// @ts-ignore
@@ -66,7 +66,7 @@ export function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {
6666
return functionalUpdate(
6767
props.children,
6868
// eslint-disable-next-line react-hooks/rules-of-hooks
69-
useStore(api.store, props.selector as any),
69+
useStore(api.store, props.selector),
7070
) as any
7171
}
7272

0 commit comments

Comments
 (0)