mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
25 lines
518 B
JavaScript
25 lines
518 B
JavaScript
|
const contexts = new WeakMap();
|
||
|
|
||
|
const ID_PREFIX = 'v';
|
||
|
|
||
|
function getContext(rendererContextResult) {
|
||
|
if (contexts.has(rendererContextResult)) {
|
||
|
return contexts.get(rendererContextResult);
|
||
|
}
|
||
|
const ctx = {
|
||
|
currentIndex: 0,
|
||
|
get id() {
|
||
|
return ID_PREFIX + this.currentIndex.toString();
|
||
|
},
|
||
|
};
|
||
|
contexts.set(rendererContextResult, ctx);
|
||
|
return ctx;
|
||
|
}
|
||
|
|
||
|
export function incrementId(rendererContextResult) {
|
||
|
const ctx = getContext(rendererContextResult);
|
||
|
const id = ctx.id;
|
||
|
ctx.currentIndex++;
|
||
|
return id;
|
||
|
}
|