source: node_modules/react-immutable-pure-component/lib/react-immutable-pure-component.es.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 6.0 KB
Line 
1import React from 'react';
2import { is } from 'immutable';
3
4function _typeof(obj) {
5 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
6 _typeof = function (obj) {
7 return typeof obj;
8 };
9 } else {
10 _typeof = function (obj) {
11 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
12 };
13 }
14
15 return _typeof(obj);
16}
17
18function _classCallCheck(instance, Constructor) {
19 if (!(instance instanceof Constructor)) {
20 throw new TypeError("Cannot call a class as a function");
21 }
22}
23
24function _defineProperties(target, props) {
25 for (var i = 0; i < props.length; i++) {
26 var descriptor = props[i];
27 descriptor.enumerable = descriptor.enumerable || false;
28 descriptor.configurable = true;
29 if ("value" in descriptor) descriptor.writable = true;
30 Object.defineProperty(target, descriptor.key, descriptor);
31 }
32}
33
34function _createClass(Constructor, protoProps, staticProps) {
35 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
36 if (staticProps) _defineProperties(Constructor, staticProps);
37 return Constructor;
38}
39
40function _defineProperty(obj, key, value) {
41 if (key in obj) {
42 Object.defineProperty(obj, key, {
43 value: value,
44 enumerable: true,
45 configurable: true,
46 writable: true
47 });
48 } else {
49 obj[key] = value;
50 }
51
52 return obj;
53}
54
55function ownKeys(object, enumerableOnly) {
56 var keys = Object.keys(object);
57
58 if (Object.getOwnPropertySymbols) {
59 var symbols = Object.getOwnPropertySymbols(object);
60 if (enumerableOnly) symbols = symbols.filter(function (sym) {
61 return Object.getOwnPropertyDescriptor(object, sym).enumerable;
62 });
63 keys.push.apply(keys, symbols);
64 }
65
66 return keys;
67}
68
69function _objectSpread2(target) {
70 for (var i = 1; i < arguments.length; i++) {
71 var source = arguments[i] != null ? arguments[i] : {};
72
73 if (i % 2) {
74 ownKeys(source, true).forEach(function (key) {
75 _defineProperty(target, key, source[key]);
76 });
77 } else if (Object.getOwnPropertyDescriptors) {
78 Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
79 } else {
80 ownKeys(source).forEach(function (key) {
81 Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
82 });
83 }
84 }
85
86 return target;
87}
88
89function _inherits(subClass, superClass) {
90 if (typeof superClass !== "function" && superClass !== null) {
91 throw new TypeError("Super expression must either be null or a function");
92 }
93
94 subClass.prototype = Object.create(superClass && superClass.prototype, {
95 constructor: {
96 value: subClass,
97 writable: true,
98 configurable: true
99 }
100 });
101 if (superClass) _setPrototypeOf(subClass, superClass);
102}
103
104function _getPrototypeOf(o) {
105 _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
106 return o.__proto__ || Object.getPrototypeOf(o);
107 };
108 return _getPrototypeOf(o);
109}
110
111function _setPrototypeOf(o, p) {
112 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
113 o.__proto__ = p;
114 return o;
115 };
116
117 return _setPrototypeOf(o, p);
118}
119
120function _assertThisInitialized(self) {
121 if (self === void 0) {
122 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
123 }
124
125 return self;
126}
127
128function _possibleConstructorReturn(self, call) {
129 if (call && (typeof call === "object" || typeof call === "function")) {
130 return call;
131 }
132
133 return _assertThisInitialized(self);
134}
135
136var NOT_SET = {};
137function isMapLike(collection) {
138 return collection !== null && _typeof(collection) === 'object' && typeof collection.get === 'function' && typeof collection.has === 'function';
139}
140
141function isInvalid(collection) {
142 return collection === null || collection === undefined;
143}
144
145function get(collection, key, notSetValue) {
146 if (isInvalid(collection)) {
147 return notSetValue;
148 }
149
150 if (isMapLike(collection)) {
151 return collection.has(key) ? collection.get(key) : notSetValue;
152 }
153
154 return hasOwnProperty.call(collection, key) ? collection[key] : notSetValue;
155}
156function getIn(collection, keyPath, notSetValue) {
157 var i = 0;
158
159 while (i !== keyPath.length) {
160 collection = get(collection, keyPath[i++], NOT_SET);
161
162 if (collection === NOT_SET) {
163 return notSetValue;
164 }
165 }
166
167 return collection;
168}
169
170function check(config) {
171 var prev = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
172 var next = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
173 var checkItem = createChecker(prev, next);
174 var checklist = config || Object.keys(_objectSpread2({}, next, {}, prev));
175 return checklist.every(checkItem);
176}
177
178function createChecker(prev, next) {
179 return function (name) {
180 if (typeof name === 'string') {
181 return is(next[name], prev[name]);
182 } else if (Array.isArray(name)) {
183 return is(getIn(next, name), getIn(prev, name));
184 }
185
186 throw new TypeError('Invalid key: expected Array or string: ' + name);
187 };
188}
189
190var ImmutablePureComponent =
191/*#__PURE__*/
192function (_React$Component) {
193 _inherits(ImmutablePureComponent, _React$Component);
194
195 function ImmutablePureComponent() {
196 _classCallCheck(this, ImmutablePureComponent);
197
198 return _possibleConstructorReturn(this, _getPrototypeOf(ImmutablePureComponent).apply(this, arguments));
199 }
200
201 _createClass(ImmutablePureComponent, [{
202 key: "shouldComponentUpdate",
203 value: function shouldComponentUpdate(nextProps) {
204 var nextState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
205 return !check(this.updateOnProps, this.props, nextProps, 'updateOnProps') || !check(this.updateOnStates, this.state, nextState, 'updateOnStates');
206 }
207 }]);
208
209 return ImmutablePureComponent;
210}(React.Component);
211
212function immutableMemo(Component, updateOnProps) {
213 return React.memo(Component, function (prev, next) {
214 return check(updateOnProps, prev, next, 'immutableMemo');
215 });
216}
217
218export default ImmutablePureComponent;
219export { ImmutablePureComponent, immutableMemo };
Note: See TracBrowser for help on using the repository browser.