Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
effector-final-form
Advanced tools
☄️ Effector bindings for Final Form 🏁
Forms values and validation rules are part of the business logic. This means that you need to be able to work with them without being bound to the UI-framework.
The goal of this project is to combine Final Form and Effector to achieve the above.
yarn add effector-final-form
# or
npm add effector-final-form
# or
pnpm add effector-final-form
Just import from the root module:
import { createForm } from 'effector-final-form';
import { vi } from 'vitest';
import waitForExpect from 'wait-for-expect';
// import { createForm } from 'effector-final-form';
import { createForm } from '../../index';
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
describe('example', () => {
test('', async () => {
const { $formState, $fields, api } = createForm({
onSubmit: async (f) => {
await sleep(1000);
return f.firstName === 'Incorrect' ? { firstName: 'Submit Error' } : undefined;
},
validate: (f) => (f.firstName === '' ? { firstName: 'Can not be empty' } : undefined),
initialValues: { firstName: '' },
subscribeOn: ['values', 'errors', 'submitting', 'submitSucceeded', 'submitFailed', 'submitErrors'],
});
await api.registerField({
name: 'firstName',
subscribeOn: ['value', 'error', 'initial'],
});
api.changeFx({ name: 'firstName', value: '' });
await waitForExpect(() => {
expect($fields.getState().firstName.error).toBe('Can not be empty');
});
expect($fields.getState().firstName.initial).toBe('');
expect($fields.getState().firstName.value).toBe('');
expect($formState.getState().errors).toStrictEqual({ firstName: 'Can not be empty' });
expect($formState.getState().values).toStrictEqual({ firstName: '' });
expect($formState.getState().submitting).toBe(false);
expect($formState.getState().submitSucceeded).toBe(false);
expect($formState.getState().submitFailed).toBe(false);
expect($formState.getState().submitErrors).toBe(null);
{
await api.changeFx({ name: 'firstName', value: 'Incorrect' });
await waitForExpect(() => {
expect($fields.getState().firstName.error).toBe(undefined);
expect($fields.getState().firstName.value).toBe('Incorrect');
expect($formState.getState().errors).toStrictEqual({});
});
}
{
const submitPromise = api.submitFx();
expect($formState.getState().submitting).toBe(true);
vi.useFakeTimers();
vi.runOnlyPendingTimers();
await submitPromise;
vi.useRealTimers();
expect($formState.getState().submitting).toBe(false);
expect($formState.getState().submitSucceeded).toBe(false);
expect($formState.getState().submitFailed).toBe(true);
expect($formState.getState().submitErrors).toStrictEqual({ firstName: 'Submit Error' });
}
{
await api.changeFx({ name: 'firstName', value: 'John' });
expect($fields.getState().firstName.error).toBe(undefined);
expect($fields.getState().firstName.value).toBe('John');
expect($formState.getState().errors).toStrictEqual({});
const submitPromise = api.submitFx();
await waitForExpect(() => {
expect($formState.getState().submitting).toBe(true);
});
vi.useFakeTimers();
vi.runOnlyPendingTimers();
await submitPromise;
vi.useRealTimers();
await waitForExpect(() => {
expect($formState.getState().submitting).toBe(false);
});
expect($formState.getState().submitSucceeded).toBe(true);
expect($formState.getState().submitFailed).toBe(false);
expect($formState.getState().submitErrors).toBe(null);
}
});
});
0.2.0
Store
as initialValues
FAQs
☄️ Effector bindings for Final Form
The npm package effector-final-form receives a total of 2 weekly downloads. As such, effector-final-form popularity was classified as not popular.
We found that effector-final-form demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.