Skip to content

Commit

Permalink
Bump version to 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jonataslaw authored Jul 1, 2020
1 parent 221b439 commit 6063810
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 28 deletions.
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
## [3.2.0]
- Improve GetBuilder ram usage
- Added method update to Rx
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:
```dart
class User{
User(this.name = '', this.age = 0);
String name;
int age;
}
final user = User().obs;
Obx(()=> Text("Name ${user.value.name}: Age: ${user.value.age}"))
// To update:
user.update((user){
user.name = 'Jonny';
user.age = 18;
});
```

Now is also possible to access a value without using the ".value". Just open and close parentheses.
In the previous example, you could do:
```dart
user().name; // before: user.value.name
```
And it is also possible to set a value without using the value, inserting the value directly into the variable.
```dart
user(User('João', 35)); // before: user.value = User('João', 35)
```
Added fenix mode to Get.lazyPut.


## [3.1.4]
- Update readme banner

Expand Down
19 changes: 8 additions & 11 deletions lib/src/get_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,15 @@ class GetImpl implements GetService {
Bindings binding,
preventDuplicates = true,
bool popGesture}) {
if (preventDuplicates &&
'/' + page.toString().toLowerCase() == currentRoute) {
if (preventDuplicates && '/${page.runtimeType}' == currentRoute) {
return null;
}

return global(id).currentState.push(GetPageRoute(
opaque: opaque ?? true,
page: () => page,
settings: RouteSettings(
name: '/' + page.toString().toLowerCase(), arguments: arguments),
settings:
RouteSettings(name: '/${page.runtimeType}', arguments: arguments),
popGesture: popGesture ?? defaultPopGesture,
transition: transition ?? defaultTransition,
fullscreenDialog: fullscreenDialog,
Expand Down Expand Up @@ -183,16 +182,15 @@ class GetImpl implements GetService {
bool fullscreenDialog = false,
preventDuplicates = true,
Duration duration}) {
if (preventDuplicates &&
'/' + page.toString().toLowerCase() == currentRoute) {
if (preventDuplicates && '/${page.runtimeType}' == currentRoute) {
return null;
}
return global(id).currentState.pushReplacement(GetPageRoute(
opaque: opaque ?? true,
page: () => page,
binding: binding,
settings: RouteSettings(
name: '/' + page.toString().toLowerCase(), arguments: arguments),
settings:
RouteSettings(name: '/${page.runtimeType}', arguments: arguments),
fullscreenDialog: fullscreenDialog,
popGesture: popGesture ?? defaultPopGesture,
transition: transition ?? defaultTransition,
Expand All @@ -218,9 +216,8 @@ class GetImpl implements GetService {
popGesture: popGesture ?? defaultPopGesture,
page: () => page,
binding: binding,
settings: RouteSettings(
name: '/' + page.runtimeType.toString().toLowerCase(),
arguments: arguments),
settings:
RouteSettings(name: '/${page.runtimeType}', arguments: arguments),
fullscreenDialog: fullscreenDialog,
transition: transition ?? defaultTransition,
duration: duration ?? defaultDurationTransition,
Expand Down
19 changes: 14 additions & 5 deletions lib/src/instance/get_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import 'package:get/src/typedefs/typedefs.dart';
class GetConfig {
//////////// INSTANCE MANAGER
static Map<dynamic, dynamic> _singl = {};
static Map<dynamic, FcBuilderFunc> _factory = {};
static Map<dynamic, Lazy> _factory = {};
static Map<String, String> routesKey = {};
static SmartManagement smartManagement = SmartManagement.full;
static bool isLogEnable = true;
static String currentRoute;
}

class Lazy {
Lazy(this.builder, this.fenix);
bool fenix;
FcBuilderFunc builder;
}

class GetInstance {
factory GetInstance() {
if (_getInstance == null) _getInstance = GetInstance._();
Expand All @@ -20,9 +26,10 @@ class GetInstance {
GetInstance._();
static GetInstance _getInstance;

void lazyPut<S>(FcBuilderFunc builder, {String tag}) {
void lazyPut<S>(FcBuilderFunc builder, {String tag, bool fenix = false}) {
String key = _getKey(S, tag);
GetConfig._factory.putIfAbsent(key, () => builder);

GetConfig._factory.putIfAbsent(key, () => Lazy(builder, fenix));
}

Future<S> putAsync<S>(FcBuilderFuncAsync<S> builder,
Expand Down Expand Up @@ -154,7 +161,7 @@ class GetInstance {

if (GetConfig.isLogEnable)
print('[GET] $S instance was created at that time');
S _value = put<S>(GetConfig._factory[key].call() as S);
S _value = put<S>(GetConfig._factory[key].builder() as S);

if (!isDependencyInit<S>() &&
GetConfig.smartManagement != SmartManagement.onlyBuilder) {
Expand All @@ -163,7 +170,9 @@ class GetInstance {
}

if (GetConfig.smartManagement != SmartManagement.keepFactory) {
GetConfig._factory.remove(key);
if (!GetConfig._factory[key].fenix) {
GetConfig._factory.remove(key);
}
}

if (callInit) {
Expand Down
23 changes: 21 additions & 2 deletions lib/src/rx/rx_impl.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:async';
import 'dart:collection';
import 'rx_interface.dart';

class _RxImpl<T> implements RxInterface<T> {
StreamController<T> subject = StreamController<T>.broadcast();
Map<Stream<T>, StreamSubscription> _subscriptions = Map();
HashMap<Stream<T>, StreamSubscription> _subscriptions =
HashMap<Stream<T>, StreamSubscription>();

T _value;
T get value {
Expand All @@ -13,6 +15,18 @@ class _RxImpl<T> implements RxInterface<T> {
return _value;
}

T call([T v]) {
if (v != null) {
this.value = v;
}
return this.value;
}

void update(void fn(T value)) {
fn(value);
subject.add(value);
}

String get string => value.toString();

close() {
Expand Down Expand Up @@ -354,6 +368,11 @@ class RxList<E> extends Iterable<E> implements RxInterface<E> {
add(item);
}

void update(void fn(Iterable<E> value)) {
fn(value);
subject.add(null);
}

/// Replaces all existing items of this list with [items]
void assignAll(Iterable<E> items) {
clear();
Expand Down Expand Up @@ -473,5 +492,5 @@ extension ListExtension<E> on List<E> {
}

extension RxT<T> on T {
Rx<T> get obs => Rx(this);
Rx<T> get obs => Rx<T>(this);
}
20 changes: 11 additions & 9 deletions lib/src/state/get_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import 'package:get/src/root/smart_management.dart';
import 'package:get/src/rx/rx_interface.dart';

class GetxController extends DisposableInterface {
final HashSet<Updater> _updaters = HashSet<Updater>();
final HashSet<UpdaterBuilder> _updaters = HashSet<UpdaterBuilder>();

/// Update GetBuilder with update();
void update([List<String> ids, bool condition = true]) {
if (!condition) return;
(ids == null)
? _updaters.forEach((rs) {
rs.updater(() {});
rs().updater(() {});
})
: _updaters
.where((element) => ids.contains(element.id))
.forEach((rs) => rs.updater(() {}));
.where((element) => ids.contains(element().id))
.forEach((rs) => rs().updater(() {}));
}

@override
Expand Down Expand Up @@ -60,7 +60,7 @@ class GetBuilder<T extends GetxController> extends StatefulWidget {

class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> {
T controller;
Updater real;
UpdaterBuilder real;
bool isCreator = false;
@override
void initState() {
Expand All @@ -75,24 +75,24 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> {
isCreator = true;
}
controller = GetInstance().find<T>(tag: widget.tag);
real = Updater(updater: setState, id: widget.id);
real = () => Updater(updater: setState, id: widget.id);
controller._updaters.add(real);
} else if (isRegistred) {
controller = GetInstance().find<T>(tag: widget.tag);
isCreator = false;
real = Updater(updater: setState, id: widget.id);
real = () => Updater(updater: setState, id: widget.id);
controller._updaters.add(real);
} else {
controller = widget.init;
isCreator = true;
real = Updater(updater: setState, id: widget.id);
real = () => Updater(updater: setState, id: widget.id);
controller._updaters.add(real);
GetInstance().put<T>(controller, tag: widget.tag);
}
} else {
controller = widget.init;
isCreator = true;
real = Updater(updater: setState, id: widget.id);
real = () => Updater(updater: setState, id: widget.id);
controller._updaters.add(real);
controller?.onStart();
}
Expand Down Expand Up @@ -141,3 +141,5 @@ class Updater {
final String id;
const Updater({this.updater, this.id});
}

typedef UpdaterBuilder = Updater Function();
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: get
description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
version: 3.1.4
version: 3.2.0
homepage: https://github.com/jonataslaw/get

environment:
Expand Down

0 comments on commit 6063810

Please sign in to comment.