Skip to content

Commit

Permalink
version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredo.salzillo committed Jan 5, 2019
1 parent 63e8d93 commit b318433
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 97 deletions.
47 changes: 47 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,50 @@
## [1.1.0] - 05/01/2019

There is a lot of change in this version.
This is not a major release because there are no change in the design
or new functionality, excluding hot reload support (but yes,
something will break updating to the new version).

This is a better implementation how make more clear the goal
to avoid the use of classes and mixin and prefer instead
hook functions and composition.

The change came also from the necessity to make a better division of
responsibility.

* removed `Hook.dispose`.

Logic moved to a new `_DisposableController`,
how is private, because we don't want developers use class extension or mixin.
Sorry if someone was using `Hook.dispose` compose using `useEffect` instead.

* replaced `HookState` with `StateController`

It's a better name, and describe better the returned value of `useState`.

* deprecated `HookState.set` (now `StateController.set`),
use `StateController.value = newValue instead`
* `useState` now return `StateController` instead of 'HookState'
* `useMemo` now implements the dispose lifecycle
* `useEffect` --like all the hooks functions-- use `useMemo`
* **added hot reload support**

When the hock type change, because an hook function is added,
removed, or change type,
the hook will be disposed and reset to null.
There will be no break hot reloading the app.
But will be other side effects.

We decide to not make hooks shift to the next position,
because we prefer to have the same behavior in the case you add,
remove, or change an hook function call.

* Added Hot Reload test
* Added Hot Reload and Changelog section ro [README](README.md)

We are also thinking to make `use` private.
Everything can be done using `useMemo` now.

## [1.0.1] - 26/12/2018

* flutter packages get error fix
Expand Down
54 changes: 45 additions & 9 deletions README.md
Expand Up @@ -13,14 +13,17 @@ Like for [React](https://reactjs.org/docs/hooks-intro.html#motivation),
Hooks try to be a simple method
to share stateful logic between `Component`.

The goal of thi library is to devoid class extensions and mixin.
Of course flutter is not designed for functional Component and Hooks.

## Getting Started

You should ensure that you add the flhooks
as a dependency in your flutter project.

```yaml
dependencies:
flhooks: "^1.0.1"
flhooks: "^1.1.0"
```

You should then run `flutter packages upgrade`
Expand Down Expand Up @@ -98,18 +101,19 @@ It's the same as passing `() => fn` to `useMemo`.

### useState

`useState` return an `HookState`,
`HookState.value` is `initial` value passed to `useState`,
or the last passed to `HookState.set`.
`useState` return a `StateController`,
`HookState.value` is the `initial` value passed to `useState`,
or the last set using `state.value = newValue`.

Will trigger the rebuild of the `StatefulBuilder`.
`state.value = newValue` will trigger
the rebuild of the `StatefulBuilder`.

```dart
final name = useState('');
// ... get the value
Text(name.value);
//... update the value
onChange: (newValue) => name.set(newValue);
//... update the value and rebuild the component
onChange: (newValue) => name.value = newValue;
```

### useEffect
Expand Down Expand Up @@ -140,7 +144,7 @@ V useAsync<V>(Future<V> Function() asyncFn, V initial, List store) {
var active = true;
asyncFn().then((result) {
if (active) {
state.set(result);
state.value = result;
}
});
return () {
Expand All @@ -153,6 +157,38 @@ V useAsync<V>(Future<V> Function() asyncFn, V initial, List store) {

Now you can use `useAsync` like any other hooks function.

## Hot Reload

Hot reload is basically supported.

When the hock type change, because an hook function is added,
removed, or change type,
the hook will be disposed and reset to null.

However after an add or a remove, all hooks after the one how change,
can be disposed or had a reset.

__Pay attention, will be no break hot reloading the app,
but will be other side effects.__

We decide to not make hooks shift to the next position,
because we prefer to have the same behavior in the case you add,
remove, or change an hook function call.

Feel free to open a issue or fork the repository
to suggest a new implementation.

## Example

More example in the [example](example) directory.
More example in the [example](example) directory.

## Changelog
Current version is __1.1.0__,
read the [changelog](CHANGELOG.md) for more info.

## Next on flhooks

New hooks will be added in future like `useFuture` (or `useAsync`) and `useStream`,
there will be no need to use `FutureBuilder` and `StreamBuilder` anymore.

We are actually testing some `useIf` conditional implementation of hooks.
2 changes: 1 addition & 1 deletion example/todo_app/pubspec.yaml
Expand Up @@ -15,7 +15,7 @@ environment:
dependencies:
flutter:
sdk: flutter
flhooks: ^1.0.0
flhooks: ^1.0.1

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand Down

0 comments on commit b318433

Please sign in to comment.