Skip to content

Commit

Permalink
$mol_storage: async persist
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Nov 12, 2023
1 parent 3de93a0 commit f41667f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
6 changes: 1 addition & 5 deletions state/local/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ namespace $ {
this.native().removeItem( key )
} else {
this.native().setItem( key , JSON.stringify( next ) )
try {
this.$.$mol_storage.persisted( true )
} catch( error ) {
$mol_fail_log( error )
}
this.$.$mol_storage.persisted( true )
}

return next
Expand Down
11 changes: 5 additions & 6 deletions storage/storage.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ namespace $ {

@ $mol_mem
static native() {
return $mol_wire_sync( this.$.$mol_dom_context.navigator.storage )
return this.$.$mol_dom_context.navigator.storage
}

@ $mol_mem
static persisted( next?: boolean ): boolean {
$mol_mem_persist()
const native = this.native()
const prev = $mol_mem_cached( ()=> this.persisted() ) ?? native.persisted()
if( next && !prev ) native.persist()
return next ?? prev
if( next ) native.persist()
return next ?? $mol_wire_sync( native ).persisted()
}

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

static dir() {
return this.native().getDirectory()
return $mol_wire_sync( this.native() ).getDirectory()
}

}
Expand Down

0 comments on commit f41667f

Please sign in to comment.