@zedux/atoms
Version:
A Molecular State Engine for React
15 lines (14 loc) • 638 B
JavaScript
import { Ecosystem } from '../classes/Ecosystem.js';
import { getEcosystem, internalStore } from '../store/index.js';
export const createEcosystem = (config = {}) => {
if (config === null || config === void 0 ? void 0 : config.id) {
const ecosystem = getEcosystem(config.id);
if (ecosystem)
return ecosystem;
}
const ecosystem = new Ecosystem(config);
// yep. Set this here. We'll make sure no component can ever be updated
// synchronously from this call (causing update-during-render react warnings)
internalStore.setStateDeep({ [ecosystem.id]: ecosystem });
return ecosystem;
};