Session
Nano framework has inbuilt session
module, it helps to store key-value information in app session that gets cleared when app closed/killed.
Storing and reading data from session:
All the methods like onPress
, onLongPress
, onStart
, onResume
, onPause
and onEnd
in framework has access to moduleParams parameter that has all the available modules, you can use session
module from it like below.
For example, below is the code to store and delete key-value data using setValue
, deleteValue
and deleteAllValues
method from session
module.
const buttonPress = {
component: NANO.BUTTON,
value: 'CLICK TO SAVE DATA TO SESSION',
onPress: ({ moduleParams }) => {
// set Value
moduleParams["session"].setValue("name", "value")
// delete Value
moduleParams["session"].deleteValue("name")
// delete All values
moduleParams["session"].deleteAllValues()
}
};
const screen = {
name: 'HomeScreen',
screen: {
h1: [buttonPress]
}
};
You can read data from session in any screen using getValue
and getAllValues
like below.
const text2 = {
component: NANO.TEXT,
value: "I AM IN ANOTHER SCREEN",
};
const screen = {
name: 'AnotherScreen',
screen: {
h1: [text],
},
onStart: ({moduleParams}) => {
// read single value
console.log(moduleParams["session"].getValue("name"))
// read all stored values
console.log(moduleParams["session"].getAllValues())
}
};