preact-pure-props
Version:
compare only the props. If the state does not change, do not re-ender.
127 lines (96 loc) • 3.25 kB
JavaScript
/*
Copyright (c) 2019 Daybrush
name: preact-pure-props
license: MIT
author: Daybrush
repository: https://github.com/daybrush/pure-props/tree/master/preact-pure-props
version: 0.1.4
*/
var process = { env: {NODE_ENV: "production"} };
import { Component } from 'preact-compat';
/*
Copyright (c) 2019 Daybrush
name: react-pure-props
license: MIT
author: Daybrush
repository: https://github.com/daybrush/pure-props/tree/master/react-pure-props
version: 0.1.4
*/
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
};
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
//
var shallowequal = function shallowEqual(objA, objB, compare, compareContext) {
var ret = compare ? compare.call(compareContext, objA, objB) : void 0;
if (ret !== void 0) {
return !!ret;
}
if (objA === objB) {
return true;
}
if (typeof objA !== "object" || !objA || typeof objB !== "object" || !objB) {
return false;
}
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
// Test for A's keys different from B.
for (var idx = 0; idx < keysA.length; idx++) {
var key = keysA[idx];
if (!bHasOwnProperty(key)) {
return false;
}
var valueA = objA[key];
var valueB = objB[key];
ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0;
if (ret === false || (ret === void 0 && valueA !== valueB)) {
return false;
}
}
return true;
};
var PureProps =
/*#__PURE__*/
function (_super) {
__extends(PureProps, _super);
function PureProps() {
return _super !== null && _super.apply(this, arguments) || this;
}
var __proto = PureProps.prototype;
__proto.shouldComponentUpdate = function (prevProps, prevState) {
return prevState !== this.state || !shallowequal(prevProps, this.props);
};
return PureProps;
}(Component);
export default PureProps;
//# sourceMappingURL=pure-props.esm.js.map