react-native/Libraries/StyleSheet/styleDiffer.js

62 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-01-30 01:10:49 +00:00
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
2015-01-30 01:10:49 +00:00
*
* @providesModule styleDiffer
2015-03-25 02:34:12 +00:00
* @flow
2015-01-30 01:10:49 +00:00
*/
'use strict';
var deepDiffer = require('deepDiffer');
2015-03-25 02:34:12 +00:00
function styleDiffer(a: any, b: any): bool {
2015-01-30 01:10:49 +00:00
return !styleEqual(a, b);
}
2015-03-25 02:34:12 +00:00
function styleEqual(a: any, b: any): bool {
2015-01-30 01:10:49 +00:00
if (!a) {
return !b;
}
if (!b) {
return !a;
}
if (typeof a !== typeof b) {
return false;
}
if (typeof a === 'number') {
return a === b;
}
if (Array.isArray(a)) {
if (!Array.isArray(b) || a.length !== b.length) {
return false;
}
for (var i = 0; i < a.length; ++i) {
if (!styleEqual(a[i], b[i])) {
return false;
}
}
return true;
}
for (var key in a) {
if (deepDiffer(a[key], b[key])) {
return false;
}
}
for (var key in b) {
if (!a.hasOwnProperty(key)) {
return false;
}
}
return true;
}
module.exports = styleDiffer;