import AsyncStorage from "@react-native-community/async-storage" ; import { StorageValue } from "../../typings/StorageValue" ; param { string } key param { MxObject [ ] } value returns { Promise . < void > } export async function SetStorageItemObjectList ( key ? , value ? ) { if ( ! key ) { return Promise . reject ( new Error ( "Input parameter 'Key' is required" ) ) ; } if ( ! value ) { return Promise . reject ( new Error ( "Input parameter 'Value' is required" ) ) ; } const serializedObjects = value . map ( serializeMxObject ) ; return setItem ( key , JSON . stringify ( serializedObjects ) ) ; function setItem ( key , value ) { if ( navigator && navigator . product === "ReactNative" ) { return AsyncStorage . setItem ( key , value ) ; } if ( window ) { window . localStorage . setItem ( key , value ) ; return Promise . resolve ( ) ; } return Promise . reject ( new Error ( "No storage API available" ) ) ; } function serializeMxObject ( object ) { return object . getAttributes ( ) . reduce < StorageValue > ( ( accumulator , attributeName ) => { accumulator [ attributeName ] = object . get ( attributeName ) ; return accumulator ; } , { guid : object . getGuid ( ) } ) ; } }