-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from emanuel-braz/develop
Release 0.3.0
- Loading branch information
Showing
19 changed files
with
1,003 additions
and
533 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Flutter Analyze | ||
|
||
on: | ||
push: | ||
branches: [ develop ] | ||
pull_request: | ||
branches: [ develop, master, release/* ] | ||
types: [opened, synchronize, reopened, ready_for_review] | ||
|
||
jobs: | ||
build: | ||
if: github.event.pull_request.draft == false | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: subosito/flutter-action@v1 | ||
with: | ||
flutter-version: '2.8.1' | ||
channel: 'stable' | ||
- name: Install dependencies | ||
run: flutter pub get | ||
# Issue opened in flutter repo, not fixed yet https://github.com/flutter/flutter/issues/7274#issuecomment-934241151 | ||
# - name: Run Flutter analyze | ||
# run: flutter analyze lib | ||
- name: Run Flutter tests | ||
run: flutter test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
on: | ||
pull_request: | ||
branches: | ||
- "release/*" | ||
|
||
jobs: | ||
pull-request: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: auto-pr-release-develop | ||
uses: repo-sync/pull-request@v2 | ||
with: | ||
source_branch: ${{ github.head_ref }} | ||
destination_branch: "develop" | ||
pr_title: ":robot: ${{github.event.pull_request.title}}" | ||
pr_body: "${{github.event.pull_request.body}}" | ||
pr_template: "" | ||
pr_reviewer: "" | ||
pr_assignee: "" | ||
pr_label: "auto-pr" | ||
pr_milestone: "" | ||
pr_draft: true | ||
pr_allow_empty: true | ||
github_token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
lib/src/controllers/app_event/micro_app_event_controller.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// ignore_for_file: cancel_subscriptions | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_micro_app/flutter_micro_app.dart'; | ||
import 'package:flutter_micro_app/src/services/native_service.dart'; | ||
|
||
import 'micro_app_event_helper.dart'; | ||
|
||
/// [MicroAppEventController] | ||
class MicroAppEventController { | ||
final String _channel = Constants.channelAppEvents; | ||
final StreamController<MicroAppEvent> _controller = | ||
StreamController.broadcast(); | ||
late MicroAppNativeService _microAppNativeService; | ||
late MicroAppEventHelper _handlerRegisterHelper; | ||
|
||
/// Used to listen all micro app events | ||
MicroAppEventSubscription get onEvent => _controller.stream.listen; | ||
|
||
/// Can be used to filter events and listen to app events, anywhere | ||
Stream<MicroAppEvent> get stream => _controller.stream; | ||
bool get hasSubscribers => _controller.hasListener; | ||
bool get hasHandlers => _handlers.isNotEmpty; | ||
|
||
final Map<MicroAppEventHandler, StreamSubscription<MicroAppEvent>> _handlers = | ||
{}; | ||
|
||
/// get all handlers and subscriptions availables | ||
Map<MicroAppEventHandler, StreamSubscription<MicroAppEvent>> get handlers => | ||
_handlers; | ||
|
||
/// Factory instance | ||
factory MicroAppEventController() => instance; | ||
|
||
/// MicroAppController instance | ||
static MicroAppEventController instance = MicroAppEventController._(); | ||
MicroAppEventController._() { | ||
_handlerRegisterHelper = MicroAppEventHelper(); | ||
_microAppNativeService = MicroAppNativeService(_channel, | ||
methodCallHandler: (MethodCall call) async { | ||
_controller | ||
.add(MicroAppEvent(name: call.method, payload: call.arguments)); | ||
}); | ||
} | ||
|
||
/// ⚠️ It is used only for unit tests purposes | ||
factory MicroAppEventController.$testOnlyPurpose() => | ||
MicroAppEventController._(); | ||
|
||
/// [MicroAppEvent] | ||
void emit(MicroAppEvent event) { | ||
if (MicroAppPreferences.config.nativeEventsEnabled) { | ||
_microAppNativeService.emit( | ||
Constants.methodMicroAppEvent, event.toString()); | ||
} | ||
_controller.add(event); | ||
} | ||
|
||
/// register handler | ||
StreamSubscription<MicroAppEvent>? registerHandler<T>( | ||
MicroAppEventHandler? handler) { | ||
if (handler == null) return null; | ||
final subscription = | ||
_handlerRegisterHelper.registerHandler(stream, handler); | ||
_handlers.putIfAbsent(handler, () => subscription); | ||
return subscription; | ||
} | ||
|
||
/// pauseAllHandlers | ||
void pauseAllHandlers() => | ||
_handlerRegisterHelper.pauseAllSubscriptions(_handlers); | ||
|
||
/// resumeAllHandlers | ||
void resumeAllHandlers() => | ||
_handlerRegisterHelper.resumeAllSubscriptions(_handlers); | ||
|
||
/// unregisterAllHandlers | ||
Future<void> unregisterAllHandlers() => | ||
_handlerRegisterHelper.unregisterAllSubscriptions(_handlers); | ||
|
||
/// unregisterHandler | ||
Future<void> unregisterHandler({String? id, List<String>? channels}) => | ||
_handlerRegisterHelper.unregisterSubscription(_handlers, | ||
id: id, channels: channels); | ||
|
||
/// hasHandler | ||
bool hasHandler({String? id, List<String>? channels}) => | ||
_handlerRegisterHelper | ||
.findHandlerEntries(handlers, id: id, channels: channels) | ||
.isNotEmpty; | ||
|
||
/// dispose controller (do not dispose this, if there is not a very specific situation case) | ||
void dispose() { | ||
_controller.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import '../../../flutter_micro_app.dart'; | ||
|
||
/// [MicroAppEventHandler] | ||
class MicroAppEventHandler<T> extends EventChannelsEquatable { | ||
final String? id; | ||
final MicroAppEventOnEvent onEvent; | ||
final MicroAppEventOnDone? onDone; | ||
final MicroAppEventOnError? onError; | ||
final bool? cancelOnError; | ||
final bool distinct; | ||
|
||
const MicroAppEventHandler(this.onEvent, | ||
{this.onDone, | ||
this.onError, | ||
this.cancelOnError, | ||
List<String> channels = const [], | ||
this.id, | ||
this.distinct = true}) | ||
: super(channels); | ||
|
||
@override | ||
List<Object?> get props => | ||
[onEvent, onDone, onError, cancelOnError, channels, id, distinct]; | ||
} |
Oops, something went wrong.