1 | import React, { Component } from 'react';
|
2 | import shallowEqual from 'fbjs/lib/shallowEqual';
|
3 | import hoistNonReactStatics from 'hoist-non-react-statics';
|
4 | import { createChangeEmitter } from 'change-emitter';
|
5 | import $$observable from 'symbol-observable';
|
6 |
|
7 | var setStatic = function setStatic(key, value) {
|
8 | return function (BaseComponent) {
|
9 |
|
10 | BaseComponent[key] = value;
|
11 |
|
12 | return BaseComponent;
|
13 | };
|
14 | };
|
15 |
|
16 | var setDisplayName = function setDisplayName(displayName) {
|
17 | return setStatic('displayName', displayName);
|
18 | };
|
19 |
|
20 | var getDisplayName = function getDisplayName(Component$$1) {
|
21 | if (typeof Component$$1 === 'string') {
|
22 | return Component$$1;
|
23 | }
|
24 |
|
25 | if (!Component$$1) {
|
26 | return undefined;
|
27 | }
|
28 |
|
29 | return Component$$1.displayName || Component$$1.name || 'Component';
|
30 | };
|
31 |
|
32 | var wrapDisplayName = function wrapDisplayName(BaseComponent, hocName) {
|
33 | return hocName + '(' + getDisplayName(BaseComponent) + ')';
|
34 | };
|
35 |
|
36 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
37 | return typeof obj;
|
38 | } : function (obj) {
|
39 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
40 | };
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | var classCallCheck = function (instance, Constructor) {
|
53 | if (!(instance instanceof Constructor)) {
|
54 | throw new TypeError("Cannot call a class as a function");
|
55 | }
|
56 | };
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | var _extends = Object.assign || function (target) {
|
67 | for (var i = 1; i < arguments.length; i++) {
|
68 | var source = arguments[i];
|
69 |
|
70 | for (var key in source) {
|
71 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
72 | target[key] = source[key];
|
73 | }
|
74 | }
|
75 | }
|
76 |
|
77 | return target;
|
78 | };
|
79 |
|
80 |
|
81 |
|
82 | var inherits = function (subClass, superClass) {
|
83 | if (typeof superClass !== "function" && superClass !== null) {
|
84 | throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
85 | }
|
86 |
|
87 | subClass.prototype = Object.create(superClass && superClass.prototype, {
|
88 | constructor: {
|
89 | value: subClass,
|
90 | enumerable: false,
|
91 | writable: true,
|
92 | configurable: true
|
93 | }
|
94 | });
|
95 | if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
96 | };
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | var objectWithoutProperties = function (obj, keys) {
|
107 | var target = {};
|
108 |
|
109 | for (var i in obj) {
|
110 | if (keys.indexOf(i) >= 0) continue;
|
111 | if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
|
112 | target[i] = obj[i];
|
113 | }
|
114 |
|
115 | return target;
|
116 | };
|
117 |
|
118 | var possibleConstructorReturn = function (self, call) {
|
119 | if (!self) {
|
120 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
121 | }
|
122 |
|
123 | return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
124 | };
|
125 |
|
126 | var createEagerElementUtil = function createEagerElementUtil(hasKey, isReferentiallyTransparent, type, props, children) {
|
127 | if (!hasKey && isReferentiallyTransparent) {
|
128 | if (children) {
|
129 | return type(_extends({}, props, { children: children }));
|
130 | }
|
131 | return type(props);
|
132 | }
|
133 |
|
134 | var Component$$1 = type;
|
135 |
|
136 | if (children) {
|
137 | return React.createElement(
|
138 | Component$$1,
|
139 | props,
|
140 | children
|
141 | );
|
142 | }
|
143 |
|
144 | return React.createElement(Component$$1, props);
|
145 | };
|
146 |
|
147 | var isClassComponent = function isClassComponent(Component$$1) {
|
148 | return Boolean(Component$$1 && Component$$1.prototype && _typeof(Component$$1.prototype.isReactComponent) === 'object');
|
149 | };
|
150 |
|
151 | var isReferentiallyTransparentFunctionComponent = function isReferentiallyTransparentFunctionComponent(Component$$1) {
|
152 | return Boolean(typeof Component$$1 === 'function' && !isClassComponent(Component$$1) && !Component$$1.defaultProps && !Component$$1.contextTypes && (process.env.NODE_ENV === 'production' || !Component$$1.propTypes));
|
153 | };
|
154 |
|
155 | var createFactory = function createFactory(type) {
|
156 | var isReferentiallyTransparent = isReferentiallyTransparentFunctionComponent(type);
|
157 | return function (p, c) {
|
158 | return createEagerElementUtil(false, isReferentiallyTransparent, type, p, c);
|
159 | };
|
160 | };
|
161 |
|
162 | var mapProps = function mapProps(propsMapper) {
|
163 | return function (BaseComponent) {
|
164 | var factory = createFactory(BaseComponent);
|
165 | var MapProps = function MapProps(props) {
|
166 | return factory(propsMapper(props));
|
167 | };
|
168 | if (process.env.NODE_ENV !== 'production') {
|
169 | return setDisplayName(wrapDisplayName(BaseComponent, 'mapProps'))(MapProps);
|
170 | }
|
171 | return MapProps;
|
172 | };
|
173 | };
|
174 |
|
175 | var withProps = function withProps(input) {
|
176 | var hoc = mapProps(function (props) {
|
177 | return _extends({}, props, typeof input === 'function' ? input(props) : input);
|
178 | });
|
179 | if (process.env.NODE_ENV !== 'production') {
|
180 | return function (BaseComponent) {
|
181 | return setDisplayName(wrapDisplayName(BaseComponent, 'withProps'))(hoc(BaseComponent));
|
182 | };
|
183 | }
|
184 | return hoc;
|
185 | };
|
186 |
|
187 | var pick = function pick(obj, keys) {
|
188 | var result = {};
|
189 | for (var i = 0; i < keys.length; i++) {
|
190 | var key = keys[i];
|
191 | if (obj.hasOwnProperty(key)) {
|
192 | result[key] = obj[key];
|
193 | }
|
194 | }
|
195 | return result;
|
196 | };
|
197 |
|
198 | var withPropsOnChange = function withPropsOnChange(shouldMapOrKeys, propsMapper) {
|
199 | return function (BaseComponent) {
|
200 | var factory = createFactory(BaseComponent);
|
201 | var shouldMap = typeof shouldMapOrKeys === 'function' ? shouldMapOrKeys : function (props, nextProps) {
|
202 | return !shallowEqual(pick(props, shouldMapOrKeys), pick(nextProps, shouldMapOrKeys));
|
203 | };
|
204 |
|
205 | var WithPropsOnChange = function (_Component) {
|
206 | inherits(WithPropsOnChange, _Component);
|
207 |
|
208 | function WithPropsOnChange() {
|
209 | var _temp, _this, _ret;
|
210 |
|
211 | classCallCheck(this, WithPropsOnChange);
|
212 |
|
213 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
214 | args[_key] = arguments[_key];
|
215 | }
|
216 |
|
217 | return _ret = (_temp = (_this = possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.computedProps = propsMapper(_this.props), _temp), possibleConstructorReturn(_this, _ret);
|
218 | }
|
219 |
|
220 | WithPropsOnChange.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
221 | if (shouldMap(this.props, nextProps)) {
|
222 | this.computedProps = propsMapper(nextProps);
|
223 | }
|
224 | };
|
225 |
|
226 | WithPropsOnChange.prototype.render = function render() {
|
227 | return factory(_extends({}, this.props, this.computedProps));
|
228 | };
|
229 |
|
230 | return WithPropsOnChange;
|
231 | }(Component);
|
232 |
|
233 | if (process.env.NODE_ENV !== 'production') {
|
234 | return setDisplayName(wrapDisplayName(BaseComponent, 'withPropsOnChange'))(WithPropsOnChange);
|
235 | }
|
236 | return WithPropsOnChange;
|
237 | };
|
238 | };
|
239 |
|
240 |
|
241 | var mapValues = function mapValues(obj, func) {
|
242 | var result = {};
|
243 |
|
244 | for (var key in obj) {
|
245 | if (obj.hasOwnProperty(key)) {
|
246 | result[key] = func(obj[key], key);
|
247 | }
|
248 | }
|
249 |
|
250 | return result;
|
251 | };
|
252 |
|
253 | var withHandlers = function withHandlers(handlers) {
|
254 | return function (BaseComponent) {
|
255 | var factory = createFactory(BaseComponent);
|
256 |
|
257 | var WithHandlers = function (_Component) {
|
258 | inherits(WithHandlers, _Component);
|
259 |
|
260 | function WithHandlers() {
|
261 | var _temp, _this, _ret;
|
262 |
|
263 | classCallCheck(this, WithHandlers);
|
264 |
|
265 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
266 | args[_key] = arguments[_key];
|
267 | }
|
268 |
|
269 | return _ret = (_temp = (_this = possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _initialiseProps.call(_this), _temp), possibleConstructorReturn(_this, _ret);
|
270 | }
|
271 |
|
272 | WithHandlers.prototype.componentWillReceiveProps = function componentWillReceiveProps() {
|
273 | this.cachedHandlers = {};
|
274 | };
|
275 |
|
276 | WithHandlers.prototype.render = function render() {
|
277 | return factory(_extends({}, this.props, this.handlers));
|
278 | };
|
279 |
|
280 | return WithHandlers;
|
281 | }(Component);
|
282 |
|
283 | var _initialiseProps = function _initialiseProps() {
|
284 | var _this2 = this;
|
285 |
|
286 | this.cachedHandlers = {};
|
287 | this.handlers = mapValues(typeof handlers === 'function' ? handlers(this.props) : handlers, function (createHandler, handlerName) {
|
288 | return function () {
|
289 | var cachedHandler = _this2.cachedHandlers[handlerName];
|
290 | if (cachedHandler) {
|
291 | return cachedHandler.apply(undefined, arguments);
|
292 | }
|
293 |
|
294 | var handler = createHandler(_this2.props);
|
295 | _this2.cachedHandlers[handlerName] = handler;
|
296 |
|
297 | if (process.env.NODE_ENV !== 'production' && typeof handler !== 'function') {
|
298 | console.error(
|
299 |
|
300 | 'withHandlers(): Expected a map of higher-order functions. ' + 'Refer to the docs for more info.');
|
301 | }
|
302 |
|
303 | return handler.apply(undefined, arguments);
|
304 | };
|
305 | });
|
306 | };
|
307 |
|
308 | if (process.env.NODE_ENV !== 'production') {
|
309 | return setDisplayName(wrapDisplayName(BaseComponent, 'withHandlers'))(WithHandlers);
|
310 | }
|
311 | return WithHandlers;
|
312 | };
|
313 | };
|
314 |
|
315 | var defaultProps = function defaultProps(props) {
|
316 | return function (BaseComponent) {
|
317 | var factory = createFactory(BaseComponent);
|
318 | var DefaultProps = function DefaultProps(ownerProps) {
|
319 | return factory(ownerProps);
|
320 | };
|
321 | DefaultProps.defaultProps = props;
|
322 | if (process.env.NODE_ENV !== 'production') {
|
323 | return setDisplayName(wrapDisplayName(BaseComponent, 'defaultProps'))(DefaultProps);
|
324 | }
|
325 | return DefaultProps;
|
326 | };
|
327 | };
|
328 |
|
329 | var omit = function omit(obj, keys) {
|
330 | var rest = objectWithoutProperties(obj, []);
|
331 |
|
332 | for (var i = 0; i < keys.length; i++) {
|
333 | var key = keys[i];
|
334 | if (rest.hasOwnProperty(key)) {
|
335 | delete rest[key];
|
336 | }
|
337 | }
|
338 | return rest;
|
339 | };
|
340 |
|
341 | var renameProp = function renameProp(oldName, newName) {
|
342 | var hoc = mapProps(function (props) {
|
343 | var _babelHelpers$extends;
|
344 |
|
345 | return _extends({}, omit(props, [oldName]), (_babelHelpers$extends = {}, _babelHelpers$extends[newName] = props[oldName], _babelHelpers$extends));
|
346 | });
|
347 | if (process.env.NODE_ENV !== 'production') {
|
348 | return function (BaseComponent) {
|
349 | return setDisplayName(wrapDisplayName(BaseComponent, 'renameProp'))(hoc(BaseComponent));
|
350 | };
|
351 | }
|
352 | return hoc;
|
353 | };
|
354 |
|
355 | var keys = Object.keys;
|
356 |
|
357 |
|
358 | var mapKeys = function mapKeys(obj, func) {
|
359 | return keys(obj).reduce(function (result, key) {
|
360 | var val = obj[key];
|
361 |
|
362 | result[func(val, key)] = val;
|
363 |
|
364 | return result;
|
365 | }, {});
|
366 | };
|
367 |
|
368 | var renameProps = function renameProps(nameMap) {
|
369 | var hoc = mapProps(function (props) {
|
370 | return _extends({}, omit(props, keys(nameMap)), mapKeys(pick(props, keys(nameMap)), function (_, oldName) {
|
371 | return nameMap[oldName];
|
372 | }));
|
373 | });
|
374 | if (process.env.NODE_ENV !== 'production') {
|
375 | return function (BaseComponent) {
|
376 | return setDisplayName(wrapDisplayName(BaseComponent, 'renameProps'))(hoc(BaseComponent));
|
377 | };
|
378 | }
|
379 | return hoc;
|
380 | };
|
381 |
|
382 | var flattenProp = function flattenProp(propName) {
|
383 | return function (BaseComponent) {
|
384 | var factory = createFactory(BaseComponent);
|
385 | var FlattenProp = function FlattenProp(props) {
|
386 | return factory(_extends({}, props, props[propName]));
|
387 | };
|
388 |
|
389 | if (process.env.NODE_ENV !== 'production') {
|
390 | return setDisplayName(wrapDisplayName(BaseComponent, 'flattenProp'))(FlattenProp);
|
391 | }
|
392 | return FlattenProp;
|
393 | };
|
394 | };
|
395 |
|
396 | var withState = function withState(stateName, stateUpdaterName, initialState) {
|
397 | return function (BaseComponent) {
|
398 | var factory = createFactory(BaseComponent);
|
399 |
|
400 | var WithState = function (_Component) {
|
401 | inherits(WithState, _Component);
|
402 |
|
403 | function WithState() {
|
404 | var _temp, _this, _ret;
|
405 |
|
406 | classCallCheck(this, WithState);
|
407 |
|
408 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
409 | args[_key] = arguments[_key];
|
410 | }
|
411 |
|
412 | return _ret = (_temp = (_this = possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = {
|
413 | stateValue: typeof initialState === 'function' ? initialState(_this.props) : initialState
|
414 | }, _this.updateStateValue = function (updateFn, callback) {
|
415 | return _this.setState(function (_ref) {
|
416 | var stateValue = _ref.stateValue;
|
417 | return {
|
418 | stateValue: typeof updateFn === 'function' ? updateFn(stateValue) : updateFn
|
419 | };
|
420 | }, callback);
|
421 | }, _temp), possibleConstructorReturn(_this, _ret);
|
422 | }
|
423 |
|
424 | WithState.prototype.render = function render() {
|
425 | var _babelHelpers$extends;
|
426 |
|
427 | return factory(_extends({}, this.props, (_babelHelpers$extends = {}, _babelHelpers$extends[stateName] = this.state.stateValue, _babelHelpers$extends[stateUpdaterName] = this.updateStateValue, _babelHelpers$extends)));
|
428 | };
|
429 |
|
430 | return WithState;
|
431 | }(Component);
|
432 |
|
433 | if (process.env.NODE_ENV !== 'production') {
|
434 | return setDisplayName(wrapDisplayName(BaseComponent, 'withState'))(WithState);
|
435 | }
|
436 | return WithState;
|
437 | };
|
438 | };
|
439 |
|
440 | var withReducer = function withReducer(stateName, dispatchName, reducer, initialState) {
|
441 | return function (BaseComponent) {
|
442 | var factory = createFactory(BaseComponent);
|
443 |
|
444 | var WithReducer = function (_Component) {
|
445 | inherits(WithReducer, _Component);
|
446 |
|
447 | function WithReducer() {
|
448 | var _temp, _this, _ret;
|
449 |
|
450 | classCallCheck(this, WithReducer);
|
451 |
|
452 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
453 | args[_key] = arguments[_key];
|
454 | }
|
455 |
|
456 | return _ret = (_temp = (_this = possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = {
|
457 | stateValue: _this.initializeStateValue()
|
458 | }, _this.dispatch = function (action) {
|
459 | return _this.setState(function (_ref) {
|
460 | var stateValue = _ref.stateValue;
|
461 | return {
|
462 | stateValue: reducer(stateValue, action)
|
463 | };
|
464 | });
|
465 | }, _temp), possibleConstructorReturn(_this, _ret);
|
466 | }
|
467 |
|
468 | WithReducer.prototype.initializeStateValue = function initializeStateValue() {
|
469 | if (initialState !== undefined) {
|
470 | return typeof initialState === 'function' ? initialState(this.props) : initialState;
|
471 | }
|
472 | return reducer(undefined, { type: '@@recompose/INIT' });
|
473 | };
|
474 |
|
475 | WithReducer.prototype.render = function render() {
|
476 | var _babelHelpers$extends;
|
477 |
|
478 | return factory(_extends({}, this.props, (_babelHelpers$extends = {}, _babelHelpers$extends[stateName] = this.state.stateValue, _babelHelpers$extends[dispatchName] = this.dispatch, _babelHelpers$extends)));
|
479 | };
|
480 |
|
481 | return WithReducer;
|
482 | }(Component);
|
483 |
|
484 | if (process.env.NODE_ENV !== 'production') {
|
485 | return setDisplayName(wrapDisplayName(BaseComponent, 'withReducer'))(WithReducer);
|
486 | }
|
487 | return WithReducer;
|
488 | };
|
489 | };
|
490 |
|
491 | var identity = function identity(Component$$1) {
|
492 | return Component$$1;
|
493 | };
|
494 |
|
495 | var branch = function branch(test, left) {
|
496 | var right = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : identity;
|
497 | return function (BaseComponent) {
|
498 | var leftFactory = void 0;
|
499 | var rightFactory = void 0;
|
500 | var Branch = function Branch(props) {
|
501 | if (test(props)) {
|
502 | leftFactory = leftFactory || createFactory(left(BaseComponent));
|
503 | return leftFactory(props);
|
504 | }
|
505 | rightFactory = rightFactory || createFactory(right(BaseComponent));
|
506 | return rightFactory(props);
|
507 | };
|
508 |
|
509 | if (process.env.NODE_ENV !== 'production') {
|
510 | return setDisplayName(wrapDisplayName(BaseComponent, 'branch'))(Branch);
|
511 | }
|
512 | return Branch;
|
513 | };
|
514 | };
|
515 |
|
516 | var renderComponent = function renderComponent(Component$$1) {
|
517 | return function (_) {
|
518 | var factory = createFactory(Component$$1);
|
519 | var RenderComponent = function RenderComponent(props) {
|
520 | return factory(props);
|
521 | };
|
522 | if (process.env.NODE_ENV !== 'production') {
|
523 | RenderComponent.displayName = wrapDisplayName(Component$$1, 'renderComponent');
|
524 | }
|
525 | return RenderComponent;
|
526 | };
|
527 | };
|
528 |
|
529 | var Nothing = function (_Component) {
|
530 | inherits(Nothing, _Component);
|
531 |
|
532 | function Nothing() {
|
533 | classCallCheck(this, Nothing);
|
534 | return possibleConstructorReturn(this, _Component.apply(this, arguments));
|
535 | }
|
536 |
|
537 | Nothing.prototype.render = function render() {
|
538 | return null;
|
539 | };
|
540 |
|
541 | return Nothing;
|
542 | }(Component);
|
543 |
|
544 | Nothing.displayName = 'Nothing';
|
545 |
|
546 | var renderNothing = function renderNothing(_) {
|
547 | return Nothing;
|
548 | };
|
549 |
|
550 | var shouldUpdate = function shouldUpdate(test) {
|
551 | return function (BaseComponent) {
|
552 | var factory = createFactory(BaseComponent);
|
553 |
|
554 | var ShouldUpdate = function (_Component) {
|
555 | inherits(ShouldUpdate, _Component);
|
556 |
|
557 | function ShouldUpdate() {
|
558 | classCallCheck(this, ShouldUpdate);
|
559 | return possibleConstructorReturn(this, _Component.apply(this, arguments));
|
560 | }
|
561 |
|
562 | ShouldUpdate.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
|
563 | return test(this.props, nextProps);
|
564 | };
|
565 |
|
566 | ShouldUpdate.prototype.render = function render() {
|
567 | return factory(this.props);
|
568 | };
|
569 |
|
570 | return ShouldUpdate;
|
571 | }(Component);
|
572 |
|
573 | if (process.env.NODE_ENV !== 'production') {
|
574 | return setDisplayName(wrapDisplayName(BaseComponent, 'shouldUpdate'))(ShouldUpdate);
|
575 | }
|
576 | return ShouldUpdate;
|
577 | };
|
578 | };
|
579 |
|
580 | var pure = function pure(BaseComponent) {
|
581 | var hoc = shouldUpdate(function (props, nextProps) {
|
582 | return !shallowEqual(props, nextProps);
|
583 | });
|
584 |
|
585 | if (process.env.NODE_ENV !== 'production') {
|
586 | return setDisplayName(wrapDisplayName(BaseComponent, 'pure'))(hoc(BaseComponent));
|
587 | }
|
588 |
|
589 | return hoc(BaseComponent);
|
590 | };
|
591 |
|
592 | var onlyUpdateForKeys = function onlyUpdateForKeys(propKeys) {
|
593 | var hoc = shouldUpdate(function (props, nextProps) {
|
594 | return !shallowEqual(pick(nextProps, propKeys), pick(props, propKeys));
|
595 | });
|
596 |
|
597 | if (process.env.NODE_ENV !== 'production') {
|
598 | return function (BaseComponent) {
|
599 | return setDisplayName(wrapDisplayName(BaseComponent, 'onlyUpdateForKeys'))(hoc(BaseComponent));
|
600 | };
|
601 | }
|
602 | return hoc;
|
603 | };
|
604 |
|
605 | var onlyUpdateForPropTypes = function onlyUpdateForPropTypes(BaseComponent) {
|
606 | var propTypes = BaseComponent.propTypes;
|
607 |
|
608 | if (process.env.NODE_ENV !== 'production') {
|
609 | if (!propTypes) {
|
610 |
|
611 | console.error('A component without any `propTypes` was passed to ' + '`onlyUpdateForPropTypes()`. Check the implementation of the ' + ('component with display name "' + getDisplayName(BaseComponent) + '".')
|
612 |
|
613 | );
|
614 | }
|
615 | }
|
616 |
|
617 | var propKeys = Object.keys(propTypes || {});
|
618 | var OnlyUpdateForPropTypes = onlyUpdateForKeys(propKeys)(BaseComponent);
|
619 |
|
620 | if (process.env.NODE_ENV !== 'production') {
|
621 | return setDisplayName(wrapDisplayName(BaseComponent, 'onlyUpdateForPropTypes'))(OnlyUpdateForPropTypes);
|
622 | }
|
623 | return OnlyUpdateForPropTypes;
|
624 | };
|
625 |
|
626 | var withContext = function withContext(childContextTypes, getChildContext) {
|
627 | return function (BaseComponent) {
|
628 | var factory = createFactory(BaseComponent);
|
629 |
|
630 | var WithContext = function (_Component) {
|
631 | inherits(WithContext, _Component);
|
632 |
|
633 | function WithContext() {
|
634 | var _temp, _this, _ret;
|
635 |
|
636 | classCallCheck(this, WithContext);
|
637 |
|
638 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
639 | args[_key] = arguments[_key];
|
640 | }
|
641 |
|
642 | return _ret = (_temp = (_this = possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.getChildContext = function () {
|
643 | return getChildContext(_this.props);
|
644 | }, _temp), possibleConstructorReturn(_this, _ret);
|
645 | }
|
646 |
|
647 | WithContext.prototype.render = function render() {
|
648 | return factory(this.props);
|
649 | };
|
650 |
|
651 | return WithContext;
|
652 | }(Component);
|
653 |
|
654 | WithContext.childContextTypes = childContextTypes;
|
655 |
|
656 | if (process.env.NODE_ENV !== 'production') {
|
657 | return setDisplayName(wrapDisplayName(BaseComponent, 'withContext'))(WithContext);
|
658 | }
|
659 | return WithContext;
|
660 | };
|
661 | };
|
662 |
|
663 | var getContext = function getContext(contextTypes) {
|
664 | return function (BaseComponent) {
|
665 | var factory = createFactory(BaseComponent);
|
666 | var GetContext = function GetContext(ownerProps, context) {
|
667 | return factory(_extends({}, ownerProps, context));
|
668 | };
|
669 |
|
670 | GetContext.contextTypes = contextTypes;
|
671 |
|
672 | if (process.env.NODE_ENV !== 'production') {
|
673 | return setDisplayName(wrapDisplayName(BaseComponent, 'getContext'))(GetContext);
|
674 | }
|
675 | return GetContext;
|
676 | };
|
677 | };
|
678 |
|
679 |
|
680 | var lifecycle = function lifecycle(spec) {
|
681 | return function (BaseComponent) {
|
682 | var factory = createFactory(BaseComponent);
|
683 |
|
684 | if (process.env.NODE_ENV !== 'production' && spec.hasOwnProperty('render')) {
|
685 | console.error('lifecycle() does not support the render method; its behavior is to ' + 'pass all props and state to the base component.');
|
686 | }
|
687 |
|
688 | var Lifecycle = function (_Component) {
|
689 | inherits(Lifecycle, _Component);
|
690 |
|
691 | function Lifecycle() {
|
692 | classCallCheck(this, Lifecycle);
|
693 | return possibleConstructorReturn(this, _Component.apply(this, arguments));
|
694 | }
|
695 |
|
696 | Lifecycle.prototype.render = function render() {
|
697 | return factory(_extends({}, this.props, this.state));
|
698 | };
|
699 |
|
700 | return Lifecycle;
|
701 | }(Component);
|
702 |
|
703 | Object.keys(spec).forEach(function (hook) {
|
704 | return Lifecycle.prototype[hook] = spec[hook];
|
705 | });
|
706 |
|
707 | if (process.env.NODE_ENV !== 'production') {
|
708 | return setDisplayName(wrapDisplayName(BaseComponent, 'lifecycle'))(Lifecycle);
|
709 | }
|
710 | return Lifecycle;
|
711 | };
|
712 | };
|
713 |
|
714 | var toClass = function toClass(baseComponent) {
|
715 | if (isClassComponent(baseComponent)) {
|
716 | return baseComponent;
|
717 | }
|
718 |
|
719 | var ToClass = function (_Component) {
|
720 | inherits(ToClass, _Component);
|
721 |
|
722 | function ToClass() {
|
723 | classCallCheck(this, ToClass);
|
724 | return possibleConstructorReturn(this, _Component.apply(this, arguments));
|
725 | }
|
726 |
|
727 | ToClass.prototype.render = function render() {
|
728 | if (typeof baseComponent === 'string') {
|
729 | return React.createElement(baseComponent, this.props);
|
730 | }
|
731 | return baseComponent(this.props, this.context);
|
732 | };
|
733 |
|
734 | return ToClass;
|
735 | }(Component);
|
736 |
|
737 | ToClass.displayName = getDisplayName(baseComponent);
|
738 | ToClass.propTypes = baseComponent.propTypes;
|
739 | ToClass.contextTypes = baseComponent.contextTypes;
|
740 | ToClass.defaultProps = baseComponent.defaultProps;
|
741 |
|
742 | return ToClass;
|
743 | };
|
744 |
|
745 | var setPropTypes = function setPropTypes(propTypes) {
|
746 | return setStatic('propTypes', propTypes);
|
747 | };
|
748 |
|
749 | function compose() {
|
750 | for (var _len = arguments.length, funcs = Array(_len), _key = 0; _key < _len; _key++) {
|
751 | funcs[_key] = arguments[_key];
|
752 | }
|
753 |
|
754 | if (funcs.length === 0) {
|
755 | return function (arg) {
|
756 | return arg;
|
757 | };
|
758 | }
|
759 |
|
760 | if (funcs.length === 1) {
|
761 | return funcs[0];
|
762 | }
|
763 |
|
764 | return funcs.reduce(function (a, b) {
|
765 | return function () {
|
766 | return a(b.apply(undefined, arguments));
|
767 | };
|
768 | });
|
769 | }
|
770 |
|
771 | var createEagerElement = function createEagerElement(type, props, children) {
|
772 | var isReferentiallyTransparent = isReferentiallyTransparentFunctionComponent(type
|
773 |
|
774 | );var hasKey = props && props.hasOwnProperty('key'
|
775 |
|
776 | );return createEagerElementUtil(hasKey, isReferentiallyTransparent, type, props, children);
|
777 | };
|
778 |
|
779 | var createSink = function createSink(callback) {
|
780 | return function (_Component) {
|
781 | inherits(Sink, _Component);
|
782 |
|
783 | function Sink() {
|
784 | classCallCheck(this, Sink);
|
785 | return possibleConstructorReturn(this, _Component.apply(this, arguments));
|
786 | }
|
787 |
|
788 | Sink.prototype.componentWillMount = function componentWillMount() {
|
789 | callback(this.props);
|
790 | };
|
791 |
|
792 | Sink.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
793 | callback(nextProps);
|
794 | };
|
795 |
|
796 | Sink.prototype.render = function render() {
|
797 | return null;
|
798 | };
|
799 |
|
800 | return Sink;
|
801 | }(Component);
|
802 | };
|
803 |
|
804 | var componentFromProp = function componentFromProp(propName) {
|
805 | var Component$$1 = function Component$$1(props) {
|
806 | return createEagerElement(props[propName], omit(props, [propName]));
|
807 | };
|
808 | Component$$1.displayName = 'componentFromProp(' + propName + ')';
|
809 | return Component$$1;
|
810 | };
|
811 |
|
812 | var nest = function nest() {
|
813 | for (var _len = arguments.length, Components = Array(_len), _key = 0; _key < _len; _key++) {
|
814 | Components[_key] = arguments[_key];
|
815 | }
|
816 |
|
817 | var factories = Components.map(createFactory);
|
818 | var Nest = function Nest(_ref) {
|
819 | var props = objectWithoutProperties(_ref, []),
|
820 | children = _ref.children;
|
821 | return factories.reduceRight(function (child, factory) {
|
822 | return factory(props, child);
|
823 | }, children);
|
824 | };
|
825 |
|
826 | if (process.env.NODE_ENV !== 'production') {
|
827 | var displayNames = Components.map(getDisplayName);
|
828 | Nest.displayName = 'nest(' + displayNames.join(', ') + ')';
|
829 | }
|
830 |
|
831 | return Nest;
|
832 | };
|
833 |
|
834 | var hoistStatics = function hoistStatics(higherOrderComponent) {
|
835 | return function (BaseComponent) {
|
836 | var NewComponent = higherOrderComponent(BaseComponent);
|
837 | hoistNonReactStatics(NewComponent, BaseComponent);
|
838 | return NewComponent;
|
839 | };
|
840 | };
|
841 |
|
842 | var _config = {
|
843 | fromESObservable: null,
|
844 | toESObservable: null
|
845 | };
|
846 |
|
847 | var configureObservable = function configureObservable(c) {
|
848 | _config = c;
|
849 | };
|
850 |
|
851 | var config = {
|
852 | fromESObservable: function fromESObservable(observable) {
|
853 | return typeof _config.fromESObservable === 'function' ? _config.fromESObservable(observable) : observable;
|
854 | },
|
855 | toESObservable: function toESObservable(stream) {
|
856 | return typeof _config.toESObservable === 'function' ? _config.toESObservable(stream) : stream;
|
857 | }
|
858 | };
|
859 |
|
860 | var componentFromStreamWithConfig = function componentFromStreamWithConfig(config$$1) {
|
861 | return function (propsToVdom) {
|
862 | return function (_Component) {
|
863 | inherits(ComponentFromStream, _Component);
|
864 |
|
865 | function ComponentFromStream() {
|
866 | var _config$fromESObserva;
|
867 |
|
868 | var _temp, _this, _ret;
|
869 |
|
870 | classCallCheck(this, ComponentFromStream);
|
871 |
|
872 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
873 | args[_key] = arguments[_key];
|
874 | }
|
875 |
|
876 | return _ret = (_temp = (_this = possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = { vdom: null }, _this.propsEmitter = createChangeEmitter
|
877 |
|
878 |
|
879 | (), _this.props$ = config$$1.fromESObservable((_config$fromESObserva = {
|
880 | subscribe: function subscribe(observer) {
|
881 | var unsubscribe = _this.propsEmitter.listen(function (props) {
|
882 | if (props) {
|
883 | observer.next(props);
|
884 | } else {
|
885 | observer.complete();
|
886 | }
|
887 | });
|
888 | return { unsubscribe: unsubscribe };
|
889 | }
|
890 | }, _config$fromESObserva[$$observable] = function () {
|
891 | return this;
|
892 | }, _config$fromESObserva)), _this.vdom$ = config$$1.toESObservable(propsToVdom(_this.props$)), _temp), possibleConstructorReturn(_this, _ret);
|
893 | }
|
894 |
|
895 |
|
896 |
|
897 |
|
898 | ComponentFromStream.prototype.componentWillMount = function componentWillMount() {
|
899 | var _this2 = this;
|
900 |
|
901 |
|
902 | this.subscription = this.vdom$.subscribe({
|
903 | next: function next(vdom) {
|
904 | _this2.setState({ vdom: vdom });
|
905 | }
|
906 | });
|
907 | this.propsEmitter.emit(this.props);
|
908 | };
|
909 |
|
910 | ComponentFromStream.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
911 |
|
912 | this.propsEmitter.emit(nextProps);
|
913 | };
|
914 |
|
915 | ComponentFromStream.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
916 | return nextState.vdom !== this.state.vdom;
|
917 | };
|
918 |
|
919 | ComponentFromStream.prototype.componentWillUnmount = function componentWillUnmount() {
|
920 |
|
921 | this.propsEmitter.emit
|
922 |
|
923 |
|
924 | ();this.subscription.unsubscribe();
|
925 | };
|
926 |
|
927 | ComponentFromStream.prototype.render = function render() {
|
928 | return this.state.vdom;
|
929 | };
|
930 |
|
931 | return ComponentFromStream;
|
932 | }(Component);
|
933 | };
|
934 | };
|
935 |
|
936 | var componentFromStream = function componentFromStream(propsToVdom) {
|
937 | return componentFromStreamWithConfig(config)(propsToVdom);
|
938 | };
|
939 |
|
940 | var identity$1 = function identity(t) {
|
941 | return t;
|
942 | };
|
943 |
|
944 | var mapPropsStreamWithConfig = function mapPropsStreamWithConfig(config$$1) {
|
945 | var componentFromStream = componentFromStreamWithConfig({
|
946 | fromESObservable: identity$1,
|
947 | toESObservable: identity$1
|
948 | });
|
949 | return function (transform) {
|
950 | return function (BaseComponent) {
|
951 | var factory = createFactory(BaseComponent);
|
952 | var fromESObservable = config$$1.fromESObservable,
|
953 | toESObservable = config$$1.toESObservable;
|
954 |
|
955 | return componentFromStream(function (props$) {
|
956 | var _ref;
|
957 |
|
958 | return _ref = {
|
959 | subscribe: function subscribe(observer) {
|
960 | var subscription = toESObservable(transform(fromESObservable(props$))).subscribe({
|
961 | next: function next(childProps) {
|
962 | return observer.next(factory(childProps));
|
963 | }
|
964 | });
|
965 | return {
|
966 | unsubscribe: function unsubscribe() {
|
967 | return subscription.unsubscribe();
|
968 | }
|
969 | };
|
970 | }
|
971 | }, _ref[$$observable] = function () {
|
972 | return this;
|
973 | }, _ref;
|
974 | });
|
975 | };
|
976 | };
|
977 | };
|
978 |
|
979 | var mapPropsStream = function mapPropsStream(transform) {
|
980 | var hoc = mapPropsStreamWithConfig(config)(transform);
|
981 |
|
982 | if (process.env.NODE_ENV !== 'production') {
|
983 | return function (BaseComponent) {
|
984 | return setDisplayName(wrapDisplayName(BaseComponent, 'mapPropsStream'))(hoc(BaseComponent));
|
985 | };
|
986 | }
|
987 | return hoc;
|
988 | };
|
989 |
|
990 | var createEventHandlerWithConfig = function createEventHandlerWithConfig(config$$1) {
|
991 | return function () {
|
992 | var _config$fromESObserva;
|
993 |
|
994 | var emitter = createChangeEmitter();
|
995 | var stream = config$$1.fromESObservable((_config$fromESObserva = {
|
996 | subscribe: function subscribe(observer) {
|
997 | var unsubscribe = emitter.listen(function (value) {
|
998 | return observer.next(value);
|
999 | });
|
1000 | return { unsubscribe: unsubscribe };
|
1001 | }
|
1002 | }, _config$fromESObserva[$$observable] = function () {
|
1003 | return this;
|
1004 | }, _config$fromESObserva));
|
1005 | return {
|
1006 | handler: emitter.emit,
|
1007 | stream: stream
|
1008 | };
|
1009 | };
|
1010 | };
|
1011 |
|
1012 | var createEventHandler = createEventHandlerWithConfig(config);
|
1013 |
|
1014 |
|
1015 |
|
1016 | export { mapProps, withProps, withPropsOnChange, withHandlers, defaultProps, renameProp, renameProps, flattenProp, withState, withReducer, branch, renderComponent, renderNothing, shouldUpdate, pure, onlyUpdateForKeys, onlyUpdateForPropTypes, withContext, getContext, lifecycle, toClass, setStatic, setPropTypes, setDisplayName, compose, getDisplayName, wrapDisplayName, shallowEqual, isClassComponent, createEagerElement, createFactory as createEagerFactory, createSink, componentFromProp, nest, hoistStatics, componentFromStream, componentFromStreamWithConfig, mapPropsStream, mapPropsStreamWithConfig, createEventHandler, configureObservable as setObservableConfig };
|