Skip to content

Commit

Permalink
$mol_storage: mock for unsecure & nodejs context
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Dec 4, 2023
1 parent f6f890e commit 43a879a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
23 changes: 0 additions & 23 deletions storage/storage.node.ts

This file was deleted.

11 changes: 8 additions & 3 deletions storage/storage.web.ts → storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ namespace $ {

@ $mol_mem
static native() {
return this.$.$mol_dom_context.navigator.storage
return this.$.$mol_dom_context.navigator.storage ?? { // exists only in secure context
persisted: async ()=> false,
persist: async ()=> false,
estimate: async ()=> ({}),
getDirectory: async ()=> null! as FileSystemHandle,
} as StorageManager
}

@ $mol_mem
Expand All @@ -16,7 +21,7 @@ namespace $ {
const native = this.native()
if( next && !$mol_mem_cached( ()=> this.persisted() ) ) {
native.persist().then( actual => {

setTimeout( ()=> this.persisted( actual, 'cache' ), 5000 )

if( actual ) this.$.$mol_log3_rise({ place: `$mol_storage`, message: `Persist: Yes` })
Expand All @@ -29,7 +34,7 @@ namespace $ {
}

static estimate() {
return $mol_wire_sync( this.native() ).estimate()
return $mol_wire_sync( this.native() ?? {} ).estimate()
}

static dir() {
Expand Down

0 comments on commit 43a879a

Please sign in to comment.