Skip to content

Releases: JhonaCodes/reactive_notifier

v2.7.0-release

31 Mar 01:24
ff059ab
Compare
Choose a tag to compare

What's Changed

Full Changelog: v2.5.0-release...v2.7.0

v2.5.0-release

03 Feb 12:44
33be565
Compare
Choose a tag to compare

The ReactiveViewModelBuilder was created to provide a more intuitive and efficient way to handle ViewModel states while maintaining the simplicity and power of ReactiveNotifier.

Key Features and Benefits

1. Type-Safety and Clear Intent

When using ReactiveViewModelBuilder, it's recommended to use the data type managed by the ViewModel rather than the ViewModel itself. For example:

// Recommended ✅
ReactiveViewModelBuilder<ProductData>(
  notifier: productStateNotifier.notifier,
  builder: (state, keep) => ProductView(data: state)
)

// Not recommended ❌
ReactiveViewModelBuilder<ProductViewModel>

2. Practical Example

Here's a typical use case:

// ProductViewModel
class ProductViewModel extends ViewModelStateImpl<ProductData> {
  ProductViewModel() : super(ProductData());

  void updatePrice(double newPrice) {
    updateState(data.copyWith(price: newPrice));
  }

  void updateStock(int newStock) {
    updateState(data.copyWith(stock: newStock));
  }
}

// Usage in UI
ReactiveViewModelBuilder<ProductData>(
  notifier: productStateNotifier.notifier,
  builder: (state, keep) {
    return Column(
      children: [
        Text('Price: ${state.price}'),
        Text('Stock: ${state.stock}'),
        ElevatedButton(
          onPressed: () {
            // Access ViewModel methods through notifier
            productStateNotifier.notifier.updatePrice(99.99);
          },
          child: Text('Update Price'),
        ),
      ],
    );
  },
)

Clear Separation of Concerns

  • State Access: Through the state parameter in the builder
  • ViewModel Actions: Through notifier methods
  • State Updates: Handled automatically without manual transforms

Alternative Approaches

If not using ReactiveViewModelBuilder, state updates in ViewModels require manual transformation:

// Without ReactiveViewModelBuilder
myStateNotifier.transformState((s) => s); // Required after ViewModel updates

Recommendations for Different Use Cases

Use ReactiveViewModelBuilder when:

  • Working with complex ViewModels
  • Handling nested state updates
  • Need clear separation between state and actions
  • Managing form states or complex UI states

Example:

class OrderViewModel extends ViewModelStateImpl<OrderData> {
  void updateOrderStatus(OrderStatus status) {
    updateState(data.copyWith(status: status));
  }
}

// In UI
ReactiveViewModelBuilder<OrderData>(
  notifier: orderStateNotifier.notifier,
  builder: (state, keep) {
    return OrderStatusWidget(
      status: state.status,
      onStatusChange: (newStatus) {
        orderStateNotifier.notifier.updateOrderStatus(newStatus);
      },
    );
  },
)

Use ReactiveBuilder when:

  • Working with simple states
  • Managing model states with copyWith
  • Need direct state transformations
  • Handling single-value states

Example:

// Simple user model state
final userStateNotifier = ReactiveNotifier(() => User());

ReactiveBuilder(
  notifier: userStateNotifier,
  builder: (user, keep) {
    return UserProfileCard(user: user);
  },
)

Performance Benefits

  • Optimized for ViewModel state updates
  • Prevents unnecessary rebuilds
  • Efficient handling of nested state changes
  • Built-in debouncing for rapid updates

Although technically I could have created a named class, I preferred to duplicate a bit of the code, to reduce the coupling and overhead of ReactiveBuilder, this also allows me to freely modify in case of any problems of the 2 and to have a clear separation, it also makes contributions easier.

Sometimes a little bit of repeated code saves lives, 😀.

It should be noted that we are still in the stage of standardizing behavior, so code quality and optimization are not a priority at the moment.

Any suggestions or contributions are welcome.
With ❤️ from Jhonacode.

v2.4.1-release

19 Dec 15:25
d25a7fc
Compare
Choose a tag to compare
  • Update name of state and documentation for StateNotifierImpl.

  • Introducing transformState function for model editing, allowing state modifications at any nesting level. This function supports implementations like copyWith, enabling selective value updates in your models.

  • Simplified state management: unified notifier and VM into a single approach using ReactiveBuilder, ReactiveAsync, and ReactiveStream. Access functions directly through notifier reference (e.g., instance.notifier.replaceData(...)). Access ReactiveAsync data via notifier.data.

  • Removed ValueNotifier value dependency, eliminating nested state update issues (previously instance.value.value, now instance.data).

  • Protected internal builder functions for improved encapsulation.

  • Maintained compatibility with ListenableBuilder for ReactiveNotifier.

  • Removed context dependency from builder as ReactiveNotifier doesn't require it.

v.2.2.-release

21 Nov 01:21
Compare
Choose a tag to compare

2.2.0

  • Update documentations and images.
  • Implement Ci for actions.

2.1.1

  • Update Readme.

2.1.0

  • Few bits, and name convention
  • New ViewModelStateImpl for simple viewmodel state.

2.0.0

Breaking Changes 🚨

  • Complete project architecture overhaul
  • New reference handling system
  • Changed how related states are managed

New Features 🎉

  • Enhanced Debugging System

    • Improved error messages
    • Better stack traces
    • Detailed circular reference detection
  • Advanced State Management

    • Support for nested ReactiveNotifier instances in related states
    • Improved multiple reference handling
    • Better state isolation and context management
  • Async & Stream Support

    • Built-in async state handling
    • Stream state management
    • Automatic state synchronization
  • Extended Testing Support

    • More test cases
    • Better coverage
    • Improved testing utilities

Improvements 🔧

  • Better performance in state updates
  • Reduced memory footprint
  • Improved type safety
  • Enhanced error handling
  • Better documentation

Bug Fixes 🐛

  • Fixed issues with circular references
  • Improved state cleanup
  • Better error reporting
  • Fixed memory leaks in complex state trees

Documentation 📚

  • Complete documentation overhaul
  • New examples and use cases
  • Better API documentation
  • Improved error messages

1.0.5

  • Update documentation.

1.0.4

  • Implement when and callback when finish setState.
  • Help to execute any other params when change state

1.0.3

  • Upgrade SDK.

1.0.2

  • Add gif for visual context.
  • Change name from State to Notify.
  • Update golden test.

1.0.1

  • Change name from State to Notify.
  • Improve README.md.

1.0.0

  • Initial version.

Full Changelog: https://github.com/JhonaCodes/reactive_notifier/commits/V.2.2.-release