diff --git a/examples/presentation/pubspec.yaml b/examples/presentation/pubspec.yaml index a8c0bc7..b8911c7 100644 --- a/examples/presentation/pubspec.yaml +++ b/examples/presentation/pubspec.yaml @@ -9,10 +9,7 @@ dependencies: device_frame: ^1.1.0 flutter: sdk: flutter - flutter_deck: # ^0.8.0 - git: - url: https://github.com/GregoryConrad/flutter_deck - ref: fullscreen-button + flutter_deck: ^0.9.1 flutter_rearch: ^1.2.3 graphview: ^1.2.0 rearch: ^1.3.3 diff --git a/packages/flutter_rearch/lib/flutter_rearch.dart b/packages/flutter_rearch/lib/flutter_rearch.dart index 3c03069..89ac0f4 100644 --- a/packages/flutter_rearch/lib/flutter_rearch.dart +++ b/packages/flutter_rearch/lib/flutter_rearch.dart @@ -1,11 +1,16 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_rearch/src/widgets.dart'; +import 'package:meta/meta.dart'; import 'package:rearch/rearch.dart'; export 'src/side_effects.dart'; export 'src/widgets.dart'; /// The API exposed to [RearchConsumer]s to extend their functionality. +/// +/// New methods may be added to this interface on any new _minor_ release +/// (minor in terms of semver). +@experimental abstract interface class WidgetSideEffectApi implements SideEffectApi { /// The [BuildContext] of the associated [RearchConsumer]. BuildContext get context; diff --git a/packages/flutter_rearch/lib/src/side_effects.dart b/packages/flutter_rearch/lib/src/side_effects.dart index 4346b61..d5cd63e 100644 --- a/packages/flutter_rearch/lib/src/side_effects.dart +++ b/packages/flutter_rearch/lib/src/side_effects.dart @@ -1,6 +1,7 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_rearch/flutter_rearch.dart'; +import 'package:rearch/experimental.dart'; import 'package:rearch/rearch.dart'; part 'side_effects/animation.dart'; diff --git a/packages/flutter_rearch/pubspec.yaml b/packages/flutter_rearch/pubspec.yaml index 809d4af..3a7f5a4 100644 --- a/packages/flutter_rearch/pubspec.yaml +++ b/packages/flutter_rearch/pubspec.yaml @@ -13,6 +13,7 @@ environment: dependencies: flutter: sdk: flutter + meta: ^1.10.0 rearch: ^1.3.3 dev_dependencies: diff --git a/packages/rearch/lib/experimental.dart b/packages/rearch/lib/experimental.dart new file mode 100644 index 0000000..017f552 --- /dev/null +++ b/packages/rearch/lib/experimental.dart @@ -0,0 +1,33 @@ +/// A collection of ReArch experiments in case you like exploring the unknown. +/// +/// Nothing here is officially supported; +/// items may come and go or experience breaking changes on any new release. +/// Further, items here may be untested so use at your own risk! +@experimental +library experimental; + +import 'package:meta/meta.dart'; +import 'package:rearch/rearch.dart'; + +extension _UseConvenience on SideEffectRegistrar { + SideEffectRegistrar get use => this; +} + +/// A collection of experimental side effects to +/// complement the [BuiltinSideEffects]. +extension ExperimentalSideEffects on SideEffectRegistrar { + /// Returns a raw value wrapper; i.e., a getter and setter for some value. + /// *The setter will not trigger rebuilds*. + /// The initial state will be set to the result of running [init], + /// if it was provided. Otherwise, you must manually set it + /// via the setter before ever calling the getter. + // NOTE: experimental because I am not sold on the API and use cases + // for non-internal usage. + (T Function(), void Function(T)) rawValueWrapper([T Function()? init]) { + return use.callonce(() { + late T state; + if (init != null) state = init(); + return (() => state, (T newState) => state = newState); + }); + } +} diff --git a/packages/rearch/lib/rearch.dart b/packages/rearch/lib/rearch.dart index 3875082..7a2cf1b 100644 --- a/packages/rearch/lib/rearch.dart +++ b/packages/rearch/lib/rearch.dart @@ -71,6 +71,10 @@ typedef SideEffect = T Function(SideEffectApi); typedef SideEffectApiCallback = void Function(); /// The api given to [SideEffect]s to create their state. +/// +/// New methods may be added to this interface on any new _minor_ release +/// (minor in terms of semver). +@experimental abstract interface class SideEffectApi { /// Triggers a rebuild in the supplied capsule. void rebuild(); diff --git a/packages/rearch/lib/src/side_effects.dart b/packages/rearch/lib/src/side_effects.dart index ab57121..0393b71 100644 --- a/packages/rearch/lib/src/side_effects.dart +++ b/packages/rearch/lib/src/side_effects.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:meta/meta.dart'; +import 'package:rearch/experimental.dart'; import 'package:rearch/rearch.dart'; extension _UseConvenience on SideEffectRegistrar { @@ -26,20 +26,6 @@ extension BuiltinSideEffects on SideEffectRegistrar { /// Side effect that calls the supplied [callback] once, on the first build. T callonce(T Function() callback) => use.register((_) => callback()); - /// Returns a raw value wrapper; i.e., a getter and setter for some value. - /// *The setter will not trigger rebuilds*. - /// The initial state will be set to the result of running [init], - /// if it was provided. Otherwise, you must manually set it - /// via the setter before ever calling the getter. - @experimental - (T Function(), void Function(T)) rawValueWrapper([T Function()? init]) { - return use.callonce(() { - late T state; - if (init != null) state = init(); - return (() => state, (T newState) => state = newState); - }); - } - /// Side effect that provides a way for capsules to contain some state, /// where the initial state is computationally expensive. /// Further, instead of returning the state directly, this instead returns @@ -222,10 +208,10 @@ extension BuiltinSideEffects on SideEffectRegistrar { return getValue(); } - /// A mechanism to persist changes made in state. + /// A mechanism to persist changes made in state that manages its own state. /// See the docs for usage information. /// - /// Defines the way to interact with a storage provider of your choice + /// Defines a way to interact with a storage provider of your choice /// through the [read] and [write] parameters. /// /// [read] is only called once; it is assumed that if [write] is successful,