Saltearse al contenido

v7.3.0 to v8.0.0

Esta página aún no está disponible en tu idioma.

This guide will help you migrate your project from Reactter v7.3.0 to v8.0.0. The new version introduces several enhancements, breaking changes, and fixes to improve stability, performance, and developer experience. Below, we’ll walk you through the necessary steps to update your codebase.

By following this guide, you should be able to successfully migrate your project to Reactter v8.0.0. If you encounter any issues, refer to the official documentation or report them as an issue on Github.

1. Overview of Changes

Enhancements

  • Add Reactter devtools extension.
  • Add Rt.addObserver and Rt.removeObserver methods to manage the observers.
  • Add RtStateObserver class to monitor the lifecycle of state( onStateCreated , onStateBound , onStateUnbound , onStateUpdated and onStateDisposed ).
  • Add RtDependencyObserver class to monitor the lifecycle of dependency( onDependencyRegistered , onDependencyCreated , onDependencyMounted , onDependencyUnmounted , onDependencyDeleted ,  onDependencyUnregistered and onDependencyFailed ).
  • Add Rt.initializeLogger to initialize the Reactter logger.
  • Add Rt.initializeDevTools to initialize the devtools for observing the states and dependencies.
  • Add debugLabel and debugInfo to states and hooks to get info for debugging.
  • Add RtContextMixin mixin to provide access to the Rt instance.
  • Add RtState abstract class to implement the base logic of the state.
  • Add Rt.registerState method to create a new state.
  • Add Rt.getRefAt to get the reference of dependency created.
  • Add initHook method to RtHook to call when hook is created.
  • Add cancel method to UseAsyncState to cancel current method.
  • Update batch and untracked methods to support asynchronous callbacks.
  • Enhance event handling and notifier logic for improved stability and performance.
  • Enhance state management and error handling.
  • Add dependency mode to RtComponent .
  • Enhance dependency management to ensure to re-build when is detected changes while building.

Breakings

Fixes

  • Fix bug in UseEffect causing dependencies to not be unwatched.
  • Fix to show the correct dependency mode in the logger of the Rt.register method.
  • Fix nested Rt.batch method to work correctly.
  • Add error handling listeners and continue to next listeners in Notifier class.
  • Fix to propagate state param to boundInstance .
  • Remove listeners correctly from single-use listeners and handle null cases.

2. Implement the changes

  • Replace all occurrences of Reactter with Rt .

    Reactter.create(...);
    Rt.create(...);
    ReactterProvider(...);
    RtProvider(...);
  • If you’re using ReactterStateImpl or RtStateImpl , migrate to RtState .

    class MyState extends ReactterStateImpl {
    class MyState extends RtState<MyState> {
    // Implementation
    }
  • Replace UseAsyncStateStatus.standby with UseAsyncStateStatus.idle.

    UseAsyncStateStatus.standby;
    UseAsyncStateStatus.idle;
  • Replace DispatchEffect with AutoDispatchEffect .

    class MyClass with DispatchEffect {
    class MyClass with AutoDispatchEffect {
    // Implementation
    }
  • Move asyncFunction to the first parameter of UseAsyncState and UseAsyncState.withArg .

    final uAsyncState = UseAsyncState(initialValue, asyncFunction);
    final uAsyncState = UseAsyncState(asyncFunction, initialValue);
    final uAsyncStateWithArg = UseAsyncState.withArg(initialValue, asyncFunction);
    final uAsyncStateWithArg = UseAsyncState.withArg(asyncFunction, initialValue);
  • Replace Rt.isRegistered with Rt.isActive .

    Rt.isRegistered(instance);
    Rt.isActive(instance);
  • Replace Rt.getInstanceManageMode with Rt.getDependencyMode .

    Rt.getInstanceManageMode(instance);
    Rt.getDependencyMode(instance);
  • Replace RtState.refresh with RtState.notify .

    state.refresh();
    state.notify();
  • Replace UseInstance with UseDependency .

    final uDependency = UseInstance<MyDependency>();
    final uDependency = UseDependency<MyDependency>();
  • Replace deprecated Lifecycle enum values with their new counterparts.

    Lifecycle.initialized;
    Lifecycle.created;
    Lifecycle.destroyed;
    Lifecycle.deleted;
  • Replace LifecycleObserver with RtDependencyLifecycle .

    class MyClass extends LifecycleObserver {
    class MyClass extends RtDependencyLifecycle {
    // Implementation
    }
  • Replace LifecycleObserver.onInitialized with RtDependencyLifecycle.onCreated .

    class MyClass extends LifecycleObserver {
    void onInitialized() {
    class MyClass extends RtDependencyLifecycle {
    void onCreated() {
    // Implementation
    }
    }
  • Replace MemoInterceptors with MultiMemoInterceptor .

    final memo = Memo(
    computeValue,
    MemoInterceptors([
    MultiMemoInterceptor([
    // Interceptors
    ]),
    );
  • Replace AsyncMemoSafe with MemoSafeAsyncInterceptor .

    final memo = Memo(
    computeValue,
    AsyncMemoSafe(),
    MemoSafeAsyncInterceptor(),
    );
  • Replace TemporaryCacheMemo with MemoTemporaryCacheInterceptor .

    final memo = Memo(
    computeValue,
    TemporaryCacheMemo(...),
    MemoTemporaryCacheInterceptor(...),
    );
  • Replace MemoInterceptorWrapper with MemoWrapperInterceptor .

    final memo = Memo(
    computeValue,
    MemoInterceptorWrapper(...),
    MemoWrapperInterceptor(...),
    );
  • Replace init property with RtProvider.init constructor.

    RtProvider(
    init: true,
    RtProvider.init(
    ...
    );
  • Replace ReactterProviders or RtProviders with RtMultiProvider .

    RtProviders(...)
    RtMultiProvider(...)
  • Replace ReactterWatcher with RtSignalWatcher .

    ReactterWatcher(...)
    RtSignalWatcher(...)

3. Verify Your Code

After making the above changes, thoroughly test your application to ensure everything works as expected. Pay special attention to:

  • State and dependency lifecycles.
  • Event handling and notifier logic.
  • Debugging and logging outputs.