oref 2.0.2
oref: ^2.0.2 copied to clipboard
A reactive state management library for Flutter that adds magic to any Widget with signals, computed values, and effects powered by alien_signals.
2.1.0 #
Status: Unreleased
π₯ BREAKING CHANGES #
Remove GlobalSignals.*
APIs
GlobalSignals.create(value)
->signal(null, value)
GlobalSignals.computed(getter)
->computed(null, getter)
GlobalSignals.effect(callback)
->effect(null, callback)
GlobalSignals.effectScope(callback)
->effectScope(null, callback)
2.0.2 #
2.0.1 #
- Fix
ReactiveList.add
implementation for non-nullable elements
2.0.0 #
π₯ BREAKING CHANGES #
This is a complete rewrite of Oref with breaking changes to most APIs. The new version provides better performance, cleaner APIs, and improved developer experience.
API Changes
useSignal
βsignal
: ReplaceuseSignal(context, value)
withsignal(context, value)
useComputed
βcomputed
: ReplaceuseComputed(context, computation)
withcomputed(context, computation)
useEffect
βeffect
: ReplaceuseEffect(context, callback)
witheffect(context, callback)
useEffectScope
βeffectScope
: ReplaceuseEffectScope(context)
witheffectScope(context)
- Widget Effect Hooks:
getWidgetEffect
andgetWidgetScope
renamed touseWidgetEffect
anduseWidgetScope
- Memoization:
resetMemoized
renamed toresetMemoizedFor
for clarity - Reactive Access: Direct signal calls now supported in widgets (e.g.,
Text('${count()}')
), replacing the need forSignalBuilder
in many cases
Removed Features
- Removed entire old signal system implementation (848 lines deleted)
- Removed global async computed APIs (
createGlobalAsyncComputed
,useAsyncComputed
) - Removed legacy primitive operators
- Removed old async utilities and global signal management
β¨ NEW FEATURES #
Reactive Collections
ReactiveList<T>
: Reactive wrapper for List operations with automatic dependency trackingReactiveMap<K, V>
: Reactive wrapper for Map operations with automatic dependency trackingReactiveSet<T>
: Reactive wrapper for Set operations with automatic dependency tracking- Factory Constructors: Support for widget-scoped reactive collections via
.scoped()
constructors - Global Collections: Support for global reactive collections via default constructors
Enhanced Widget Integration
SignalBuilder
: New widget for explicit reactive UI updatesSignalBuildContext
Extension: Addscontext.watch()
method for reactive value access- Direct Signal Access: Signals can now be called directly in widget build methods
- Improved Widget Effects: Better automatic rebuild triggering when signal dependencies change
New Utilities
GlobalSignals
: Utility class for managing global signal instancesbatch()
anduntrack()
: Export utility functions from alien_signals for advanced use cases- Enhanced Ref System: Improved
Ref
,StateRef
, andWidgetRef
utilities moved to dedicated utils module
π§ IMPROVEMENTS #
Performance
- Built on alien_signals v0.5.3 for optimal performance
- Removed global mutable state in computed values
- Improved memoization with better scope handling and lifecycle management
- Simplified effect and scope management for reduced overhead
Developer Experience
- Better Documentation: Comprehensive inline documentation with examples for all APIs
- Cleaner API Surface: More intuitive function names following React hooks conventions
- Simplified Widget Integration: Signals can be used directly in widget build methods without complex setup
- Better Error Handling: Improved assertions and error messages for memoization and widget context usage
- Organized Code Structure: Reorganized exports and moved utilities to separate directories for better maintainability
Architecture
- Complete Rewrite: Built from ground up with lessons learned from v1.x
- Widget Effect System: New widget effect pattern for consistent scope management
- Improved Memoization: Better widget-scoped memoization with proper lifecycle management
- Modular Design: Clear separation between core primitives, reactive collections, utilities, and widgets
- Type Safety: Enhanced type safety throughout the API surface
π MIGRATION GUIDE #
Basic Signal Usage
// v1.x
final count = useSignal(context, 0);
// v2.0
final count = signal(context, 0);
Computed Values
// v1.x
final doubled = useComputed(context, () => count.value * 2);
// v2.0
final doubled = computed(context, () => count() * 2);
Effects
// v1.x
useEffect(context, () {
print('Count: ${count.value}');
});
// v2.0
effect(context, () {
print('Count: ${count()}');
});
Widget Reactivity
// v1.x - Required SignalBuilder or manual tracking
SignalBuilder(
signal: count,
builder: (context, value, _) => Text('Count: $value'),
)
// v2.0 - Direct access supported
Text('Count: ${count()}')
// or explicit watching
Text('Count: ${context.watch(() => count())}')
// or SignalBuilder
SignalBUilder(
getter: count,
builder: (context, value) => Text('Count: $value'),
);
Reactive Collections
// v2.0 - New feature
final items = ReactiveList<String>(['a', 'b', 'c']);
final itemsScoped = ReactiveList.scoped(context, ['a', 'b', 'c']);
ποΈ PACKAGE STRUCTURE #
The new version features a well-organized package structure:
- Core:
signal
,computed
,effect
,effectScope
,useMemoized
, widget effects - Reactive:
Reactive
mixin,ReactiveList
,ReactiveMap
,ReactiveSet
- Utils:
batch
,untrack
,GlobalSignals
,Ref
utilities,SignalBuildContext
- Widgets:
SignalBuilder
for explicit reactive UI
β‘ PERFORMANCE #
- Upgraded to alien_signals v0.5.3 for optimal performance
- Removed global state management overhead
- Streamlined memoization and effect tracking
- More efficient widget rebuild patterns
π¦ DEPENDENCIES #
- alien_signals: ^0.5.3 (upgraded from ^0.4.2)
- Flutter SDK: ^3.8.1 (maintained)
1.1.3 #
- pref: Refactor binding system to use LinkedBindingNode hierarchy
1.1.2 #
- Not returning use* hooks as expected
1.1.1 #
- fix: Nested hooks cause context binding to be reset
1.1.0 #
- refactor: refactor core code to make it easier to maintain and less redundant
- refactor: Remove
createGlobalAsyncComputed
anduseAsyncComputed
- feat:
createGlobalSignal
supports automatic trigger of Widget - feat:
createGlobalComputed
supports automatic trigger of Widget - feat: Added
createGlobalAsyncResult
anduseAsyncResult
to replacecreateGlobalAsyncComputed
/useAsyncComputed
1.0.0 #
Added #
- Initial release of Oref - A reactive state management library for Flutter
- Core reactive primitives:
useSignal
- Create reactive signals with automatic dependency trackinguseComputed
- Create computed values that update when dependencies changeuseEffect
- Create side effects that run when dependencies changeuseEffectScope
- Create effect scopes for managing multiple effectsref
- Convert non-reactive Widget parameters to reactive signals
- Global APIs for use outside of widgets:
createGlobalSignal
- Create global signalscreateGlobalComputed
- Create global computed valuescreateGlobalEffect
- Create global effectscreateGlobalEffectScope
- Create global effect scopescreateGlobalAsyncComputed
- Create global async computed values
- Async computed values with
useAsyncComputed
- Batching utilities with
batch
function untrack
utility for reading signals without creating dependencies- Built-in type signal operators for enhanced type safety
- Automatic Widget rebuilding integration
- Performance optimizations with alien_signals backend
Features #
- π High performance reactive system built on alien_signals
- πͺ Magic in widgets - add reactivity to any existing Widget seamlessly
- π Automatic dependency tracking and updates
- π― Full type safety with Dart's strong type system
- π§ Flexible integration with any Flutter widget
- π¦ Lightweight with minimal overhead
Dependencies #
- Flutter SDK ^3.8.1
- alien_signals ^0.4.2