UNPKG

@idiosync/react-observable

Version:

State management control layer for React projects

31 lines (30 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mergeStoreObjects = exports.getStoreObservable = void 0; const create_store_1 = require("../store/create-store"); const general_1 = require("./general"); const getStoreObservable = (callback) => { const store = create_store_1.store$.get(); if (!store) { throw new Error('Store not initialized'); } return callback(store); }; exports.getStoreObservable = getStoreObservable; const mergeStoreObjects = (...storeObjects) => { // Validate all inputs are objects return storeObjects.reduce((store, storeObject, index) => { if (!(0, general_1.isObject)(store)) { throw new Error(`Store object at index ${index} is not a valid object. Got: ${typeof store}`); } return Object.entries(storeObject).reduce((storeSegments, [key, segment]) => { if (!(0, general_1.isObject)(segment)) { throw new Error(`Store segment ${key} is not a valid object. Got: ${typeof segment}`); } return storeSegments[key] ? { ...storeSegments, [key]: { ...storeSegments[key], ...segment } } : { ...storeSegments, [key]: segment }; }, store); }, {}); }; exports.mergeStoreObjects = mergeStoreObjects;