-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1080 from cardstack/virtual-network
Virtual network with loader shimming
- Loading branch information
Showing
27 changed files
with
617 additions
and
497 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,25 @@ | ||
/* | ||
This module needs to exist so long as we have multiple loaders cooperating in | ||
the same environment. It ensures that any shared global state is really | ||
global. Ultimately we would like to get to the point where the loader itself | ||
is scoped so broadly that there's only one, and module-scoped state is safe to | ||
treat as global. | ||
*/ | ||
|
||
const bucket: Map<string, unknown> = (() => { | ||
let g = globalThis as unknown as { | ||
__card_api_shared_state: Map<string, unknown> | undefined; | ||
}; | ||
if (!g.__card_api_shared_state) { | ||
g.__card_api_shared_state = new Map(); | ||
} | ||
return g.__card_api_shared_state; | ||
})(); | ||
|
||
export function initSharedState<T>(key: string, fn: () => T): T { | ||
if (bucket.has(key)) { | ||
return bucket.get(key) as T; | ||
} | ||
bucket.set(key, fn()); | ||
return bucket.get(key) as T; | ||
} |
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
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
Oops, something went wrong.