5
5
/// A Dart library for building UI using ReactJS.
6
6
library react;
7
7
8
- /// Top-level ReactJS [Component class] (https://facebook.github.io/react/docs/top-level-api.html#react.component)
9
- /// which provides the [ReactJS Component API] (https://facebook.github.io/react/docs/component-api.html)
8
+ import 'package:react/src/typedefs.dart' ;
9
+
10
+ /// Top-level ReactJS [Component class] (https://facebook.github.io/react/docs/react-component.html)
11
+ /// which provides the [ReactJS Component API] (https://facebook.github.io/react/docs/react-component.html#reference)
10
12
abstract class Component {
11
- /// ReactJS `Component` props.
12
- Map props;
13
+ /// A private field that backs [props] , which is exposed via getter/setter so
14
+ /// it can be overridden in strong mode.
15
+ ///
16
+ /// Necessary since the `@virtual` annotation within the meta package
17
+ /// [doesn't work for overriding fields] (https://github.com/dart-lang/sdk/issues/27452).
18
+ ///
19
+ /// TODO: Switch back to a plain field once this issue is fixed.
20
+ Map _props;
21
+
22
+ /// A private field that backs [state] , which is exposed via getter/setter so
23
+ /// it can be overridden in strong mode.
24
+ ///
25
+ /// Necessary since the `@virtual` annotation within the meta package
26
+ /// [doesn't work for overriding fields] (https://github.com/dart-lang/sdk/issues/27452).
27
+ ///
28
+ /// TODO: Switch back to a plain field once this issue is fixed.
29
+ Map _state = {};
13
30
14
- /// Provides access to the underlying DOM representation of the [render] ed `Component` .
15
- dynamic ref;
31
+ /// A private field that backs [ref] , which is exposed via getter/setter so
32
+ /// it can be overridden in strong mode.
33
+ ///
34
+ /// Necessary since the `@virtual` annotation within the meta package
35
+ /// [doesn't work for overriding fields] (https://github.com/dart-lang/sdk/issues/27452).
36
+ ///
37
+ /// TODO: Switch back to a plain field once this issue is fixed.
38
+ Ref _ref;
39
+
40
+ /// ReactJS [Component] props.
41
+ ///
42
+ /// Related: [state]
43
+ Map get props => _props;
44
+ set props (Map value) => _props = value;
45
+
46
+ /// ReactJS [Component] state.
47
+ ///
48
+ /// Related: [props]
49
+ Map get state => _state;
50
+ set state (Map value) => _state = value;
51
+
52
+ /// A function that returns a component reference:
53
+ ///
54
+ /// * [Component] if it is a Dart component.
55
+ /// * `Element` _(DOM node)_ if it is a React DOM component.
56
+ Ref get ref => _ref;
57
+ set ref (Ref value) => _ref = value;
16
58
17
59
dynamic _jsRedraw;
18
60
@@ -32,14 +74,14 @@ abstract class Component {
32
74
/// instance of this `Component` returned by [render] .
33
75
dynamic get jsThis => _jsThis;
34
76
35
- /// Allows the [ReactJS `displayName` property] (https://facebook.github.io/react/docs/component-specs .html#displayname)
77
+ /// Allows the [ReactJS `displayName` property] (https://facebook.github.io/react/docs/react-component .html#displayname)
36
78
/// to be set for debugging purposes.
37
79
String get displayName => runtimeType.toString ();
38
80
39
81
/// Bind the value of input to [state[key] ].
40
82
bind (key) => [state[key], (value) => setState ({key: value})];
41
83
42
- initComponentInternal (props, _jsRedraw, [ref, _jsThis]) {
84
+ initComponentInternal (props, _jsRedraw, [Ref ref, _jsThis]) {
43
85
this ._jsRedraw = _jsRedraw;
44
86
this .ref = ref;
45
87
this ._jsThis = _jsThis;
@@ -57,9 +99,6 @@ abstract class Component {
57
99
transferComponentState ();
58
100
}
59
101
60
- /// ReactJS `Component` state.
61
- Map state = {};
62
-
63
102
/// Private reference to the value of [state] from the previous render cycle.
64
103
///
65
104
/// Useful for ReactJS lifecycle methods [shouldComponentUpdate] , [componentWillUpdate] and [componentDidUpdate] .
@@ -98,7 +137,7 @@ abstract class Component {
98
137
///
99
138
/// Optionally accepts a callback that gets called after the component updates.
100
139
///
101
- /// [A.k.a "forceUpdate"] (https://facebook.github.io/react/docs/component-api .html#forceupdate)
140
+ /// [A.k.a "forceUpdate"] (https://facebook.github.io/react/docs/react-component .html#forceupdate)
102
141
void redraw ([callback ()]) {
103
142
setState ({}, callback);
104
143
}
@@ -109,7 +148,7 @@ abstract class Component {
109
148
///
110
149
/// Also allows [newState] to be used as a transactional `setState` callback.
111
150
///
112
- /// See: <https://facebook.github.io/react/docs/component-api .html#setstate>
151
+ /// See: <https://facebook.github.io/react/docs/react-component .html#setstate>
113
152
void setState (dynamic newState, [callback ()]) {
114
153
if (newState is Map ) {
115
154
_nextState.addAll (newState);
@@ -128,7 +167,7 @@ abstract class Component {
128
167
///
129
168
/// Optionally accepts a callback that gets called after the component updates.
130
169
///
131
- /// See: <https://facebook.github.io/react/docs/component-api .html#replacestate >
170
+ /// See: <https://facebook.github.io/react/docs/react-component .html#setstate >
132
171
void replaceState (Map newState, [callback ()]) {
133
172
Map nextState = newState == null ? {} : new Map .from (newState);
134
173
_nextState = nextState;
@@ -143,7 +182,7 @@ abstract class Component {
143
182
/// If you call [setState] within this method, [render] will see the updated state and will be executed only once
144
183
/// despite the [state] value change.
145
184
///
146
- /// See: <https://facebook.github.io/react/docs/component-specs .html#mounting-componentwillmount>
185
+ /// See: <https://facebook.github.io/react/docs/react-component .html#mounting-componentwillmount>
147
186
void componentWillMount () {}
148
187
149
188
/// ReactJS lifecycle method that is invoked once, only on the client _(not on the server)_, immediately after the
@@ -153,7 +192,7 @@ abstract class Component {
153
192
///
154
193
/// The [componentDidMount] method of child `Component` s is invoked _before_ that of parent `Component` .
155
194
///
156
- /// See: <https://facebook.github.io/react/docs/component-specs .html#mounting-componentdidmount>
195
+ /// See: <https://facebook.github.io/react/docs/react-component .html#mounting-componentdidmount>
157
196
void componentDidMount () {}
158
197
159
198
/// ReactJS lifecycle method that is invoked when a `Component` is receiving [newProps] .
@@ -165,16 +204,16 @@ abstract class Component {
165
204
///
166
205
/// Calling [setState] within this function will not trigger an additional [render] .
167
206
///
168
- /// See: <https://facebook.github.io/react/docs/component-specs .html#updating-componentwillreceiveprops>
169
- void componentWillReceiveProps (newProps) {}
207
+ /// See: <https://facebook.github.io/react/docs/react-component .html#updating-componentwillreceiveprops>
208
+ void componentWillReceiveProps (Map newProps) {}
170
209
171
210
/// ReactJS lifecycle method that is invoked before rendering when [nextProps] or [nextState] are being received.
172
211
///
173
212
/// Use this as an opportunity to return false when you're certain that the transition to the new props and state
174
213
/// will not require a component update.
175
214
///
176
- /// See: <https://facebook.github.io/react/docs/component-specs .html#updating-shouldcomponentupdate>
177
- bool shouldComponentUpdate (nextProps, nextState) => true ;
215
+ /// See: <https://facebook.github.io/react/docs/react-component .html#updating-shouldcomponentupdate>
216
+ bool shouldComponentUpdate (Map nextProps, Map nextState) => true ;
178
217
179
218
/// ReactJS lifecycle method that is invoked immediately before rendering when [nextProps] or [nextState] are being
180
219
/// received.
@@ -183,8 +222,8 @@ abstract class Component {
183
222
///
184
223
/// Use this as an opportunity to perform preparation before an update occurs.
185
224
///
186
- /// See: <https://facebook.github.io/react/docs/component-specs .html#updating-componentwillupdate>
187
- void componentWillUpdate (nextProps, nextState) {}
225
+ /// See: <https://facebook.github.io/react/docs/react-component .html#updating-componentwillupdate>
226
+ void componentWillUpdate (Map nextProps, Map nextState) {}
188
227
189
228
/// ReactJS lifecycle method that is invoked immediately after the `Component` 's updates are flushed to the DOM.
190
229
///
@@ -193,20 +232,20 @@ abstract class Component {
193
232
/// Use this as an opportunity to operate on the [rootNode] (DOM) when the `Component` has been updated as a result
194
233
/// of the values of [prevProps] / [prevState] .
195
234
///
196
- /// See: <https://facebook.github.io/react/docs/component-specs .html#updating-componentdidupdate>
197
- void componentDidUpdate (prevProps, prevState) {}
235
+ /// See: <https://facebook.github.io/react/docs/react-component .html#updating-componentdidupdate>
236
+ void componentDidUpdate (Map prevProps, Map prevState) {}
198
237
199
238
/// ReactJS lifecycle method that is invoked immediately before a `Component` is unmounted from the DOM.
200
239
///
201
240
/// Perform any necessary cleanup in this method, such as invalidating timers or cleaning up any DOM [Element] s that
202
241
/// were created in [componentDidMount] .
203
242
///
204
- /// See: <https://facebook.github.io/react/docs/component-specs .html#unmounting-componentwillunmount>
243
+ /// See: <https://facebook.github.io/react/docs/react-component .html#unmounting-componentwillunmount>
205
244
void componentWillUnmount () {}
206
245
207
246
/// Invoked once before the `Component` is mounted. The return value will be used as the initial value of [state] .
208
247
///
209
- /// See: <https://facebook.github.io/react/docs/component-specs .html#getinitialstate>
248
+ /// See: <https://facebook.github.io/react/docs/react-component .html#getinitialstate>
210
249
Map getInitialState () => {};
211
250
212
251
/// Invoked once and cached when [reactComponentClass] is called. Values in the mapping will be set on [props]
@@ -215,7 +254,7 @@ abstract class Component {
215
254
/// This method is invoked before any instances are created and thus cannot rely on [props] . In addition, be aware
216
255
/// that any complex objects returned by `getDefaultProps` will be shared across instances, not copied.
217
256
///
218
- /// See: <https://facebook.github.io/react/docs/component-specs .html#getdefaultprops>
257
+ /// See: <https://facebook.github.io/react/docs/react-component .html#getdefaultprops>
219
258
Map getDefaultProps () => {};
220
259
221
260
/// __Required.__
@@ -224,13 +263,13 @@ abstract class Component {
224
263
/// be either a virtual representation of a native DOM component (such as [DivElement] ) or another composite
225
264
/// `Component` that you've defined yourself.
226
265
///
227
- /// See: <https://facebook.github.io/react/docs/component-specs .html#render>
266
+ /// See: <https://facebook.github.io/react/docs/react-component .html#render>
228
267
dynamic render ();
229
268
}
230
269
231
270
/// Typedef of a transactional [Component.setState] callback.
232
271
///
233
- /// See: <https://facebook.github.io/react/docs/component-api .html#setstate>
272
+ /// See: <https://facebook.github.io/react/docs/react-component .html#setstate>
234
273
typedef Map _TransactionalSetStateCallback (Map prevState, Map props);
235
274
236
275
0 commit comments