Simplifies `inherit` checks in property restoring.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 24 Jun 2015 08:00:23 +0000 (09:00 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 24 Jun 2015 08:25:37 +0000 (09:25 +0100)
lib/properties/restore.js

index 358e7a8..d9d40f9 100644 (file)
@@ -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;