effector-final-form
Advanced tools
Comparing version 0.9.0-next.0 to 0.9.0
import type { Store } from 'effector'; | ||
import type { FormApi as FFFormApi, FieldState as FFFieldState } from 'final-form'; | ||
import type { FormApi as FFFormApi, FieldState as FFFieldState, FieldSubscription as FFFieldSubscription } from 'final-form'; | ||
import type { createFormState } from './createFormState'; | ||
@@ -29,7 +29,7 @@ import type { FormSubscription, ValidationResult } from './types'; | ||
pauseValidation: import("effector").Effect<void, void, Error>; | ||
registerField: <P, T_1 extends readonly (keyof import("final-form").FieldSubscription)[] = readonly (keyof import("final-form").FieldSubscription)[]>({ name, subscribeOn, config, initialValue, validate, }: { | ||
registerField: <P extends keyof FormValues, T_1 extends readonly (keyof FFFieldSubscription)[] = readonly (keyof FFFieldSubscription)[]>({ name, subscribeOn, config, initialValue, validate, }: { | ||
name: keyof FormValues; | ||
subscribeOn: T_1; | ||
initialValue?: P | Store<P> | undefined; | ||
validate?: ((value?: P | undefined) => ValidationResult) | undefined; | ||
initialValue?: FormValues[P] | Store<FormValues[P]> | undefined; | ||
validate?: ((value?: FormValues[P] | undefined) => ValidationResult) | undefined; | ||
config?: Omit<import("final-form").FieldConfig<FormValues[keyof FormValues]>, "initialValue" | "getValidator"> | undefined; | ||
@@ -42,5 +42,26 @@ }) => { | ||
resetState: import("effector").Effect<void, void, Error>; | ||
setValidationFn: (fn: Required<((value?: P | undefined) => ValidationResult) | undefined>) => void; | ||
setValidationFn: (fn: Required<((value?: FormValues[P] | undefined) => ValidationResult) | undefined>) => void; | ||
}; | ||
$state: Store<Pick<FFFieldState<P>, "value" | T_1[number]>>; | ||
$: Store<Pick<Omit<FFFieldState<FormValues[P]>, "active" | "dirty" | "modifiedSinceLastSubmit" | "error" | "invalid" | "modified" | "pristine" | "submitError" | "submitFailed" | "submitting" | "submitSucceeded" | "touched" | "valid" | "validating" | "visited" | "initial" | "length" | "value"> & { | ||
active: boolean | null; | ||
dirty: boolean | null; | ||
modifiedSinceLastSubmit: boolean | null; | ||
error: any; | ||
invalid: boolean | null; | ||
modified: boolean | null; | ||
pristine: boolean | null; | ||
submitError: any; | ||
submitFailed: boolean | null; | ||
submitting: boolean | null; | ||
submitSucceeded: boolean | null; | ||
touched: boolean | null; | ||
valid: boolean | null; | ||
validating: boolean | null; | ||
visited: boolean | null; | ||
initial: Exclude<FormValues[P], undefined> | null; | ||
length: number | null; | ||
value: Exclude<FormValues[P], undefined> | null; | ||
}, T_1[number]> & { | ||
name: keyof FormValues; | ||
}>; | ||
}; | ||
@@ -47,0 +68,0 @@ reset: import("effector").Effect<void | Partial<FormValues> | undefined, void, Error>; |
@@ -7,3 +7,3 @@ import type { FormApi as FFFormApi, FormState as FFFormState } from 'final-form'; | ||
}) => { | ||
$state: import("effector").Store<Pick<Omit<FFFormState<FormValues, Partial<FormValues>>, "active" | "errors" | "modified" | "submitErrors" | "touched" | "visited"> & { | ||
$: import("effector").Store<Pick<Omit<FFFormState<FormValues, Partial<FormValues>>, "active" | "errors" | "modified" | "submitErrors" | "touched" | "visited"> & { | ||
active: Exclude<keyof FormValues, undefined> | null; | ||
@@ -10,0 +10,0 @@ errors: import("final-form").AnyObject | null; |
@@ -13,7 +13,7 @@ import type { Config as FFConfig } from 'final-form'; | ||
pauseValidation: import("effector").Effect<void, void, Error>; | ||
registerField: <P, T_1 extends readonly (keyof import("final-form").FieldSubscription)[] = readonly (keyof import("final-form").FieldSubscription)[]>({ name, subscribeOn, config, initialValue, validate, }: { | ||
registerField: <P extends keyof FormValues, T_1 extends readonly (keyof import("final-form").FieldSubscription)[] = readonly (keyof import("final-form").FieldSubscription)[]>({ name, subscribeOn, config, initialValue, validate, }: { | ||
name: keyof FormValues; | ||
subscribeOn: T_1; | ||
initialValue?: P | import("effector").Store<P> | undefined; | ||
validate?: ((value?: P | undefined) => any) | undefined; | ||
initialValue?: FormValues[P] | import("effector").Store<FormValues[P]> | undefined; | ||
validate?: ((value?: FormValues[P] | undefined) => any) | undefined; | ||
config?: Omit<import("final-form").FieldConfig<FormValues[keyof FormValues]>, "initialValue" | "getValidator"> | undefined; | ||
@@ -26,5 +26,26 @@ }) => { | ||
resetState: import("effector").Effect<void, void, Error>; | ||
setValidationFn: (fn: Required<((value?: P | undefined) => any) | undefined>) => void; | ||
setValidationFn: (fn: Required<((value?: FormValues[P] | undefined) => any) | undefined>) => void; | ||
}; | ||
$state: import("effector").Store<Pick<import("final-form").FieldState<P>, "value" | T_1[number]>>; | ||
$: import("effector").Store<Pick<Omit<import("final-form").FieldState<FormValues[P]>, "active" | "dirty" | "modifiedSinceLastSubmit" | "error" | "invalid" | "modified" | "pristine" | "submitError" | "submitFailed" | "submitting" | "submitSucceeded" | "touched" | "valid" | "validating" | "visited" | "initial" | "length" | "value"> & { | ||
active: boolean | null; | ||
dirty: boolean | null; | ||
modifiedSinceLastSubmit: boolean | null; | ||
error: any; | ||
invalid: boolean | null; | ||
modified: boolean | null; | ||
pristine: boolean | null; | ||
submitError: any; | ||
submitFailed: boolean | null; | ||
submitting: boolean | null; | ||
submitSucceeded: boolean | null; | ||
touched: boolean | null; | ||
valid: boolean | null; | ||
validating: boolean | null; | ||
visited: boolean | null; | ||
initial: Exclude<FormValues[P], undefined> | null; | ||
length: number | null; | ||
value: Exclude<FormValues[P], undefined> | null; | ||
}, T_1[number]> & { | ||
name: keyof FormValues; | ||
}>; | ||
}; | ||
@@ -36,3 +57,3 @@ reset: import("effector").Effect<void | Partial<FormValues> | undefined, void, Error>; | ||
}; | ||
$state: import("effector").Store<Pick<Omit<import("final-form").FormState<FormValues, Partial<FormValues>>, "active" | "errors" | "modified" | "submitErrors" | "touched" | "visited"> & { | ||
$: import("effector").Store<Pick<Omit<import("final-form").FormState<FormValues, Partial<FormValues>>, "active" | "errors" | "modified" | "submitErrors" | "touched" | "visited"> & { | ||
active: Exclude<keyof FormValues, undefined> | null; | ||
@@ -39,0 +60,0 @@ errors: import("final-form").AnyObject | null; |
@@ -1,4 +0,4 @@ | ||
import { createEffect as c, is as R, createEvent as m, createStore as x, sample as $ } from "effector"; | ||
import { fieldSubscriptionItems as z, formSubscriptionItems as D, createForm as T } from "final-form"; | ||
function _(t) { | ||
import { createEffect as c, is as D, createEvent as b, createStore as A, sample as T } from "effector"; | ||
import { fieldSubscriptionItems as U, formSubscriptionItems as q, createForm as w } from "final-form"; | ||
function O(t) { | ||
if (t === null) | ||
@@ -13,8 +13,8 @@ return "Null"; | ||
} | ||
const v = (t) => { | ||
const N = (t) => { | ||
const e = t.__proto__.toString(); | ||
return ["Error", "TypeError"].includes(e) ? [e, t.message] : []; | ||
}, N = (t) => t.toDateString ? [!0, t.getTime()] : [!1], O = (t) => t.constructor !== RegExp ? [!1] : [!0, t.toString()], S = (t, e) => { | ||
const r = _(t); | ||
if (r !== _(e)) | ||
}, h = (t) => t.toDateString ? [!0, t.getTime()] : [!1], x = (t) => t.constructor !== RegExp ? [!1] : [!0, t.toString()], F = (t, e) => { | ||
const r = O(t); | ||
if (r !== O(e)) | ||
return !1; | ||
@@ -31,5 +31,5 @@ if (r === "Function") | ||
const n = Array.from(t), i = Array.from(e); | ||
return n.toString() !== i.toString() ? !1 : n.every((d, f) => d === i[f] || S(d, i[f])); | ||
return n.toString() !== i.toString() ? !1 : n.every((d, f) => d === i[f] || F(d, i[f])); | ||
} | ||
const s = O(t), o = O(e); | ||
const s = x(t), o = x(e); | ||
if (s[0]) | ||
@@ -39,3 +39,3 @@ return o[0] ? s[1] === o[1] : !1; | ||
return !1; | ||
const l = N(t), a = N(e); | ||
const l = h(t), a = h(e); | ||
if (l[0]) | ||
@@ -45,3 +45,3 @@ return a[0] ? l[1] === a[1] : !1; | ||
return !1; | ||
const u = v(t), p = v(e); | ||
const u = N(t), p = N(e); | ||
if (u[0]) | ||
@@ -53,17 +53,17 @@ return p[0] ? u[0] === p[0] && u[1] === p[1] : !1; | ||
const d = t[i], f = e[i]; | ||
return d === f || S(d, f); | ||
return d === f || F(d, f); | ||
}); | ||
} | ||
return !1; | ||
}, A = (t) => t == null, h = (t, e) => ( | ||
}, j = (t) => t == null, S = (t, e) => ( | ||
// @ts-expect-error | ||
e.reduce((r, s) => A(t[s]) ? { ...r, [s]: null } : r, t) | ||
), j = (t, e) => ( | ||
e.reduce((r, s) => j(t[s]) ? { ...r, [s]: null } : r, t) | ||
), E = (t, e) => ( | ||
// @ts-expect-error | ||
A(e) ? {} : t.reduce( | ||
j(e) ? {} : t.reduce( | ||
(r, s) => Object.prototype.hasOwnProperty.call(e, s) ? { ...r, [s]: e[s] } : r, | ||
{} | ||
) | ||
), E = (t, e) => t.reduce((r, s) => ({ ...r, [s]: e.includes(s) }), {}), q = (t, e) => !S(t, e), w = (t) => { | ||
}, U = (t) => { | ||
), P = (t, e) => t.reduce((r, s) => ({ ...r, [s]: e.includes(s) }), {}), z = (t, e) => !F(t, e), B = (t) => { | ||
}, I = (t) => { | ||
const { finalForm: e, formStateApi: r, revalidateFx: s } = t, o = (n) => (i) => e.change(n, i), l = ({ | ||
@@ -74,24 +74,27 @@ name: n, | ||
initialValue: f, | ||
validate: P | ||
validate: $ | ||
}) => { | ||
const F = c(P ?? w), k = { | ||
const V = c($ ?? B), m = [...i, "name", "value"], k = { | ||
...d, | ||
initialValue: R.store(f) ? f.getState() : f, | ||
getValidator: (g) => F | ||
}, b = m(); | ||
initialValue: D.store(f) ? f.getState() : f, | ||
getValidator: (g) => V | ||
}, y = b(); | ||
e.batch(() => { | ||
e.registerField( | ||
// @ts-expect-error | ||
n, | ||
b, | ||
E(z, [...i, "name", "value"]), | ||
// @ts-expect-error | ||
y, | ||
P(U, m), | ||
k | ||
), s(); | ||
}); | ||
const C = j([...i, "value"], e.getFieldState(n)), V = x({ ...C, name: n }); | ||
$({ | ||
clock: b.filterMap(({ blur: g, change: M, focus: G, ...y }) => y.name === n ? y : void 0), | ||
target: V | ||
const C = S(E(m, e.getFieldState(n)), m), _ = A({ ...C, name: n }), H = y.filterMap( | ||
({ blur: g, change: J, focus: K, ...v }) => v.name === n ? v : void 0 | ||
); | ||
T({ | ||
clock: H, | ||
fn: (g) => ({ ...S(g, m), name: n }), | ||
target: _ | ||
}); | ||
const H = o(n); | ||
const R = o(n); | ||
return { api: { | ||
@@ -101,3 +104,3 @@ blurFx: c(() => { | ||
}), | ||
changeFx: c(H), | ||
changeFx: c(R), | ||
focusFx: c(() => { | ||
@@ -110,5 +113,5 @@ e.focus(n); | ||
setValidationFn: (g) => { | ||
F.use(g), s(); | ||
V.use(g), s(); | ||
} | ||
}, $state: V }; | ||
}, $: _ }; | ||
}, a = () => { | ||
@@ -133,17 +136,17 @@ e.pauseValidation(), r.setValidationPaused(!0); | ||
}; | ||
}, B = (t) => { | ||
const { finalForm: e, subscribeOn: r } = t, s = j([...r, "isValidationPaused"], { | ||
}, M = (t) => { | ||
const { finalForm: e, subscribeOn: r } = t, s = E([...r, "isValidationPaused"], { | ||
...e.getState(), | ||
isValidationPaused: !1 | ||
}), o = { | ||
update: m(), | ||
setValidationPaused: m() | ||
}, l = x(h(s, r), { | ||
updateFilter: q | ||
update: b(), | ||
setValidationPaused: b() | ||
}, l = A(S(s, r), { | ||
updateFilter: z | ||
}).on(o.update, (a, u) => Object.assign({}, a, u)).on(o.setValidationPaused, (a, u) => Object.assign({}, a, { isValidationPaused: u })); | ||
return e.subscribe((a) => { | ||
o.update(h(a, r)); | ||
}, E(D, r)), { $state: l, formStateApi: o }; | ||
}, L = (t) => { | ||
const { subscribeOn: e, ...r } = t, s = c(r.onSubmit), o = T({ | ||
o.update(S(a, r)); | ||
}, P(q, r)), { $: l, formStateApi: o }; | ||
}, W = (t) => { | ||
const { subscribeOn: e, ...r } = t, s = c(r.onSubmit), o = w({ | ||
...r, | ||
@@ -163,3 +166,3 @@ onSubmit: async (n) => { | ||
o.mutators.__update__(); | ||
}), { $state: a, formStateApi: u } = B({ | ||
}), { $: a, formStateApi: u } = M({ | ||
finalForm: o, | ||
@@ -170,11 +173,11 @@ subscribeOn: e | ||
api: { | ||
...U({ finalForm: o, formStateApi: u, revalidateFx: l }), | ||
...I({ finalForm: o, formStateApi: u, revalidateFx: l }), | ||
revalidateFx: l, | ||
setSubmitFn: s.use | ||
}, | ||
$state: a | ||
$: a | ||
}; | ||
}; | ||
export { | ||
L as createForm | ||
W as createForm | ||
}; |
import { Pick } from '../types'; | ||
import { isNil } from './isNil'; | ||
import { normalizedState } from './normalizedState'; | ||
import { normalizeState } from './normalizeState'; | ||
declare const pick: <K extends string, T extends Record<string, any>>(propsToPick: K[], input: T) => Pick<T, K>; | ||
declare const normalizeSubscriptions: <T extends readonly string[]>(a: T, b: T) => {}; | ||
declare const notEquals: (a: any, b: any) => boolean; | ||
export { pick, isNil, normalizeSubscriptions, notEquals, normalizedState }; | ||
export { pick, isNil, normalizeSubscriptions, notEquals, normalizeState }; |
{ | ||
"name": "effector-final-form", | ||
"version": "0.9.0-next.0", | ||
"version": "0.9.0", | ||
"description": "☄️ Effector bindings for Final Form", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -39,3 +39,3 @@ # effector-final-form | ||
const loginField = form.api.registerField<string>({ | ||
const loginField = form.api.registerField({ | ||
name: 'login', | ||
@@ -46,7 +46,7 @@ subscribeOn: ['value', 'error', 'validating'], | ||
loginField.$state.watch(console.log); | ||
// {name: "login", value: undefined, error: undefined, validating: true} | ||
// {name: "login", error: "Incorrect login", value: undefined, validating: false} | ||
loginField.$.watch(console.log); | ||
// {name: "login", value: null, error: null, validating: true} | ||
// {name: "login", error: "Incorrect login", value: null, validating: false} | ||
const passwordField = form.api.registerField<string>({ | ||
const passwordField = form.api.registerField({ | ||
name: 'password', | ||
@@ -57,12 +57,12 @@ subscribeOn: ['value', 'error', 'validating'], | ||
passwordField.$state.watch(console.log); | ||
// {name: "password", value: undefined, error: undefined, validating: true} | ||
// {name: "password", error: "Incorrect password", value: undefined, validating: false} | ||
passwordField.$.watch(console.log); | ||
// {name: "password", value: null, error: null, validating: true} | ||
// {name: "password", error: "Incorrect password", value: null, validating: false} | ||
loginField.api.changeFx('John'); | ||
// {name: "login", error: undefined, value: "John", validating: true} | ||
// {name: "login", error: undefined, value: "John", validating: false} | ||
// {name: "login", error: null, value: "John", validating: true} | ||
// {name: "login", error: null, value: "John", validating: false} | ||
passwordField.api.changeFx('secret'); | ||
// {name: "password", error: undefined, value: "secret", validating: true} | ||
// {name: "password", error: undefined, value: "secret", validating: false} | ||
// {name: "password", error: null, value: "secret", validating: true} | ||
// {name: "password", error: null, value: "secret", validating: false} | ||
form.api.submitFx(); | ||
@@ -69,0 +69,0 @@ // {login: "John", password: "secret"} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24048
403