Skip to content

Commit

Permalink
Bump to 2.11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jonataslaw authored Jun 7, 2020
1 parent ca5a32c commit 53ac3ce
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 274 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.11.2]
- Added docs
- Improvement performance of Obx

## [2.11.1]
- Fixed: oninit calling only once.

Expand Down
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ Obviously, if someone wants to contribute to the project and create a code gener
Typing in Get using Bindings is unnecessary. you can use the Obx widget instead of GetX which only receives the anonymous function that creates a widget.
Obviously, if you don't use a type, you will need to have an instance of your controller to use the variables, or use `Get.find<Controller>()` .value or Controller.to.value to retrieve the value.

### GetX vs GetBuilder vs Obx MixinBuilder
### GetX vs GetBuilder vs Obx vs MixinBuilder
In a decade working with programming I was able to learn some valuable lessons.
My first contact with reactive programming was so "wow, this is incredible" and in fact reactive programming is incredible.
However, it is not suitable for all situations. Often all you need is to change the state of 2 or 3 widgets at the same time, or an ephemeral change of state, in which case reactive programming is not bad, but it is not appropriate.
Expand Down Expand Up @@ -764,6 +764,23 @@ Get.to(Home(), binding: HomeBinding());

There, you don't have to worry about memory management of your application anymore, Get will do it for you.

The Binding class is called when a route is called, you can create an "initialBinding in your GetMaterialApp to insert all the dependencies that will be created.
```dart
GetMaterialApp(
initialBinding: SampleBind(),
home: Home();
);
```

If you want to use your initializations in one place, you can use SmartManagement.keepfactory to allow this, and although using keepfactory should be the exception, as it is the softest SmartManagement out there.

I always prefer the standard SmartManagement (full). It can be annoying at times, and eliminate something you don't want, as it has refined controls that remove memory dependency even if there is a flaw, and a widget is not arranged properly. It is safe enough with StatelessWidget, since even if there is no page available, it will still remove the controller from memory. But there are some use cases, which this restriction can be bothersome. For these situations you can use SmartManagement.onlyBuilders, which will depend on the effective removal of widgets that use the controller from the tree to remove the controller.

- NOTE: DO NOT USE SmartManagement.keepFactory if you are using multiple Bindings. It was designed to be used without Bindings, or with a single Binding linked in the GetBaterialApp's initialBinding.

- NOTE2: Using Bindings is completely optional, you can use Get.put() and Get.find() on classes that use a given controller without any problem.
However, if you work with Services or any other abstraction, I recommend using Bindings for a larger organization.

## Workers:
Workers will assist you, triggering specific callbacks when an event occurs.

Expand Down Expand Up @@ -1062,7 +1079,7 @@ You don't need the context, and you will find your navigation stack by Id.
See how simple it is:
```dart
Navigator(
key: nestedKey(1), // create a key by index
key: Get.nestedKey(1), // create a key by index
initialRoute: '/',
onGenerateRoute: (settings) {
if (settings.name == '/') {
Expand Down Expand Up @@ -1146,7 +1163,7 @@ Get.offNamedUntil() // go to next named route and remove all the previous routes
GetPlatform.isAndroid/isIOS/isWeb... //(This method is completely compatible with FlutterWeb, unlike the framework. "Platform.isAndroid")
Get.height / Get.width // Equivalent to the method: MediaQuery.of(context).size.height
Get.height / Get.width // Equivalent to the method: MediaQuery.of(context).size.height, but they are immutable. If you need a changeable height/width (like browser windows that can be scaled) you will need to use context.height and context.width
Get.context // Gives the context of the screen in the foreground anywhere in your code.
Expand Down
13 changes: 4 additions & 9 deletions lib/src/get_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ class Get {
bool callInit = false;
if (Get.isRegistred<S>(tag: tag)) {
if (!isDependencyInit<S>() &&
Get().smartManagement == SmartManagement.full) {
Get().smartManagement != SmartManagement.onlyBuilder) {
Get().registerRouteInstance<S>(tag: tag);
callInit = true;
}
Expand All @@ -781,7 +781,7 @@ class Get {
S _value = Get.put<S>(Get()._factory[key].call() as S);

if (!isDependencyInit<S>() &&
Get().smartManagement == SmartManagement.full) {
Get().smartManagement != SmartManagement.onlyBuilder) {
Get().registerRouteInstance<S>(tag: tag);
callInit = true;
}
Expand Down Expand Up @@ -902,13 +902,6 @@ class Get {
/// give current arguments
static Map<String, String> get parameters => Get()._parameters;

/// interface to GetX
RxInterface _obs;

static RxInterface get obs => Get()._obs;

static set obs(RxInterface observer) => Get()._obs = observer;

/// give name from current route
static get currentRoute => Get()._routing.current;

Expand Down Expand Up @@ -1005,6 +998,8 @@ class _FcBuilder<S> {
}
}



typedef _FcBuilderFunc<S> = S Function();

typedef _FcBuilderFuncAsync<S> = Future<S> Function();
2 changes: 1 addition & 1 deletion lib/src/routes/observers/route_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class GetObserver extends NavigatorObserver {
if (Get.isLogEnable) print("[BACK ROUTE] ${route?.settings?.name}");
}

if (Get().smartManagement == SmartManagement.full) {
if (Get().smartManagement != SmartManagement.onlyBuilder) {
Get().removeDependencyByRoute("${route?.settings?.name}");
}

Expand Down
21 changes: 8 additions & 13 deletions lib/src/rx/rx_getbuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> {
bool isRegistred = Get.isRegistred<T>();
if (widget.global) {
if (isPrepared) {
isCreator = true;
if (Get().smartManagement != SmartManagement.keepFactory) {
isCreator = true;
}
controller = Get.find<T>();
} else if (isRegistred) {
controller = Get.find<T>();
Expand All @@ -62,26 +64,19 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> {
if (isCreator && Get().smartManagement == SmartManagement.onlyBuilder) {
controller?.onInit();
}

_observer.subject.stream.listen((data) {
setState(() {});
});
_observer.subject.stream.listen((data) => setState(() {}));
super.initState();
}

@override
void dispose() {
if (widget.dispose != null) widget.dispose(this);

if (isCreator || widget.assignId) {
if (widget.autoRemove && Get.isRegistred<T>()) {
// controller.onClose();
Get.delete<T>();
}
// } else {
// controller.onClose();
}
// controller.onClose();

_observer.close();
controller = null;
isCreator = null;
Expand All @@ -90,10 +85,10 @@ class _GetXState<T extends DisposableInterface> extends State<GetX<T>> {

@override
Widget build(BuildContext context) {
final observer = Get.obs;
Get.obs = this._observer;
final observer = getObs;
getObs = this._observer;
final result = widget.builder(controller);
Get.obs = observer;
getObs = observer;
return result;
}
}
Loading

0 comments on commit 53ac3ce

Please sign in to comment.