-
Notifications
You must be signed in to change notification settings - Fork 3
Using StorageHub
Natalia Djohari edited this page Mar 6, 2019
·
2 revisions
Note! Data saved into the storage module is not saved to disk. Any information you add to the storage after the app has started will be lost when you close the browser window.
-
Open
client/src/js/storage.js
, there is a hello world example in there already -
To add more data on startup, add any of the following in
client/src/js/storage.js
:StorageHub.setData('myData', 'hello') StorageHub.setData('myData', [1, 2, 3]) StorageHub.setData('myData', { property: [1, 2, 3] })
-
You can also load data from a json file:
const addressData = require('./data/address.json'); StorageHub.setData('address', addressData);
-
You can setData in any page or event.
-
Access the data in a page of your choice. There is an example in
homePage.js
andcontactsPage.js
already.const StorageHub = require('watch-framework').StorageHub; ... StorageHub.getData('myData')
-
To debug the StorageHub, you can do the following:
StorageHub.setDebug(true) StorageHub.setData('myData', 'is stored!') StorageHub.setDebug(false)
This will end up printing the following: