UNPKG

@zedux/atoms

Version:

A Molecular State Engine for React

19 lines (18 loc) 796 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createEcosystem = void 0; const Ecosystem_1 = require("../classes/Ecosystem"); const index_1 = require("../store/index"); const createEcosystem = (config = {}) => { if (config === null || config === void 0 ? void 0 : config.id) { const ecosystem = (0, index_1.getEcosystem)(config.id); if (ecosystem) return ecosystem; } const ecosystem = new Ecosystem_1.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) index_1.internalStore.setStateDeep({ [ecosystem.id]: ecosystem }); return ecosystem; }; exports.createEcosystem = createEcosystem;