@@ -5,10 +5,10 @@ import type {
55} from '../../@types/persisters/persister-remote/index.d.ts' ;
66import type { Content , Store } from '../../@types/store/index.d.ts' ;
77import { jsonParse , jsonStringWithMap } from '../../common/json.ts' ;
8- import { isNull , startInterval , stopInterval } from '../../common/other.ts' ;
8+ import { startInterval , stopInterval } from '../../common/other.ts' ;
99import { createCustomPersister } from '../common/create.ts' ;
1010
11- const getETag = ( response : Response ) => response . headers . get ( 'ETag' ) ;
11+ const getETag = ( response : Response ) => response . headers . get ( 'ETag' ) ?? '' ;
1212
1313export const createRemotePersister = ( (
1414 store : Store ,
@@ -17,11 +17,14 @@ export const createRemotePersister = ((
1717 autoLoadIntervalSeconds = 5 ,
1818 onIgnoredError ?: ( error : any ) => void ,
1919) : RemotePersister => {
20- let lastEtag : string | null ;
20+ let lastEtag : string = '' ;
2121
2222 const getPersisted = async ( ) : Promise < Content > => {
23- const response = await fetch ( loadUrl ) ;
23+ const response = await fetch ( loadUrl , {
24+ headers : { 'If-None-Match' : lastEtag } ,
25+ } ) ;
2426 lastEtag = getETag ( response ) ;
27+ console . log ( [ ...response . headers . entries ( ) ] , lastEtag ) ;
2528 return jsonParse ( await response . text ( ) ) ;
2629 } ;
2730
@@ -38,14 +41,10 @@ export const createRemotePersister = ((
3841 startInterval ( async ( ) => {
3942 const response = await fetch ( loadUrl , {
4043 method : 'HEAD' ,
41- headers : { 'If-None-Match' : lastEtag ?? '' } ,
44+ headers : { 'If-None-Match' : lastEtag } ,
4245 } ) ;
4346 const currentEtag = getETag ( response ) ;
44- if (
45- ! isNull ( lastEtag ) &&
46- ! isNull ( currentEtag ) &&
47- currentEtag != lastEtag
48- ) {
47+ if ( currentEtag != lastEtag ) {
4948 lastEtag = currentEtag ;
5049 listener ( ) ;
5150 }
0 commit comments