From a9d460434e76f1c51c8a92fa02db4e2bd45e3598 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Wed, 24 Jun 2015 09:00:23 +0100 Subject: [PATCH] Simplifies `inherit` checks in property restoring. --- lib/properties/restore.js | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/lib/properties/restore.js b/lib/properties/restore.js index 358e7a8a..d9d40f90 100644 --- a/lib/properties/restore.js +++ b/lib/properties/restore.js @@ -2,6 +2,17 @@ var shallowClone = require('./clone').shallow; var MULTIPLEX_SEPARATOR = ','; var SIZE_POSITION_SEPARATOR = '/'; +function isInheritOnly(values) { + for (var i = 0, l = values.length; i < l; i++) { + var value = values[i][0]; + + if (value != 'inherit' && value != MULTIPLEX_SEPARATOR && value != SIZE_POSITION_SEPARATOR) + return false; + } + + return true; +} + function background(property, compactable, lastInMultiplex) { var components = property.components; var restored = []; @@ -80,23 +91,12 @@ function background(property, compactable, lastInMultiplex) { if (restored.length === 0) restored.push([compactable[property.name].defaultValue]); - if (_isInheritBackground(restored)) + if (isInheritOnly(restored)) return [restored[0]]; return restored; } -function _isInheritBackground(values) { - for (var i = 0, l = values.length; i < l; i++) { - var value = values[i][0]; - - if (value != 'inherit' && value != MULTIPLEX_SEPARATOR && value != SIZE_POSITION_SEPARATOR) - return false; - } - - return true; -} - function borderRadius(property, compactable) { if (property.multiplex) { var horizontal = shallowClone(property); @@ -199,17 +199,6 @@ function multiplex(restoreWith) { }; } -function _isInheritOnly(values) { - for (var i = 0, l = values.length; i < l; i++) { - var value = values[i][0]; - - if (value != 'inherit') - return false; - } - - return true; -} - function withoutDefaults(property, compactable) { var components = property.components; var restored = []; @@ -225,7 +214,7 @@ function withoutDefaults(property, compactable) { if (restored.length === 0) restored.push([compactable[property.name].defaultValue]); - if (_isInheritOnly(restored)) + if (isInheritOnly(restored)) return [restored[0]]; return restored; -- 2.34.1