diff --git a/packages/katana_scoped/lib/src/ref.dart b/packages/katana_scoped/lib/src/ref.dart index fe6c29a0a..083448c9e 100644 --- a/packages/katana_scoped/lib/src/ref.dart +++ b/packages/katana_scoped/lib/src/ref.dart @@ -154,7 +154,7 @@ abstract class RefHasApp implements RefOrRefHasAny, RefHasAny { /// [Ref] in the application scope. /// /// アプリケーションスコープの[Ref]。 - AppScopedValueOrAppRef get app; + AppScopedValueRef get app; } /// Reference with page scope [Ref]. diff --git a/packages/katana_scoped/lib/src/scoped_query.dart b/packages/katana_scoped/lib/src/scoped_query.dart index 715e55004..e3610d09f 100644 --- a/packages/katana_scoped/lib/src/scoped_query.dart +++ b/packages/katana_scoped/lib/src/scoped_query.dart @@ -146,63 +146,6 @@ class ScopedQuery extends ScopedQueryBase { }); } -/// [ScopedQuery] available at app scope. -/// -/// Appスコープで利用可能な[ScopedQuery]。 -/// -/// {@macro scoped_query} -class AppScopedQuery - extends ScopedQueryBase { - /// [ScopedQuery] available at app scope. - /// - /// Appスコープで利用可能な[ScopedQuery]。 - /// - /// {@macro scoped_query} - const AppScopedQuery( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced = false, - }); -} - -/// [ScopedQuery] available at page scope. -/// -/// ページスコープで利用可能な[ScopedQuery]。 -/// -/// {@macro scoped_query} -class PageScopedQuery - extends ScopedQueryBase { - /// [ScopedQuery] available at page scope. - /// - /// ページスコープで利用可能な[ScopedQuery]。 - /// - /// {@macro scoped_query} - const PageScopedQuery( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced = false, - }); -} - -/// [ScopedQuery] available in the widget scope. -/// -/// ウィジェットスコープで利用可能な[ScopedQuery]。 -/// -/// {@macro scoped_query} -class WidgetScopedQuery - extends ScopedQueryBase { - /// [ScopedQuery] available in the widget scope. - /// - /// ウィジェットスコープで利用可能な[ScopedQuery]。 - /// - /// {@macro scoped_query} - const WidgetScopedQuery( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced = false, - }); -} - /// Base class that can specify the type of the [provider] part of [ScopedQuery]. /// /// Used to create frameworks. @@ -333,66 +276,6 @@ class ChangeNotifierScopedQuery }); } -/// [ChangeNotifierScopedQuery] available at app scope. -/// -/// Appスコープで利用可能な[ChangeNotifierScopedQuery]。 -/// -/// {@macro change_notifier_scoped_query} -@immutable -class ChangeNotifierAppScopedQuery - extends ChangeNotifierScopedQueryBase { - /// [ChangeNotifierScopedQuery] available at app scope. - /// - /// Appスコープで利用可能な[ChangeNotifierScopedQuery]。 - /// - /// {@macro change_notifier_scoped_query} - const ChangeNotifierAppScopedQuery( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced, - }); -} - -/// [ChangeNotifierScopedQuery] available at page scope. -/// -/// ページスコープで利用可能な[ChangeNotifierScopedQuery]。 -/// -/// {@macro change_notifier_scoped_query} -@immutable -class ChangeNotifierPageScopedQuery - extends ChangeNotifierScopedQueryBase { - /// [ChangeNotifierScopedQuery] available at page scope. - /// - /// ページスコープで利用可能な[ChangeNotifierScopedQuery]。 - /// - /// {@macro change_notifier_scoped_query} - const ChangeNotifierPageScopedQuery( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced, - }); -} - -/// [ChangeNotifierScopedQuery] available in the widget scope. -/// -/// ウィジェットスコープで利用可能な[ChangeNotifierScopedQuery]。 -/// -/// {@macro change_notifier_scoped_query} -@immutable -class ChangeNotifierWidgetScopedQuery - extends ChangeNotifierScopedQueryBase { - /// [ChangeNotifierScopedQuery] available in the widget scope. - /// - /// ウィジェットスコープで利用可能な[ChangeNotifierScopedQuery]。 - /// - /// {@macro change_notifier_scoped_query} - const ChangeNotifierWidgetScopedQuery( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced, - }); -} - /// Base class that allows specifying the type of the [provider] part of [ScopedQuery] that allows passing a single parameter. /// /// Used to create frameworks. @@ -471,96 +354,6 @@ class ScopedQueryFamily ); } -/// You can pass one parameter [AppScopedQuery]. -/// -/// パラメーターを一つ渡すことができる[AppScopedQuery]。 -/// -/// {@macro scoped_query} -@immutable -class AppScopedQueryFamily - extends ScopedQueryFamilyBase { - /// You can pass one parameter [AppScopedQuery]. - /// - /// パラメーターを一つ渡すことができる[AppScopedQuery]。 - /// - /// {@macro scoped_query} - const AppScopedQueryFamily( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced = false, - }); - - /// By passing [param], the corresponding [ScopedQuery] is returned. - /// - /// [param]を渡すことで対応した[ScopedQuery]を返します。 - @override - AppScopedQuery call(Param param) => AppScopedQuery( - (ref) => provider(ref, param), - name: "${_name ?? hashCode}#${param.hashCode}", - autoDisposeWhenUnreferenced: autoDisposeWhenUnreferenced, - ); -} - -/// You can pass one parameter [PageScopedQuery]. -/// -/// パラメーターを一つ渡すことができる[PageScopedQuery]。 -/// -/// {@macro scoped_query} -@immutable -class PageScopedQueryFamily - extends ScopedQueryFamilyBase { - /// You can pass one parameter [PageScopedQuery]. - /// - /// パラメーターを一つ渡すことができる[PageScopedQuery]。 - /// - /// {@macro scoped_query} - const PageScopedQueryFamily( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced = false, - }); - - /// By passing [param], the corresponding [ScopedQuery] is returned. - /// - /// [param]を渡すことで対応した[ScopedQuery]を返します。 - @override - PageScopedQuery call(Param param) => PageScopedQuery( - (ref) => provider(ref, param), - name: "${_name ?? hashCode}#${param.hashCode}", - autoDisposeWhenUnreferenced: autoDisposeWhenUnreferenced, - ); -} - -/// You can pass one parameter [WidgetScopedQuery]. -/// -/// パラメーターを一つ渡すことができる[WidgetScopedQuery]。 -/// -/// {@macro scoped_query} -@immutable -class WidgetScopedQueryFamily - extends ScopedQueryFamilyBase { - /// You can pass one parameter [WidgetScopedQuery]. - /// - /// パラメーターを一つ渡すことができる[WidgetScopedQuery]。 - /// - /// {@macro scoped_query} - const WidgetScopedQueryFamily( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced = false, - }); - - /// By passing [param], the corresponding [ScopedQuery] is returned. - /// - /// [param]を渡すことで対応した[ScopedQuery]を返します。 - @override - WidgetScopedQuery call(Param param) => WidgetScopedQuery( - (ref) => provider(ref, param), - name: "${_name ?? hashCode}#${param.hashCode}", - autoDisposeWhenUnreferenced: autoDisposeWhenUnreferenced, - ); -} - /// You can pass one parameter [ChangeNotifierScopedQuery]. /// /// パラメーターを一つ渡すことができる[ChangeNotifierScopedQuery]。 @@ -618,90 +411,3 @@ class ChangeNotifierScopedQueryFamily autoDisposeWhenUnreferenced: autoDisposeWhenUnreferenced, ); } - -/// You can pass one parameter [ChangeNotifierAppScopedQuery]. -/// -/// パラメーターを一つ渡すことができる[ChangeNotifierAppScopedQuery]。 -/// -/// {@macro change_notifier_scoped_query} -@immutable -class ChangeNotifierAppScopedQueryFamily - extends ChangeNotifierScopedQueryFamilyBase { - /// You can pass one parameter [ChangeNotifierAppScopedQuery]. - /// - /// パラメーターを一つ渡すことができる[ChangeNotifierAppScopedQuery]。 - /// - /// {@macro change_notifier_scoped_query} - const ChangeNotifierAppScopedQueryFamily( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced, - }); - - @override - ChangeNotifierAppScopedQuery call(Param param) => - ChangeNotifierAppScopedQuery( - (ref) => provider(ref, param), - name: "${_name ?? hashCode}#${param.hashCode}", - autoDisposeWhenUnreferenced: autoDisposeWhenUnreferenced, - ); -} - -/// You can pass one parameter [ChangeNotifierPageScopedQuery]. -/// -/// パラメーターを一つ渡すことができる[ChangeNotifierPageScopedQuery]。 -/// -/// {@macro change_notifier_scoped_query} -@immutable -class ChangeNotifierPageScopedQueryFamily - extends ChangeNotifierScopedQueryFamilyBase { - /// You can pass one parameter [ChangeNotifierPageScopedQuery]. - /// - /// パラメーターを一つ渡すことができる[ChangeNotifierPageScopedQuery]。 - /// - /// {@macro change_notifier_scoped_query} - const ChangeNotifierPageScopedQueryFamily( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced, - }); - - @override - ChangeNotifierPageScopedQuery call(Param param) => - ChangeNotifierPageScopedQuery( - (ref) => provider(ref, param), - name: "${_name ?? hashCode}#${param.hashCode}", - autoDisposeWhenUnreferenced: autoDisposeWhenUnreferenced, - ); -} - -/// You can pass one parameter [ChangeNotifierWidgetScopedQuery]. -/// -/// パラメーターを一つ渡すことができる[ChangeNotifierWidgetScopedQuery]。 -/// -/// {@macro change_notifier_scoped_query} -@immutable -class ChangeNotifierWidgetScopedQueryFamily - extends ChangeNotifierScopedQueryFamilyBase { - /// You can pass one parameter [ChangeNotifierWidgetScopedQuery]. - /// - /// パラメーターを一つ渡すことができる[ChangeNotifierWidgetScopedQuery]。 - /// - /// {@macro change_notifier_scoped_query} - const ChangeNotifierWidgetScopedQueryFamily( - super.provider, { - super.name, - super.autoDisposeWhenUnreferenced, - }); - - @override - ChangeNotifierWidgetScopedQuery call(Param param) => - ChangeNotifierWidgetScopedQuery( - (ref) => provider(ref, param), - name: "${_name ?? hashCode}#${param.hashCode}", - autoDisposeWhenUnreferenced: autoDisposeWhenUnreferenced, - ); -} diff --git a/packages/katana_scoped/lib/value/ancestor.dart b/packages/katana_scoped/lib/value/ancestor.dart deleted file mode 100644 index 513a348fd..000000000 --- a/packages/katana_scoped/lib/value/ancestor.dart +++ /dev/null @@ -1,48 +0,0 @@ -part of 'value.dart'; - -/// Provides an extension method for [PageOrWidgetScopedValueRef] to retrieve a [ScopedValue] that already exists in the page or widget scope. -/// -/// ページスコープやウィジェットスコープにすでに存在している[ScopedValue]の取得を行うための[PageOrWidgetScopedValueRef]用の拡張メソッドを提供します。 -extension PageScopedValueRefAncestorExtensions on PageOrWidgetScopedValueRef { - /// This is used to retrieve a [ScopedValue] already registered in [watch] or [cache] with the widget below it, etc. - /// - /// An error is returned when trying to retrieve a [ScopedValue] that is not registered in [watch] or [cache]. - /// - /// [ScopedValue] registered in [watch] and [ScopedValue] registered in [cache] are processed in this order. - /// - /// When [watch] returns a registered [ScopedValue], it will be associated with the widget and notify the user of the change. - /// - /// If there are multiple [ScopedValue] of the same type in the scope, specify [name]. - /// - /// If [ScopedValue] is not found in that scope, it is searched recursively from the child to the parent scope. - /// - /// [watch]や[cache]ですでに登録している[ScopedValue]をその下のウィジェット等で取得するために利用します。 - /// - /// [watch]や[cache]で登録されていない[ScopedValue]を取得しようとした時エラーが返されます。 - /// - /// [watch]で登録した[ScopedValue]、[cache]で登録した[ScopedValue]の順番で処理されます。 - /// - /// [watch]で登録した[ScopedValue]を返すときにウィジェットに関連付けて変更を通知するようにします。 - /// - /// そのスコープ内に同じ型の[ScopedValue]が複数存在する場合は[name]を指定してください。 - /// - /// そのスコープ内に[ScopedValue]が見つからなかったときは子から親のスコープへと再帰的に検索します。 - T ancestor([ - Object? name, - ]) { - final res = getAlreadyExistsScopedValue>( - name: name, - listen: true, - ) ?? - getAlreadyExistsScopedValue>( - name: name, - ); - assert( - res != null, - "Could not find $T. Please define $T in the element above.", - ); - return res!; - } -} diff --git a/packages/katana_scoped/lib/value/fetch.dart b/packages/katana_scoped/lib/value/fetch.dart index 404f0fcf3..c111783c7 100644 --- a/packages/katana_scoped/lib/value/fetch.dart +++ b/packages/katana_scoped/lib/value/fetch.dart @@ -1,9 +1,9 @@ part of 'value.dart'; -/// Provides an extension method for [Ref] to retrieve a [ScopedValue] that already exists. +/// Provides an extension method for [AppScopedValueOrAppRef] to retrieve a [ScopedValue] that already exists. /// -/// すでに存在している[ScopedValue]の取得を行うための[Ref]用の拡張メソッドを提供します。 -extension RefFetchExtensions on Ref { +/// すでに存在している[ScopedValue]の取得を行うための[AppScopedValueOrAppRef]用の拡張メソッドを提供します。 +extension RefFetchExtensions on AppScopedValueOrAppRef { @Deprecated( "[fetch] will no longer be available in the App scope. Instead, use [ref.page.ancestor] or [ref.widget.ancestor] and limit its use to page and widget scopes only. Appスコープでの[fetch]の利用はできなくなります。代わりに[ref.page.ancestor]や[ref.widget.ancestor]を利用し、ページやウィジェットスコープのみでの利用に限定してください。", ) @@ -40,3 +40,46 @@ extension RefHasPageFetchExtensions on RefHasPage { ); } } + +/// Provides an extension method for [PageOrWidgetScopedValueRef] to retrieve a [ScopedValue] that already exists in the page or widget scope. +/// +/// ページスコープやウィジェットスコープにすでに存在している[ScopedValue]の取得を行うための[PageOrWidgetScopedValueRef]用の拡張メソッドを提供します。 +extension PageScopedValueRefAncestorExtensions on PageOrWidgetScopedValueRef { + /// This is used to retrieve a [ScopedValue] already registered in [watch] or [cache] with the widget below it, etc. + /// + /// An error is returned when trying to retrieve a [ScopedValue] that is not registered in [watch] or [cache]. + /// + /// [ScopedValue] registered in [watch] and [ScopedValue] registered in [cache] are processed in this order. + /// + /// When [watch] returns a registered [ScopedValue], it will be associated with the widget and notify the user of the change. + /// + /// If there are multiple [ScopedValue] of the same type in the scope, specify [name]. + /// + /// [watch]や[cache]ですでに登録している[ScopedValue]をその下のウィジェット等で取得するために利用します。 + /// + /// [watch]や[cache]で登録されていない[ScopedValue]を取得しようとした時エラーが返されます。 + /// + /// [watch]で登録した[ScopedValue]、[cache]で登録した[ScopedValue]の順番で処理されます。 + /// + /// [watch]で登録した[ScopedValue]を返すときにウィジェットに関連付けて変更を通知するようにします。 + /// + /// そのスコープ内に同じ型の[ScopedValue]が複数存在する場合は[name]を指定してください。 + T fetch([ + Object? name, + ]) { + final res = getAlreadyExistsScopedValue>( + name: name, + listen: true, + ) ?? + getAlreadyExistsScopedValue>( + name: name, + ); + assert( + res != null, + "Could not find $T. Please define $T in the element above.", + ); + return res!; + } +} diff --git a/packages/katana_scoped/lib/value/value.dart b/packages/katana_scoped/lib/value/value.dart index a818e7d97..4ff9a3513 100644 --- a/packages/katana_scoped/lib/value/value.dart +++ b/packages/katana_scoped/lib/value/value.dart @@ -9,7 +9,6 @@ import 'package:flutter/widgets.dart'; // Project imports: import 'package:katana_scoped/katana_scoped.dart'; -part 'ancestor.dart'; part 'cache.dart'; part 'fetch.dart'; part 'on.dart'; diff --git a/packages/masamune/lib/router/router.dart b/packages/masamune/lib/router/router.dart index 3a226023b..e76e6d4b1 100644 --- a/packages/masamune/lib/router/router.dart +++ b/packages/masamune/lib/router/router.dart @@ -101,7 +101,7 @@ extension MasamuneRouterPageScopedValueRefExtensions on PageScopedValueRef { NestedAppRouter nestedRouter({ Object? name, }) { - final router = ancestor(name); + final router = fetch(name); return router; } }