react-native-full-responsive
Version:
Create a fully responsive React Native app for all supported platforms
37 lines (36 loc) • 1.33 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.recursiveMapping = void 0;
var _parseValue = require("../parseValue");
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 (0, _parseValue.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);
};
exports.recursiveMapping = recursiveMapping;
//# sourceMappingURL=recursiveMapping.js.map
;