Under maintenanceMVP Verson: 0.9.7 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
Prop
Type
Accepted Values
Description
Default
initialValue
Object
Object
The first parameter, the Initial State object, is the initial value of the user-defined TangoStore
{}
options
Object
Object
The second parameter, persistence, is an object that contains optional settings
-
storageKey
String
tango-store-state
The first of the second parameter is used to store the key name of the persisted data
-
Eternity
Boolean
true|false
The second property in the second parameter, whether persistence is enabled
false
Storage
String
local|session
The third property in the second parameter, select the storage method
local
persistentFields
Array
[]/undefined
The 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
-