| 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 | 2×
2×
2×
2×
2×
2×
166×
292×
458×
458×
458×
4×
454×
256×
198×
173×
198×
198×
458×
458×
458×
433×
458×
458×
458×
433×
458×
979×
12×
967×
860×
107×
56×
51×
51×
50×
1×
1×
458×
458×
861×
232×
| var Loadable, React, _;
React = require('react');
Loadable = require('./loadable');
_ = require('underscore');
module.exports = React.createClass({
displayName: 'LoadableItem',
propTypes: {
id: React.PropTypes.string.isRequired,
options: React.PropTypes.object,
store: React.PropTypes.object.isRequired,
actions: React.PropTypes.object.isRequired,
renderItem: React.PropTypes.func.isRequired,
saved: React.PropTypes.func,
load: React.PropTypes.func,
renderLoading: React.PropTypes.func,
renderError: React.PropTypes.func,
update: React.PropTypes.func,
bindEvent: React.PropTypes.string,
isLong: React.PropTypes.bool
},
getDefaultProps: function() {
return {
bindEvent: 'change',
isLong: false
};
},
componentDidMount: function() {
return this.reload({});
},
componentDidUpdate: function(oldProps) {
return this.reload(oldProps);
},
reload: function(oldProps) {
var actions, id, load, options, ref, store;
ref = this.props, id = ref.id, store = ref.store, load = ref.load, actions = ref.actions, options = ref.options;
if (id == null) {
return;
}
if (oldProps.id === id && oldProps.store === store && oldProps.actions === actions && oldProps.load === load && _.isEqual(oldProps.options, options)) {
return;
}
if (load == null) {
load = actions.load;
}
Eif (!store.isNew(id, options)) {
return load(id, options);
}
},
render: function() {
var actions, bindEvent, id, isLoaded, isLoading, isLoadingOrLoad, isLong, load, options, ref, renderBug, renderError, renderItem, renderLoading, renderModes, saved, store, update;
ref = this.props, id = ref.id, store = ref.store, actions = ref.actions, load = ref.load, isLoaded = ref.isLoaded, isLoading = ref.isLoading, renderItem = ref.renderItem, saved = ref.saved, renderLoading = ref.renderLoading, renderError = ref.renderError, renderBug = ref.renderBug, update = ref.update, options = ref.options, bindEvent = ref.bindEvent, isLong = ref.isLong;
if (load == null) {
load = actions.load;
}
Eif (isLoaded == null) {
isLoaded = store.isLoaded;
}
if (isLoading == null) {
isLoading = store.isLoading;
}
isLoadingOrLoad = function() {
if (id == null) {
return true;
}
if (store.get(id, options)) {
return false;
} else if (isLoading(id, options)) {
return true;
} else Iif (isLoaded(id, options)) {
return false;
} else if (store.isUnknown(id, options) || store.reload(id, options)) {
return true;
} else Iif (store.isNew(id, options) && store.get(id, options).id && saved) {
return saved();
} else {
return false;
}
};
renderModes = {
renderLoading: renderLoading,
renderError: renderError,
renderBug: renderBug
};
return React.createElement(Loadable, {
"store": store,
"isLoading": isLoadingOrLoad,
"isLoaded": (function() {
return isLoaded(id);
}),
"isFailed": (function() {
return store.isFailed(id);
}),
"render": renderItem,
"renderLoading": renderLoading,
"update": update,
"bindEvent": bindEvent,
"isLong": isLong,
"renderModes": true,
"s": true
});
}
});
|