-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ts): better dependency injection
- Loading branch information
1 parent
1e4b04b
commit 20f94a7
Showing
5 changed files
with
61 additions
and
34 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { Map } from 'mapbox-gl'; | ||
import type { InjectionKey, Ref } from 'vue'; | ||
|
||
const MapKey: InjectionKey<Ref<Map>> = Symbol('Map'); | ||
const MapLoadedKey: InjectionKey<Ref<boolean>> = Symbol('MapLoaded'); | ||
const MapStylesLoadedKey: InjectionKey<Ref<boolean>> = Symbol('MapStyleLoaded'); | ||
const MapTilesLoadedKey: InjectionKey<Ref<boolean>> = Symbol('MapTilesLoaded'); | ||
|
||
export { MapKey, MapLoadedKey, MapStylesLoadedKey, MapTilesLoadedKey }; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { InjectionKey } from 'vue'; | ||
import { inject } from 'vue'; | ||
|
||
export function injectStrict<T>(key: InjectionKey<T>, fallback?: T) { | ||
const resolved = inject(key, fallback); | ||
if (!resolved) { | ||
throw new Error(`Could not resolve ${key.description}`); | ||
} | ||
return resolved; | ||
} |