forked from Ambroos/react-nested-status
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (39 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
var React = require('react'),
PropTypes = require('prop-types'),
withSideEffect = require('react-side-effect');
function reducePropsToState(propsList) {
var innermostProps = propsList[propsList.length - 1];
if (innermostProps) {
return innermostProps.code;
}
}
function handleStateChangeOnClient(code) {
return code;
}
function NestedStatus() {}
NestedStatus.prototype = Object.create(React.Component.prototype);
NestedStatus.displayName = 'NestedStatus';
NestedStatus.propTypes = {
code: PropTypes.number.isRequired
};
NestedStatus.prototype.render = function () {
if (this.props.children) {
return React.Children.only(this.props.children);
} else {
return null;
}
};
var sideEffected = withSideEffect(
reducePropsToState,
handleStateChangeOnClient
)(NestedStatus);
var getState = sideEffected.peek;
var getFinalState = sideEffected.rewind;
sideEffected.peek = function() {
return getState() || 200;
};
sideEffected.rewind = function() {
return getFinalState() || 200;
};
module.exports = sideEffected;