Jonatas

add benchmarks from value notifier vs get value

@@ -5,7 +5,6 @@ export 'src/extension_navigation.dart'; @@ -5,7 +5,6 @@ export 'src/extension_navigation.dart';
5 export 'src/root/root_widget.dart'; 5 export 'src/root/root_widget.dart';
6 export 'src/routes/custom_transition.dart'; 6 export 'src/routes/custom_transition.dart';
7 export 'src/routes/default_route.dart'; 7 export 'src/routes/default_route.dart';
8 -export 'src/routes/default_route.dart';  
9 export 'src/routes/get_route.dart'; 8 export 'src/routes/get_route.dart';
10 export 'src/routes/observers/route_observer.dart'; 9 export 'src/routes/observers/route_observer.dart';
11 export 'src/routes/transitions_type.dart'; 10 export 'src/routes/transitions_type.dart';
@@ -4,22 +4,21 @@ import '../../../get_rx/get_rx.dart'; @@ -4,22 +4,21 @@ import '../../../get_rx/get_rx.dart';
4 4
5 typedef WidgetCallback = Widget Function(); 5 typedef WidgetCallback = Widget Function();
6 6
7 -/// The simplest reactive widget in GetX.  
8 -///  
9 -/// Just pass your Rx variable in the root scope of the callback to have it  
10 -/// automatically registered for changes. 7 +/// The [ObxWidget] is the base for all GetX reactive widgets
11 /// 8 ///
12 -/// final _name = "GetX".obs;  
13 -/// Obx(() => Text( _name.value )),... ;  
14 -class Obx extends StatefulWidget {  
15 - final WidgetCallback builder;  
16 -  
17 - const Obx(this.builder); 9 +/// See also:
  10 +/// - [Obx]
  11 +/// - [ObxValue]
  12 +abstract class ObxWidget extends StatefulWidget {
  13 + const ObxWidget({Key key}) : super(key: key);
18 14
19 _ObxState createState() => _ObxState(); 15 _ObxState createState() => _ObxState();
  16 +
  17 + @protected
  18 + Widget build();
20 } 19 }
21 20
22 -class _ObxState extends State<Obx> { 21 +class _ObxState extends State<ObxWidget> {
23 RxInterface _observer; 22 RxInterface _observer;
24 StreamSubscription subs; 23 StreamSubscription subs;
25 24
@@ -43,7 +42,7 @@ class _ObxState extends State<Obx> { @@ -43,7 +42,7 @@ class _ObxState extends State<Obx> {
43 Widget get notifyChilds { 42 Widget get notifyChilds {
44 final observer = getObs; 43 final observer = getObs;
45 getObs = _observer; 44 getObs = _observer;
46 - final result = widget.builder(); 45 + final result = widget.build();
47 if (!_observer.canUpdate) { 46 if (!_observer.canUpdate) {
48 throw """ 47 throw """
49 [Get] the improper use of a GetX has been detected. 48 [Get] the improper use of a GetX has been detected.
@@ -62,6 +61,22 @@ class _ObxState extends State<Obx> { @@ -62,6 +61,22 @@ class _ObxState extends State<Obx> {
62 Widget build(BuildContext context) => notifyChilds; 61 Widget build(BuildContext context) => notifyChilds;
63 } 62 }
64 63
  64 +/// The simplest reactive widget in GetX.
  65 +///
  66 +/// Just pass your Rx variable in the root scope of the callback to have it
  67 +/// automatically registered for changes.
  68 +///
  69 +/// final _name = "GetX".obs;
  70 +/// Obx(() => Text( _name.value )),... ;
  71 +class Obx extends ObxWidget {
  72 + final WidgetCallback builder;
  73 +
  74 + const Obx(this.builder);
  75 +
  76 + @override
  77 + Widget build() => builder();
  78 +}
  79 +
65 /// Similar to Obx, but manages a local state. 80 /// Similar to Obx, but manages a local state.
66 /// Pass the initial data in constructor. 81 /// Pass the initial data in constructor.
67 /// Useful for simple local states, like toggles, visibility, themes, 82 /// Useful for simple local states, like toggles, visibility, themes,
@@ -76,45 +91,12 @@ class _ObxState extends State<Obx> { @@ -76,45 +91,12 @@ class _ObxState extends State<Obx> {
76 91
77 // TODO: change T to a proper Rx interface, that includes the accessor 92 // TODO: change T to a proper Rx interface, that includes the accessor
78 // for ::value 93 // for ::value
79 -class ObxValue<T extends RxInterface> extends StatefulWidget { 94 +class ObxValue<T extends RxInterface> extends ObxWidget {
80 final Widget Function(T) builder; 95 final Widget Function(T) builder;
81 final T data; 96 final T data;
82 97
83 const ObxValue(this.builder, this.data, {Key key}) : super(key: key); 98 const ObxValue(this.builder, this.data, {Key key}) : super(key: key);
84 99
85 - _ObxValueState createState() => _ObxValueState();  
86 -}  
87 -  
88 -class _ObxValueState extends State<ObxValue> {  
89 - RxInterface _observer;  
90 - StreamSubscription subs;  
91 -  
92 - _ObxValueState() {  
93 - _observer = Rx();  
94 - }  
95 -  
96 - @override  
97 - void initState() {  
98 - subs = _observer.subject.stream.listen((data) => setState(() {}));  
99 - super.initState();  
100 - }  
101 -  
102 - @override  
103 - void dispose() {  
104 - subs.cancel();  
105 - _observer.close();  
106 - super.dispose();  
107 - }  
108 -  
109 - Widget get notifyChilds {  
110 - final observer = getObs;  
111 - getObs = _observer;  
112 - // observable is implicity taken from the constructor.  
113 - final result = widget.builder(widget.data);  
114 - getObs = observer;  
115 - return result;  
116 - }  
117 -  
118 @override 100 @override
119 - Widget build(BuildContext context) => notifyChilds; 101 + Widget build() => builder(data);
120 } 102 }
@@ -204,7 +204,7 @@ class GetUtils { @@ -204,7 +204,7 @@ class GetUtils {
204 204
205 /// Checks if string is phone number. 205 /// Checks if string is phone number.
206 static bool isPhoneNumber(String s) => hasMatch(s, 206 static bool isPhoneNumber(String s) => hasMatch(s,
207 - r'^(0|\+|(\+[0-9]{2,4}|\(\+?[0-9]{2,4}\)) ?)([0-9]*|\d{2,4}-\d{2,4}(-\d{2,4})?)$'); 207 + r'^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$');
208 208
209 /// Checks if string is DateTime (UTC or Iso8601). 209 /// Checks if string is DateTime (UTC or Iso8601).
210 static bool isDateTime(String s) => 210 static bool isDateTime(String s) =>
@@ -239,14 +239,12 @@ void main() { @@ -239,14 +239,12 @@ void main() {
239 '(455) 443-8171', 239 '(455) 443-8171',
240 '(915) 685-8658', 240 '(915) 685-8658',
241 '(572) 207-1898', 241 '(572) 207-1898',
242 -  
243 - // TODO those are failing, but they shouldn't  
244 - // '(81) 6 2499-9538',  
245 - // '(31) 32304-4263',  
246 - // '(64) 25242-6375',  
247 - // '(41) 19308-7925',  
248 - // '(67) 61684-0395',  
249 - // '(60) 54706-3569', 242 + '(81) 6 2499-9538',
  243 + '(31) 32304-4263',
  244 + '(64) 25242-6375',
  245 + '(41) 19308-7925',
  246 + '(67) 61684-0395',
  247 + '(60) 54706-3569',
250 '(31) 33110055', 248 '(31) 33110055',
251 '(11) 3344-5599', 249 '(11) 3344-5599',
252 '(31) 977447788', 250 '(31) 977447788',