Giter Club home page Giter Club logo

final-form-storage's Introduction

final-form-storage

Build Status codebeat badge codecov

A set of helpers helping persist the state of form based on Final Form

Installation

Currently the only source for obtaining this library is to build it from source as it is available from no package registry yet.

$ npm install
$ npm test # check if everying is OK
$ npm run build

Helper functions

loadValues: (options: StorageOptions) => Mutator

A mutator loading raw form values from a storage:

const form = createForm({
  mutators: {
    loadValues: loadValues(options)
    /* other mutators */
  }
  /* rest of the config */
});

saveValues: (options: StorageOptions) => FormSubscriber

Subscriber that saves raw form values to a storage on each call.

form.subscribe(saveValues(options), { /* subscription */ });

Storages

Storages are objects implementing DataStorage interface that can be passed to the helpers through options. They are effectively drivers for persistence

BrowserStorage

A thin wrapper over browser's Storage API, using JSON.parse and JSON.stringify for (de-)serialization.

BrowserStorage.useWith: (storage: Storage) => BrowserStorage

A static factory method that creates BrowserStorage object with the underlying storage passed as an argument. It accepts window.localStorage, window.sessionStorage or anything with compatible API.

const storage = BrowserStorage.useWith(window.localStorage);
const storage = BrowserStorage.useWith(window.sessionStorage);

Interfaces

DataStorage

StorageOptions

Roadmap

There are persistence helpers (subscriber and mutator) planned for:

  • field value
  • form state
  • field state

In addition:

  • clearing stored data
  • define-form compatibility
  • support for React Native's AsyncStorage (as a separate package or through optional dependencies)

Known issues

any in arbitraryMutableState

There's an issue with nesting arbitraryInternalFormState within arbitraryMutableState. It's circumvented with explicit casting, though it's not completely typesafe. Low priority due to being present only in tests.

Compatibility with define-form

Not guaranteed work smoothly with define-form, which is an alternative, generics-based typings for final-form. final-form-storage does not support generic values object โ€“ it's type is any. On the roadmap.

Contributing

final-form-storage's People

Contributors

phoulgaux avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.