mobx-view-model
Version:
MobX ViewModel power for ReactJS
16 lines (15 loc) • 573 B
JavaScript
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 {
return `${ctx.VM?.name}_${ctx.generateId()}`;
}
};