Jonny Borges
Committed by GitHub

Bump version to 3.2

  1 +## [3.2.0]
  2 +- Improve GetBuilder ram usage
  3 +- Added method update to Rx
  4 +Now you no longer need to make an entire class reactive to get an element update from it, you can simply call the update method of its instance, like this:
  5 +```dart
  6 +class User{
  7 + User(this.name = '', this.age = 0);
  8 + String name;
  9 + int age;
  10 +}
  11 +
  12 +final user = User().obs;
  13 +
  14 +Obx(()=> Text("Name ${user.value.name}: Age: ${user.value.age}"))
  15 +
  16 +// To update:
  17 +user.update((user){
  18 +user.name = 'Jonny';
  19 +user.age = 18;
  20 +});
  21 +```
  22 +
  23 +Now is also possible to access a value without using the ".value". Just open and close parentheses.
  24 +In the previous example, you could do:
  25 +```dart
  26 +user().name; // before: user.value.name
  27 +```
  28 +And it is also possible to set a value without using the value, inserting the value directly into the variable.
  29 +```dart
  30 +user(User('João', 35)); // before: user.value = User('João', 35)
  31 +```
  32 +Added fenix mode to Get.lazyPut.
  33 +
  34 +
1 ## [3.1.4] 35 ## [3.1.4]
2 - Update readme banner 36 - Update readme banner
3 37
@@ -48,16 +48,15 @@ class GetImpl implements GetService { @@ -48,16 +48,15 @@ class GetImpl implements GetService {
48 Bindings binding, 48 Bindings binding,
49 preventDuplicates = true, 49 preventDuplicates = true,
50 bool popGesture}) { 50 bool popGesture}) {
51 - if (preventDuplicates &&  
52 - '/' + page.toString().toLowerCase() == currentRoute) { 51 + if (preventDuplicates && '/${page.runtimeType}' == currentRoute) {
53 return null; 52 return null;
54 } 53 }
55 54
56 return global(id).currentState.push(GetPageRoute( 55 return global(id).currentState.push(GetPageRoute(
57 opaque: opaque ?? true, 56 opaque: opaque ?? true,
58 page: () => page, 57 page: () => page,
59 - settings: RouteSettings(  
60 - name: '/' + page.toString().toLowerCase(), arguments: arguments), 58 + settings:
  59 + RouteSettings(name: '/${page.runtimeType}', arguments: arguments),
61 popGesture: popGesture ?? defaultPopGesture, 60 popGesture: popGesture ?? defaultPopGesture,
62 transition: transition ?? defaultTransition, 61 transition: transition ?? defaultTransition,
63 fullscreenDialog: fullscreenDialog, 62 fullscreenDialog: fullscreenDialog,
@@ -183,16 +182,15 @@ class GetImpl implements GetService { @@ -183,16 +182,15 @@ class GetImpl implements GetService {
183 bool fullscreenDialog = false, 182 bool fullscreenDialog = false,
184 preventDuplicates = true, 183 preventDuplicates = true,
185 Duration duration}) { 184 Duration duration}) {
186 - if (preventDuplicates &&  
187 - '/' + page.toString().toLowerCase() == currentRoute) { 185 + if (preventDuplicates && '/${page.runtimeType}' == currentRoute) {
188 return null; 186 return null;
189 } 187 }
190 return global(id).currentState.pushReplacement(GetPageRoute( 188 return global(id).currentState.pushReplacement(GetPageRoute(
191 opaque: opaque ?? true, 189 opaque: opaque ?? true,
192 page: () => page, 190 page: () => page,
193 binding: binding, 191 binding: binding,
194 - settings: RouteSettings(  
195 - name: '/' + page.toString().toLowerCase(), arguments: arguments), 192 + settings:
  193 + RouteSettings(name: '/${page.runtimeType}', arguments: arguments),
196 fullscreenDialog: fullscreenDialog, 194 fullscreenDialog: fullscreenDialog,
197 popGesture: popGesture ?? defaultPopGesture, 195 popGesture: popGesture ?? defaultPopGesture,
198 transition: transition ?? defaultTransition, 196 transition: transition ?? defaultTransition,
@@ -218,9 +216,8 @@ class GetImpl implements GetService { @@ -218,9 +216,8 @@ class GetImpl implements GetService {
218 popGesture: popGesture ?? defaultPopGesture, 216 popGesture: popGesture ?? defaultPopGesture,
219 page: () => page, 217 page: () => page,
220 binding: binding, 218 binding: binding,
221 - settings: RouteSettings(  
222 - name: '/' + page.runtimeType.toString().toLowerCase(),  
223 - arguments: arguments), 219 + settings:
  220 + RouteSettings(name: '/${page.runtimeType}', arguments: arguments),
224 fullscreenDialog: fullscreenDialog, 221 fullscreenDialog: fullscreenDialog,
225 transition: transition ?? defaultTransition, 222 transition: transition ?? defaultTransition,
226 duration: duration ?? defaultDurationTransition, 223 duration: duration ?? defaultDurationTransition,
@@ -5,13 +5,19 @@ import 'package:get/src/typedefs/typedefs.dart'; @@ -5,13 +5,19 @@ import 'package:get/src/typedefs/typedefs.dart';
5 class GetConfig { 5 class GetConfig {
6 //////////// INSTANCE MANAGER 6 //////////// INSTANCE MANAGER
7 static Map<dynamic, dynamic> _singl = {}; 7 static Map<dynamic, dynamic> _singl = {};
8 - static Map<dynamic, FcBuilderFunc> _factory = {}; 8 + static Map<dynamic, Lazy> _factory = {};
9 static Map<String, String> routesKey = {}; 9 static Map<String, String> routesKey = {};
10 static SmartManagement smartManagement = SmartManagement.full; 10 static SmartManagement smartManagement = SmartManagement.full;
11 static bool isLogEnable = true; 11 static bool isLogEnable = true;
12 static String currentRoute; 12 static String currentRoute;
13 } 13 }
14 14
  15 +class Lazy {
  16 + Lazy(this.builder, this.fenix);
  17 + bool fenix;
  18 + FcBuilderFunc builder;
  19 +}
  20 +
15 class GetInstance { 21 class GetInstance {
16 factory GetInstance() { 22 factory GetInstance() {
17 if (_getInstance == null) _getInstance = GetInstance._(); 23 if (_getInstance == null) _getInstance = GetInstance._();
@@ -20,9 +26,10 @@ class GetInstance { @@ -20,9 +26,10 @@ class GetInstance {
20 GetInstance._(); 26 GetInstance._();
21 static GetInstance _getInstance; 27 static GetInstance _getInstance;
22 28
23 - void lazyPut<S>(FcBuilderFunc builder, {String tag}) { 29 + void lazyPut<S>(FcBuilderFunc builder, {String tag, bool fenix = false}) {
24 String key = _getKey(S, tag); 30 String key = _getKey(S, tag);
25 - GetConfig._factory.putIfAbsent(key, () => builder); 31 +
  32 + GetConfig._factory.putIfAbsent(key, () => Lazy(builder, fenix));
26 } 33 }
27 34
28 Future<S> putAsync<S>(FcBuilderFuncAsync<S> builder, 35 Future<S> putAsync<S>(FcBuilderFuncAsync<S> builder,
@@ -154,7 +161,7 @@ class GetInstance { @@ -154,7 +161,7 @@ class GetInstance {
154 161
155 if (GetConfig.isLogEnable) 162 if (GetConfig.isLogEnable)
156 print('[GET] $S instance was created at that time'); 163 print('[GET] $S instance was created at that time');
157 - S _value = put<S>(GetConfig._factory[key].call() as S); 164 + S _value = put<S>(GetConfig._factory[key].builder() as S);
158 165
159 if (!isDependencyInit<S>() && 166 if (!isDependencyInit<S>() &&
160 GetConfig.smartManagement != SmartManagement.onlyBuilder) { 167 GetConfig.smartManagement != SmartManagement.onlyBuilder) {
@@ -163,8 +170,10 @@ class GetInstance { @@ -163,8 +170,10 @@ class GetInstance {
163 } 170 }
164 171
165 if (GetConfig.smartManagement != SmartManagement.keepFactory) { 172 if (GetConfig.smartManagement != SmartManagement.keepFactory) {
  173 + if (!GetConfig._factory[key].fenix) {
166 GetConfig._factory.remove(key); 174 GetConfig._factory.remove(key);
167 } 175 }
  176 + }
168 177
169 if (callInit) { 178 if (callInit) {
170 initController<S>(tag: tag); 179 initController<S>(tag: tag);
1 import 'dart:async'; 1 import 'dart:async';
  2 +import 'dart:collection';
2 import 'rx_interface.dart'; 3 import 'rx_interface.dart';
3 4
4 class _RxImpl<T> implements RxInterface<T> { 5 class _RxImpl<T> implements RxInterface<T> {
5 StreamController<T> subject = StreamController<T>.broadcast(); 6 StreamController<T> subject = StreamController<T>.broadcast();
6 - Map<Stream<T>, StreamSubscription> _subscriptions = Map(); 7 + HashMap<Stream<T>, StreamSubscription> _subscriptions =
  8 + HashMap<Stream<T>, StreamSubscription>();
7 9
8 T _value; 10 T _value;
9 T get value { 11 T get value {
@@ -13,6 +15,18 @@ class _RxImpl<T> implements RxInterface<T> { @@ -13,6 +15,18 @@ class _RxImpl<T> implements RxInterface<T> {
13 return _value; 15 return _value;
14 } 16 }
15 17
  18 + T call([T v]) {
  19 + if (v != null) {
  20 + this.value = v;
  21 + }
  22 + return this.value;
  23 + }
  24 +
  25 + void update(void fn(T value)) {
  26 + fn(value);
  27 + subject.add(value);
  28 + }
  29 +
16 String get string => value.toString(); 30 String get string => value.toString();
17 31
18 close() { 32 close() {
@@ -354,6 +368,11 @@ class RxList<E> extends Iterable<E> implements RxInterface<E> { @@ -354,6 +368,11 @@ class RxList<E> extends Iterable<E> implements RxInterface<E> {
354 add(item); 368 add(item);
355 } 369 }
356 370
  371 + void update(void fn(Iterable<E> value)) {
  372 + fn(value);
  373 + subject.add(null);
  374 + }
  375 +
357 /// Replaces all existing items of this list with [items] 376 /// Replaces all existing items of this list with [items]
358 void assignAll(Iterable<E> items) { 377 void assignAll(Iterable<E> items) {
359 clear(); 378 clear();
@@ -473,5 +492,5 @@ extension ListExtension<E> on List<E> { @@ -473,5 +492,5 @@ extension ListExtension<E> on List<E> {
473 } 492 }
474 493
475 extension RxT<T> on T { 494 extension RxT<T> on T {
476 - Rx<T> get obs => Rx(this); 495 + Rx<T> get obs => Rx<T>(this);
477 } 496 }
@@ -5,18 +5,18 @@ import 'package:get/src/root/smart_management.dart'; @@ -5,18 +5,18 @@ import 'package:get/src/root/smart_management.dart';
5 import 'package:get/src/rx/rx_interface.dart'; 5 import 'package:get/src/rx/rx_interface.dart';
6 6
7 class GetxController extends DisposableInterface { 7 class GetxController extends DisposableInterface {
8 - final HashSet<Updater> _updaters = HashSet<Updater>(); 8 + final HashSet<UpdaterBuilder> _updaters = HashSet<UpdaterBuilder>();
9 9
10 /// Update GetBuilder with update(); 10 /// Update GetBuilder with update();
11 void update([List<String> ids, bool condition = true]) { 11 void update([List<String> ids, bool condition = true]) {
12 if (!condition) return; 12 if (!condition) return;
13 (ids == null) 13 (ids == null)
14 ? _updaters.forEach((rs) { 14 ? _updaters.forEach((rs) {
15 - rs.updater(() {}); 15 + rs().updater(() {});
16 }) 16 })
17 : _updaters 17 : _updaters
18 - .where((element) => ids.contains(element.id))  
19 - .forEach((rs) => rs.updater(() {})); 18 + .where((element) => ids.contains(element().id))
  19 + .forEach((rs) => rs().updater(() {}));
20 } 20 }
21 21
22 @override 22 @override
@@ -60,7 +60,7 @@ class GetBuilder<T extends GetxController> extends StatefulWidget { @@ -60,7 +60,7 @@ class GetBuilder<T extends GetxController> extends StatefulWidget {
60 60
61 class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { 61 class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> {
62 T controller; 62 T controller;
63 - Updater real; 63 + UpdaterBuilder real;
64 bool isCreator = false; 64 bool isCreator = false;
65 @override 65 @override
66 void initState() { 66 void initState() {
@@ -75,24 +75,24 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { @@ -75,24 +75,24 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> {
75 isCreator = true; 75 isCreator = true;
76 } 76 }
77 controller = GetInstance().find<T>(tag: widget.tag); 77 controller = GetInstance().find<T>(tag: widget.tag);
78 - real = Updater(updater: setState, id: widget.id); 78 + real = () => Updater(updater: setState, id: widget.id);
79 controller._updaters.add(real); 79 controller._updaters.add(real);
80 } else if (isRegistred) { 80 } else if (isRegistred) {
81 controller = GetInstance().find<T>(tag: widget.tag); 81 controller = GetInstance().find<T>(tag: widget.tag);
82 isCreator = false; 82 isCreator = false;
83 - real = Updater(updater: setState, id: widget.id); 83 + real = () => Updater(updater: setState, id: widget.id);
84 controller._updaters.add(real); 84 controller._updaters.add(real);
85 } else { 85 } else {
86 controller = widget.init; 86 controller = widget.init;
87 isCreator = true; 87 isCreator = true;
88 - real = Updater(updater: setState, id: widget.id); 88 + real = () => Updater(updater: setState, id: widget.id);
89 controller._updaters.add(real); 89 controller._updaters.add(real);
90 GetInstance().put<T>(controller, tag: widget.tag); 90 GetInstance().put<T>(controller, tag: widget.tag);
91 } 91 }
92 } else { 92 } else {
93 controller = widget.init; 93 controller = widget.init;
94 isCreator = true; 94 isCreator = true;
95 - real = Updater(updater: setState, id: widget.id); 95 + real = () => Updater(updater: setState, id: widget.id);
96 controller._updaters.add(real); 96 controller._updaters.add(real);
97 controller?.onStart(); 97 controller?.onStart();
98 } 98 }
@@ -141,3 +141,5 @@ class Updater { @@ -141,3 +141,5 @@ class Updater {
141 final String id; 141 final String id;
142 const Updater({this.updater, this.id}); 142 const Updater({this.updater, this.id});
143 } 143 }
  144 +
  145 +typedef UpdaterBuilder = Updater Function();
1 name: get 1 name: get
2 description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get. 2 description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
3 -version: 3.1.4 3 +version: 3.2.0
4 homepage: https://github.com/jonataslaw/get 4 homepage: https://github.com/jonataslaw/get
5 5
6 environment: 6 environment: