Skip to content

Commit

Permalink
优化 EventBus 单例实现 (LianjiaTech#43)
Browse files Browse the repository at this point in the history
* Theme: 优化单例实现,初步优化 BrnAllThemeConfig 属性获取不为 null

* refactor:优化theme,暴露非null引用

* theme:去除无用信息及优化部分代码

* theme:增加属性类型

* 优化修复 EventBus
  • Loading branch information
zhoujuanjuan authored and leftcoding committed Jan 1, 2022
1 parent 0b49c99 commit c854ab2
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions lib/src/utils/brn_event_bus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ class EventBus {

static EventBus? _instance;

factory EventBus.init() {
_instance = EventBus();
factory EventBus._() {
if(_instance == null) {
_instance = EventBus();
}
return _instance!;
}

static EventBus get instance {
if (_instance == null) {
EventBus.init();
}
return _instance!;
return EventBus._();
}

StreamController _streamController;
Expand All @@ -64,7 +63,7 @@ class EventBus {
/// resumed or cancelled. So it's usually better to just cancel and later
/// subscribe again (avoids memory leak).
///
Stream on<T>() {
Stream<T> on<T>() {
if (T == dynamic) {
return streamController.stream as Stream<T>;
}
Expand All @@ -80,19 +79,5 @@ class EventBus {
void destroy() {
_streamController.close();
}
static EventBus? _instance;

factory EventBus.init() {
if (_instance == null) {
_instance = EventBus();
}
return _instance!;
}

static EventBus get instance {
if (_instance == null) {
EventBus.init();
}
return _instance!;
}
}

0 comments on commit c854ab2

Please sign in to comment.