limu
Version:
A fast js lib of immutable data, based on shallow copy on read and mark modified on write mechanism
40 lines (39 loc) • 1.22 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Licensed under the MIT License.
*
* @Author: fantasticsoul
*--------------------------------------------------------------------------------------------*/
function getId(idWrap, customPrefix = '') {
if (idWrap.value >= Number.MAX_SAFE_INTEGER) {
idWrap.value = 1;
idWrap.prefixSeed += 1;
}
else {
idWrap.value += 1;
}
const { value, prefixSeed } = idWrap;
const metaVer = `${customPrefix}${prefixSeed}_${value}`;
return metaVer;
}
export const verWrap = { value: 0, prefixSeed: 1 };
export const idWrap = { value: 0, prefixSeed: 1 };
export const symbolIdWrap = { value: 0, prefixSeed: 1 };
export const sourceIdWrap = { value: 0, prefixSeed: 1 };
export const symbolStrDict = {};
export const strSymbolDict = {};
export function genMetaId() {
return getId(idWrap, 'MID_');
}
export function genMetaVer() {
return getId(verWrap, 'MV_');
}
export function genSymbolId() {
return getId(symbolIdWrap, 'SI_');
}
export function genSourceId() {
return getId(sourceIdWrap, 'SR_');
}
export const conf = {
autoFreeze: false,
autoRevoke: true,
};