UNPKG

mobx-view-model

Version:
22 lines (21 loc) 729 B
import { createCounter } from 'yummies/complex'; const staticCounter = createCounter((counter) => counter.toString(16)); export const generateVmId = (ctx) => { if (!ctx.generateId) { const staticId = staticCounter(); const counter = createCounter((counter) => counter.toString().padStart(5, '0')); ctx.generateId = () => `${staticId}_${counter().toString().padStart(5, '0')}`; } if (process.env.NODE_ENV === 'production') { return ctx.generateId(); } else { const viewModelName = ctx.VM?.name ?? ''; if (viewModelName) { return `${viewModelName}_${ctx.generateId()}`; } else { return ctx.generateId(); } } };