MVP Verson: 0.4.8 beta
Lang Icon
Toggle Icon
Eternity
The Tango Store library natively supports enabling persistence and can specify field persistence, which can be achieved without introducing or using other libraries.
KeyPoints
  • Storage exception handling: We don't have a specific sessionStorage's exception handling (e.g. storage write failure) does try/catch to avoid browser storage limitations or JSON Crashes caused by parsing errors enhance fault tolerance.
  • Field-level persistence support: persistentFields is a practical mechanism for persisting all fields globally or avoiding persistence for sensitive or unnecessary data.
  • Multiple storage support: localStorage and are available.sessionStorage flexible options to meet different state persistence needs.
Case
1.Code format
const myStore = createTangoStore(
  initialValue: {},
  options: { 
    storageKey: '',
    Eternity: Boolean,
    Storage: ''
  },  
  persistentFields: [] 
);
2.Demo
Copy Logo
const myStore = createTangoStore(
  { user: 'John Doe', theme: 'dark' },
  { storageKey: 'my-store', Eternity: true, Storage: 'session'},  
  ['theme'] 
);

Note: The initial value is user: 'John Doe', theme: 'dark', with persistence turned on Eternity: true, persist keyname storageKey: 'my-store'Storage: 'session', specifies persistence with sessionStorage, specifies theme Fields can be persisted.

createTangoStore parameters
PropTypeAccepted ValuesDescriptionDefault
initialValueObjectObjectThe first parameter, the Initial State object, is the initial value of the user-defined TangoStore{}
optionsObjectObjectThe second parameter, persistence, is an object that contains optional settings-
storageKeyStringtango-store-stateThe first of the second parameter is used to store the key name of the persisted data-
EternityBooleantrue|falseThe second property in the second parameter, whether persistence is enabledfalse
StorageStringlocal|sessionThe third property in the second parameter, select the storage methodlocal
persistentFieldsArray[]/undefinedThe third parameter, field-level persistence, is an array of field names that specifies which fields need to be persisted. If not specified, all fields are persisted by default-