Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tanstack/form-core

Package Overview
Dependencies
Maintainers
2
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tanstack/form-core - npm Package Compare versions

Comparing version 0.4.2 to 0.5.0

7

build/legacy/FieldApi.js

@@ -26,5 +26,8 @@ // src/FieldApi.ts

return () => {
const preserveValue = this.options.preserveValue;
unsubscribe();
delete info.instances[this.uid];
if (!Object.keys(info.instances).length) {
if (!preserveValue) {
delete info.instances[this.uid];
}
if (!Object.keys(info.instances).length && !preserveValue) {
delete this.form.fieldInfo[this.name];

@@ -31,0 +34,0 @@ }

@@ -151,2 +151,6 @@ // src/FormApi.ts

};
this.deleteField = (field) => {
delete this.state.values[field];
delete this.state.fieldMeta[field];
};
this.pushFieldValue = (field, value, opts) => {

@@ -153,0 +157,0 @@ return this.setFieldValue(

@@ -76,2 +76,3 @@ import { Store } from '@tanstack/store';

}) => void;
deleteField: <TField extends DeepKeys<TFormData>>(field: TField) => void;
pushFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, value: DeepValue<TFormData, TField> extends any[] ? DeepValue<TFormData, TField>[number] : never, opts?: {

@@ -100,2 +101,3 @@ touch?: boolean;

asyncAlways?: boolean;
preserveValue?: boolean;
validator?: ValidatorType;

@@ -102,0 +104,0 @@ onMount?: (formApi: FieldApi<TParentData, TName, ValidatorType, TData>) => void;

@@ -25,5 +25,8 @@ // src/FieldApi.ts

return () => {
const preserveValue = this.options.preserveValue;
unsubscribe();
delete info.instances[this.uid];
if (!Object.keys(info.instances).length) {
if (!preserveValue) {
delete info.instances[this.uid];
}
if (!Object.keys(info.instances).length && !preserveValue) {
delete this.form.fieldInfo[this.name];

@@ -30,0 +33,0 @@ }

@@ -146,2 +146,6 @@ // src/FormApi.ts

};
this.deleteField = (field) => {
delete this.state.values[field];
delete this.state.fieldMeta[field];
};
this.pushFieldValue = (field, value, opts) => {

@@ -148,0 +152,0 @@ return this.setFieldValue(

@@ -76,2 +76,3 @@ import { Store } from '@tanstack/store';

}) => void;
deleteField: <TField extends DeepKeys<TFormData>>(field: TField) => void;
pushFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, value: DeepValue<TFormData, TField> extends any[] ? DeepValue<TFormData, TField>[number] : never, opts?: {

@@ -100,2 +101,3 @@ touch?: boolean;

asyncAlways?: boolean;
preserveValue?: boolean;
validator?: ValidatorType;

@@ -102,0 +104,0 @@ onMount?: (formApi: FieldApi<TParentData, TName, ValidatorType, TData>) => void;

{
"name": "@tanstack/form-core",
"version": "0.4.2",
"version": "0.5.0",
"description": "Powerful, type-safe, framework agnostic forms.",

@@ -5,0 +5,0 @@ "author": "tannerlinsley",

@@ -72,2 +72,3 @@ import { type DeepKeys, type DeepValue, type Updater } from './utils'

asyncAlways?: boolean
preserveValue?: boolean
validator?: ValidatorType

@@ -243,7 +244,11 @@ onMount?: (

return () => {
const preserveValue = this.options.preserveValue
unsubscribe()
delete info.instances[this.uid]
if (!Object.keys(info.instances).length) {
delete this.form.fieldInfo[this.name as never]
if (!preserveValue) {
delete info.instances[this.uid]
}
if (!Object.keys(info.instances).length && !preserveValue) {
delete this.form.fieldInfo[this.name]
}
}

@@ -250,0 +255,0 @@ }

@@ -352,2 +352,7 @@ import { Store } from '@tanstack/store'

deleteField = <TField extends DeepKeys<TFormData>>(field: TField) => {
delete this.state.values[field as keyof TFormData]
delete this.state.fieldMeta[field]
}
pushFieldValue = <TField extends DeepKeys<TFormData>>(

@@ -354,0 +359,0 @@ field: TField,

@@ -566,2 +566,41 @@ import { expect } from 'vitest'

})
// test the unmounting of the fieldAPI
it('should preserve value on unmount', () => {
const form = new FormApi({
defaultValues: {
name: 'test',
},
})
const field = new FieldApi({
form,
name: 'name',
preserveValue: true,
})
const unmount = field.mount()
unmount()
expect(form.getFieldInfo(field.name).instances[field.uid]).toBeDefined()
expect(form.getFieldInfo(field.name)).toBeDefined()
})
it('should not preserve field value on ummount', () => {
const form = new FormApi({
defaultValues: {
name: 'test',
},
})
const field = new FieldApi({
form,
name: 'name',
})
const unmount = field.mount()
unmount()
const info = form.getFieldInfo(field.name)
expect(info.instances[field.uid]).toBeUndefined()
expect(Object.keys(info.instances).length).toBe(0)
})
})

@@ -272,2 +272,17 @@ import { expect } from 'vitest'

it('should delete field from the form', () => {
const form = new FormApi({
defaultValues: {
names: 'kittu',
age: 4,
},
})
form.deleteField('names')
expect(form.getFieldValue('age')).toStrictEqual(4)
expect(form.getFieldValue('names')).toStrictEqual(undefined)
expect(form.getFieldMeta('names')).toStrictEqual(undefined)
})
it("form's valid state should be work fine", () => {

@@ -274,0 +289,0 @@ const form = new FormApi({

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc