@@ -5,7 +5,10 @@ import { getUnloadEvent } from './session.js';
55
66const settings = settings_api ;
77
8- export function getDefaultStore ( ) {
8+ /**
9+ * @returns {import('./types').StorageType }
10+ */
11+ export function getDefaultStorageType ( ) {
912 if ( _converse . state . config . get ( 'trusted' ) ) {
1013 const is_non_persistent = settings . get ( 'persistent_store' ) === 'sessionStorage' ;
1114 return is_non_persistent ? 'session' : 'persistent' ;
@@ -14,23 +17,35 @@ export function getDefaultStore() {
1417 }
1518}
1619
17- function storeUsesIndexedDB ( store ) {
18- return store === 'persistent' && settings . get ( 'persistent_store' ) === 'IndexedDB' ;
20+ /**
21+ * @param {import('./types').StorageType } type
22+ */
23+ function storeUsesIndexedDB ( type ) {
24+ return type === 'persistent' && settings . get ( 'persistent_store' ) === 'IndexedDB' ;
1925}
2026
21- export function createStore ( id , store ) {
22- const name = store || getDefaultStore ( ) ;
27+ /**
28+ * @param {string } id
29+ * @param {import('./types').StorageType } type
30+ */
31+ export function createStore ( id , type ) {
32+ const name = type || getDefaultStorageType ( ) ;
2333 const s = _converse . storage [ name ] ;
2434 if ( typeof s === 'undefined' ) {
2535 throw new TypeError ( `createStore: Could not find store for ${ id } ` ) ;
2636 }
27- return new Storage ( id , s , storeUsesIndexedDB ( store ) ) ;
37+ return new Storage ( id , s , storeUsesIndexedDB ( type ) ) ;
2838}
2939
40+ /**
41+ * @param {import('@converse/skeletor').Model|import('@converse/skeletor').Collection } model
42+ * @param {string } id
43+ * @param {import('./types').StorageType } [type]
44+ */
3045export function initStorage ( model , id , type ) {
31- const store = type || getDefaultStore ( ) ;
32- model . browserStorage = createStore ( id , store ) ;
33- if ( storeUsesIndexedDB ( store ) ) {
46+ type = type || getDefaultStorageType ( ) ;
47+ model . browserStorage = createStore ( id , type ) ;
48+ if ( storeUsesIndexedDB ( type ) ) {
3449 const flush = ( ) => model . browserStorage . flush ( ) ;
3550 const unloadevent = getUnloadEvent ( ) ;
3651 window . addEventListener ( unloadevent , flush ) ;
0 commit comments