-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
55 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
import {SignalInterface} from '@alwatr/signal'; | ||
import {eventListener, eventTrigger} from '@alwatr/signal'; | ||
|
||
const signal = new SignalInterface('easter-egg'); | ||
const buttonEventTrigger = eventTrigger.bind<{id: number}>('easter-egg'); | ||
|
||
signal.setProvider((param) => { | ||
const newValue = param * 10; | ||
console.info('2. signal provider called', {param, newValue}); | ||
return `You have ${newValue} egg`; | ||
eventListener.subscribe<{id: number}>('easter-egg', (detail) => { | ||
const newValue = detail.id * 10; | ||
console.info('2. signal provider called', {detail, newValue}); | ||
}); | ||
|
||
document.getElementById('requestButton')?.addEventListener('click', async () => { | ||
console.info('1. request with 1'); | ||
const value = await signal.request(1); | ||
const value = await buttonEventTrigger.dispatch({id: 1}); | ||
console.info('3. new signal value', {value}); | ||
}); | ||
|
||
document.getElementById('requestButton2')?.addEventListener('click', async () => { | ||
console.info('1. request with 1'); | ||
const value1 = await signal.request(1); | ||
const value1 = buttonEventTrigger.dispatch({id: 2}); | ||
console.info('3. 2x request with 2,3'); | ||
const value2p = signal.request(2); | ||
const value3p = signal.request(3); | ||
const value2p = buttonEventTrigger.dispatch({id: 2}); | ||
const value3p = buttonEventTrigger.dispatch({id: 3}); | ||
console.info('4. new signal value', {value1, value2: await value2p, value3: await value3p}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 14 additions & 16 deletions
30
uniquely/flight-finder-pwa/src/director/job-document-storage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,38 @@ | ||
import {type CacheStrategy, serviceRequest} from '@alwatr/fetch'; | ||
import {createLogger} from '@alwatr/logger'; | ||
import {SignalInterface} from '@alwatr/signal'; | ||
|
||
import {showToastSignal} from './toast.js'; | ||
import {commandTrigger, requestableContextConsumer, requestableContextProvider} from '@alwatr/signal'; | ||
|
||
import type {AlwatrDocumentStorage} from '@alwatr/type'; | ||
import type {Job} from '@alwatr/type/flight-finder.js'; | ||
|
||
export const logger = createLogger('[director/job-document-storage]'); | ||
export const jobDocumentStorageSignal = new SignalInterface('job-document-storage'); | ||
|
||
async function requestJobStorage(cacheStrategy: CacheStrategy): Promise<void> { | ||
async function requestJobStorage(cacheStrategy: CacheStrategy): Promise<AlwatrDocumentStorage<Job> | void> { | ||
logger.logMethod('jobListProvider'); | ||
|
||
try { | ||
jobDocumentStorageSignal.dispatch( | ||
<AlwatrDocumentStorage<Job>> await serviceRequest({ | ||
url: window.appConfig?.api ? window.appConfig.api + '/job' : '/job', | ||
token: window.appConfig?.token, | ||
cache: 'no-cache', | ||
cacheStrategy, | ||
}), | ||
); | ||
return (<AlwatrDocumentStorage<Job>> await serviceRequest({ | ||
url: window.appConfig?.api ? window.appConfig.api + '/job' : '/job', | ||
token: window.appConfig?.token, | ||
cache: 'no-cache', | ||
cacheStrategy, | ||
})); | ||
} | ||
catch (error) { | ||
if ((error as Error).message !== 'fetch_cache_not_found') { | ||
logger.error('jobListProvider', 'fetch_failed', error); | ||
showToastSignal.dispatch({ | ||
commandTrigger.request('toast', { | ||
message: 'عملیات با خطا رو به رو شد', | ||
}); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
jobDocumentStorageSignal.setProvider(() => requestJobStorage('network_first')); | ||
requestableContextProvider.setProvider<AlwatrDocumentStorage<Job>, null>('job-document-storage', () => { | ||
return requestJobStorage('network_first'); | ||
}); | ||
|
||
requestJobStorage('cache_only').then(() => requestJobStorage('network_first')); | ||
|
||
setInterval(() => jobDocumentStorageSignal.request(null), 60_000); | ||
setInterval(() => requestableContextConsumer.request<null>('job-document-storage', null), 60_000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters