Skip to content

Commit

Permalink
exists method added
Browse files Browse the repository at this point in the history
  • Loading branch information
t0uh33d1 committed Mar 31, 2023
1 parent fce39d5 commit 940bdd0
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 54 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@

- added example
- all methods are now static

## 1.1.0

- added exists method to check if a cubit instance exists
- all methods are now static
101 changes: 63 additions & 38 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,64 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
url: "https://pub.dev"
source: hosted
version: "2.9.0"
version: "2.10.0"
bloc:
dependency: transitive
description:
name: bloc
url: "https://pub.dartlang.org"
sha256: "658a5ae59edcf1e58aac98b000a71c762ad8f46f1394c34a52050cafb3e11a80"
url: "https://pub.dev"
source: hosted
version: "8.1.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.1"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
version: "1.3.0"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
url: "https://pub.dev"
source: hosted
version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
url: "https://pub.dev"
source: hosted
version: "1.16.0"
version: "1.17.1"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
url: "https://pub.dev"
source: hosted
version: "1.0.5"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
flutter:
Expand All @@ -66,14 +74,16 @@ packages:
dependency: "direct main"
description:
name: flutter_bloc
url: "https://pub.dartlang.org"
sha256: "434951eea948dbe87f737b674281465f610b8259c16c097b8163ce138749a775"
url: "https://pub.dev"
source: hosted
version: "8.1.2"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
url: "https://pub.dev"
source: hosted
version: "2.0.1"
flutter_test:
Expand All @@ -87,61 +97,69 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.0"
version: "1.1.0"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.4"
version: "0.6.7"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
sha256: c94db23593b89766cda57aab9ac311e3616cf87c6fa4e9749df032f66f30dcb8
url: "https://pub.dev"
source: hosted
version: "0.12.12"
version: "0.12.14"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
url: "https://pub.dev"
source: hosted
version: "0.2.0"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
sha256: "12307e7f0605ce3da64cf0db90e5fcab0869f3ca03f76be6bb2991ce0a55e82b"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
version: "1.9.0"
nested:
dependency: transitive
description:
name: nested
url: "https://pub.dartlang.org"
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
url: "https://pub.dev"
source: hosted
version: "1.8.2"
version: "1.8.3"
provider:
dependency: transitive
description:
name: provider
url: "https://pub.dartlang.org"
sha256: cdbe7530b12ecd9eb455bdaa2fcb8d4dad22e80b8afb4798b41479d5ce26847f
url: "https://pub.dev"
source: hosted
version: "6.0.5"
sky_engine:
Expand All @@ -153,51 +171,58 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
url: "https://pub.dev"
source: hosted
version: "1.9.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.1.1"
version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
sha256: "6182294da5abf431177fccc1ee02401f6df30f766bc6130a0852c6b6d7ee6b2d"
url: "https://pub.dev"
source: hosted
version: "0.4.14"
version: "0.4.18"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
sdks:
dart: ">=2.19.0-255.0.dev <3.0.0"
dart: ">=2.19.0 <4.0.0"
flutter: ">=1.16.0"
4 changes: 2 additions & 2 deletions ios/Flutter/Generated.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ FLUTTER_APPLICATION_PATH=/Users/codewave/Desktop/projects/packages/get_cubit
COCOAPODS_PARALLEL_CODE_SIGN=true
FLUTTER_TARGET=lib/main.dart
FLUTTER_BUILD_DIR=build
FLUTTER_BUILD_NAME=0.0.1
FLUTTER_BUILD_NUMBER=0.0.1
FLUTTER_BUILD_NAME=1.0.0
FLUTTER_BUILD_NUMBER=1.0.0
EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386
EXCLUDED_ARCHS[sdk=iphoneos*]=armv7
DART_OBFUSCATION=false
Expand Down
4 changes: 2 additions & 2 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export "FLUTTER_APPLICATION_PATH=/Users/codewave/Desktop/projects/packages/get_c
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=0.0.1"
export "FLUTTER_BUILD_NUMBER=0.0.1"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1.0.0"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
Expand Down
3 changes: 3 additions & 0 deletions lib/src/get_cubit_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class GetCubit {
}
}

static bool exists<T extends Cubit>({String? id}) =>
_mp.containsKey(_getKey(T, id));

/// generate the key to link instance in the HashMap
static String _getKey(Type t, String? id) {
return id == null ? t.toString() : t.toString() + id;
Expand Down
4 changes: 2 additions & 2 deletions macos/Flutter/ephemeral/Flutter-Generated.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ FLUTTER_ROOT=/Users/codewave/dev/flutter
FLUTTER_APPLICATION_PATH=/Users/codewave/Desktop/projects/packages/get_cubit
COCOAPODS_PARALLEL_CODE_SIGN=true
FLUTTER_BUILD_DIR=build
FLUTTER_BUILD_NAME=0.0.1
FLUTTER_BUILD_NUMBER=0.0.1
FLUTTER_BUILD_NAME=1.0.0
FLUTTER_BUILD_NUMBER=1.0.0
DART_OBFUSCATION=false
TRACK_WIDGET_CREATION=true
TREE_SHAKE_ICONS=false
Expand Down
4 changes: 2 additions & 2 deletions macos/Flutter/ephemeral/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export "FLUTTER_ROOT=/Users/codewave/dev/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/codewave/Desktop/projects/packages/get_cubit"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=0.0.1"
export "FLUTTER_BUILD_NUMBER=0.0.1"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1.0.0"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: get_cubit
description: A package to help handle Cubit instances across the app.
version: 1.0.0
version: 1.1.0
homepage: https://github.com/t0uh33d/get_cubit

environment:
Expand Down
37 changes: 30 additions & 7 deletions test/get_cubit_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:get_cubit/get_cubit.dart';
Expand Down Expand Up @@ -41,11 +42,17 @@ void main() {
for (int i = 0; i < 10; i++) {
GetCubit.put(CounterCubit(i: i), id: '$i');
}
print(CounterCubit().getAllInstanceIds());
if (kDebugMode) {
print(CounterCubit().getAllInstanceIds());
}
GetCubit.delete<CounterCubit>(id: '5');
print(CounterCubit().getAllInstanceIds());
if (kDebugMode) {
print(CounterCubit().getAllInstanceIds());
}
CounterCubit().deleteAllInstances();
print(CounterCubit().getAllInstanceIds());
if (kDebugMode) {
print(CounterCubit().getAllInstanceIds());
}
});

test('instance deletion test', () {
Expand All @@ -54,9 +61,21 @@ void main() {
GetCubit.put(CounterCubit(i: 2), id: 'id_2');
GetCubit.put(CounterCubit(i: 3), id: 'id_3');

print(CounterCubit().getAllInstanceIds());
if (kDebugMode) {
print(CounterCubit().getAllInstanceIds());
}
GetCubit.deleteAllCubitInstances<CounterCubit>();
print(CounterCubit().getAllInstanceIds());
if (kDebugMode) {
print(CounterCubit().getAllInstanceIds());
}
});

test('check if a cubit exists', () {
GetCubit.put(CounterCubit(i: 0), id: 'id_0');
GetCubit.put(CounterCubit(i: 1), id: 'id_1');
if (kDebugMode) {
print(GetCubit.exists<CounterCubit>(id: 'id_0'));
}
});

test('flusher test', () {
Expand All @@ -67,16 +86,20 @@ void main() {
GetCubit.put(CounterCubit(i: 0), id: 'id_0');
GetCubit.put(CounterCubit(i: 1), id: 'id_1');
GetCubit.put(CounterCubit(i: 2), id: 'id_2');
if (kDebugMode) {
print(GetCubit.getAllRegisteredInstanceKeys);
}

print(GetCubit.getAllRegisteredInstanceKeys);
GetCubit.flush(flushExclusions: [
FlushExclusions(cubitType: CubitA),
FlushExclusions(
cubitType: CounterCubit,
id: 'id_0',
excludeAllRelatedInstances: false),
]);
print(GetCubit.getAllRegisteredInstanceKeys);
if (kDebugMode) {
print(GetCubit.getAllRegisteredInstanceKeys);
}
});
}

Expand Down

0 comments on commit 940bdd0

Please sign in to comment.