UNPKG

react-native-full-responsive

Version:

Create a fully responsive React Native app for all supported platforms

30 lines 1.16 kB
import { parseValue } from '../parseValue'; export const recursiveMapping = (style, styleConfig) => { /** * WeakMap to store references to already processed objects and arrays * to avoid redundant processing and improve performance (caching). */ const cache = new WeakMap(); const mapper = currentStyle => { if (currentStyle == null || typeof currentStyle !== 'object') { return parseValue(currentStyle, styleConfig); } const cachedResult = cache.get(currentStyle); if (cachedResult) return cachedResult; /** * Create an empty result structure to hold the mapped values */ const result = Array.isArray(currentStyle) ? currentStyle.map(mapper) : Object.create(null); /** * Recursively map each property in the current object (or array element). * If the currentStyle is an object, we loop through its properties and apply `mapper` to each one. */ for (const property in currentStyle) { result[property] = mapper(currentStyle[property]); } cache.set(currentStyle, result); return result; }; return mapper(style); }; //# sourceMappingURL=recursiveMapping.js.map