v7.3.0 to v8.0.0
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
andRt.removeObserver
methods to manage the observers. - Add
RtStateObserver
class to monitor the lifecycle of state(onStateCreated
,onStateBound
,onStateUnbound
,onStateUpdated
andonStateDisposed
). - Add
RtDependencyObserver
class to monitor the lifecycle of dependency(onDependencyRegistered
,onDependencyCreated
,onDependencyMounted
,onDependencyUnmounted
,onDependencyDeleted
,onDependencyUnregistered
andonDependencyFailed
). - Add
Rt.initializeLogger
to initialize the Reactter logger. - Add
Rt.initializeDevTools
to initialize the devtools for observing the states and dependencies. - Add
debugLabel
anddebugInfo
to states and hooks to get info for debugging. - Add
RtContextMixin
mixin to provide access to theRt
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 toRtHook
to call when hook is created. - Add
cancel
method toUseAsyncState
to cancel current method. - Update
batch
anduntracked
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
toRtComponent
. - Enhance dependency management to ensure to re-build when is detected changes while building.
Breakings
- Remove
Reactter
, useRt
instead. - Remove
ReactterStateImpl
andRtStateImpl
, useRtState
instead. - Replace
UseAsyncStateStatus.standby
toUseAsyncStateStatus.idle
. - Rename
DispatchEffect
toAutoDispatchEffect
. - Move
asyncFunction
to the first parameter ofUseAsyncState
andUseAsyncState.withArg
. - Remove
Rt.isRegistered
, useRt.isActive
instead. - Remove
Rt.getInstanceManageMode
, useRt.getDependencyMode
instead. - Remove
InstanceManageMode
, useDependencyMode
instead. - Remove
Lifecycle.initialized
, useLifecycle.created
instead. - Remove
Lifecycle.destroyed
, useLifecycle.deleted
instead. - Replace
LifecycleObserver
toRtDependencyLifecycle
. - Remove
LifecycleObserver.onInitialized
, useRtDependencyLifecycle.onCreated
instead. - Remove
ReactterInstance
andReactterDependency
, useRtDependencyRef
instead. - Remove
ReactterHook
, useRtHook
instead. - Remove
ReactterInterface
, useRtInterface
instead. - Remove
RtState.refresh
, useRtState.notify
instead. - Remove
UseInstance
, useUseDependency
instead. - Remove
ReactterAction
, useRtAction
instead. - Remove
ReactterActionCallable
, useRtActionCallable
instead. - Remove
MemoInterceptors
, useMultiMemoInterceptor
instead. - Remove
AsyncMemoSafe
, useMemoSafeAsyncInterceptor
instead. - Remove
TemporaryCacheMemo
, useMemoTemporaryCacheInterceptor
instead. - Remove
MemoInterceptorWrapper
, useMemoWrapperInterceptor
instead. - Remove
Obj
. - Remove
init
property fromRtProvider
, useRtProvider.init
instead. - Remove
ReactterComponent
, useRtComponent
instead. - Remove
ReactterConsumer
, useRtConsumer
instead. - Remove
ReactterProvider
, useRtProvider
instead. - Remove
ReactterProviders
, useRtMultiProvider
instead. - Remove
ReactterScope
, useRtScope
instead. - Remove
ReactterWatcher
, useRtSignalWatcher
instead. - Remove
ReactterDependencyNotFoundException
, useRtDependencyNotFoundException
instead. - Remove
ReactterScopeNotFoundException
, useRtScopeNotFoundException
instead.
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
withRt
.Reactter.create(...);Rt.create(...);ReactterProvider(...);RtProvider(...); -
If you’re using
ReactterStateImpl
orRtStateImpl
, migrate toRtState
.class MyState extendsReactterStateImpl{class MyState extends RtState<MyState> {// Implementation} -
Replace
UseAsyncStateStatus.standby
withUseAsyncStateStatus.idle
.UseAsyncStateStatus.standby;UseAsyncStateStatus.idle; -
Replace
DispatchEffect
withAutoDispatchEffect
.class MyClass withDispatchEffect{class MyClass with AutoDispatchEffect {// Implementation} -
Move
asyncFunction
to the first parameter ofUseAsyncState
andUseAsyncState.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
withRt.isActive
.Rt.isRegistered(instance);Rt.isActive(instance); -
Replace
Rt.getInstanceManageMode
withRt.getDependencyMode
.Rt.getInstanceManageMode(instance);Rt.getDependencyMode(instance); -
Replace
RtState.refresh
withRtState.notify
.state.refresh();state.notify(); -
Replace
UseInstance
withUseDependency
.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
withRtDependencyLifecycle
.class MyClass extendsLifecycleObserver{class MyClass extends RtDependencyLifecycle {// Implementation} -
Replace
LifecycleObserver.onInitialized
withRtDependencyLifecycle.onCreated
.class MyClass extendsLifecycleObserver{voidonInitialized() {class MyClass extends RtDependencyLifecycle {void onCreated() {// Implementation}} -
Replace
MemoInterceptors
withMultiMemoInterceptor
.final memo = Memo(computeValue,MemoInterceptors([MultiMemoInterceptor([// Interceptors]),); -
Replace
AsyncMemoSafe
withMemoSafeAsyncInterceptor
.final memo = Memo(computeValue,AsyncMemoSafe(),MemoSafeAsyncInterceptor(),); -
Replace
TemporaryCacheMemo
withMemoTemporaryCacheInterceptor
.final memo = Memo(computeValue,TemporaryCacheMemo(...),MemoTemporaryCacheInterceptor(...),); -
Replace
MemoInterceptorWrapper
withMemoWrapperInterceptor
.final memo = Memo(computeValue,MemoInterceptorWrapper(...),MemoWrapperInterceptor(...),); -
Replace
init
property withRtProvider.init
constructor.RtProvider(init: true,RtProvider.init(...); -
Replace
ReactterProviders
orRtProviders
withRtMultiProvider
.RtProviders(...)RtMultiProvider(...) -
Replace
ReactterWatcher
withRtSignalWatcher
.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.