This commit is contained in:
Eric Bailey
2024-09-05 13:04:15 -05:00
parent 9ad2d11fa2
commit ae3f2015f2
2 changed files with 33 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import {emitGeoUpdated} from '#/state/events'
let geo: any
export async function resolveGeo() {
const req = new Promise(y => {
setTimeout(() => {
try {
geo = {country_code: 'US'}
emitGeoUpdated({geo})
} catch (e) {
} finally {
y(0)
}
}, 1000)
})
if (!geo) {
await req
}
}
export function getGeo() {
return geo
}
+8
View File
@@ -45,3 +45,11 @@ export function listenPostCreated(fn: () => void): UnlistenFn {
emitter.on('post-created', fn)
return () => emitter.off('post-created', fn)
}
export function emitGeoUpdated({geo}: {geo: any}) {
emitter.emit('geo-updated', geo)
}
export function listenGeoUpdated(fn: ({geo}: {geo: any}) => void): UnlistenFn {
emitter.on('geo-updated', fn)
return () => emitter.off('geo-updated', fn)
}