Skip to content

Commit

Permalink
Version 0.3.2:
Browse files Browse the repository at this point in the history
- dartfmt style fixes
  • Loading branch information
Vladimir Minkin authored and Vladimir Minkin committed Jun 22, 2020
1 parent 5210f32 commit 3fb35a6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 38 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.3.2
- dartfmt style fixes

## 0.3.1
- WireListener has first parameter Wire that holds signal, scope, listener itself and replies

Expand Down
16 changes: 8 additions & 8 deletions lib/src/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ part of wire;
///
typedef WireDataListener = void Function(dynamic value);

class WireData
{
class WireData {
Function _onRemove;
final _listeners = <Object, List<WireDataListener>>{};

Expand All @@ -31,20 +30,21 @@ class WireData
WireData(this._key, this._onRemove);

void refresh() {
_listeners.forEach((scope, listeners) =>
listeners.forEach((func) => func(_value)));
_listeners.forEach(
(scope, listeners) => listeners.forEach((func) => func(_value)));
}

void remove() {
_onRemove(_key);
_onRemove = null;

_key = null;
value = null; // null value means remove element that listening on change (unsubscribe)
// null value means remove element that listening on change (unsubscribe)
value = null;

while(_listeners.isNotEmpty) {
while (_listeners.isNotEmpty) {
var value = _listeners.remove(_listeners.keys.last);
while(value.isNotEmpty) {
while (value.isNotEmpty) {
value.removeLast();
}
}
Expand All @@ -66,4 +66,4 @@ class WireData
}
return this;
}
}
}
20 changes: 7 additions & 13 deletions lib/src/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ part of wire;
/// Github: https://github.com/DQvsRA
/// License: APACHE LICENSE, VERSION 2.0
///
class WireLayer
{
class WireLayer {
final Map<int, Wire> _wireByHash = <int, Wire>{};
final Map<String, List<int>> _hashesBySignal = <String, List<int>>{};

Wire add(Wire wire)
{
Wire add(Wire wire) {
var hash = wire.hash;
var signal = wire.signal;

Expand All @@ -26,12 +24,10 @@ class WireLayer
return wire;
}

bool send(String signal, [data])
{
bool send(String signal, [data]) {
var noSubscribers = true;

if (_hashesBySignal.containsKey(signal))
{
if (_hashesBySignal.containsKey(signal)) {
var WiresToRemove = <Wire>[];
_hashesBySignal[signal].forEach((hash) {
var wire = _wireByHash[hash];
Expand All @@ -46,8 +42,7 @@ class WireLayer
return noSubscribers;
}

bool remove(String signal, [Object scope, Function listener])
{
bool remove(String signal, [Object scope, Function listener]) {
var exists = _hashesBySignal.containsKey(signal);
if (exists) {
var toRemove = <Wire>[];
Expand All @@ -66,11 +61,10 @@ class WireLayer
///
/// Exclude a Wire based on an signal.
///
/// @param The Wire to remove.
/// @param The Wire to remove.
/// @return If there is no hashes (no Wires) for that SIGNAL stop future perform
///
bool _removeSignal(Wire wire)
{
bool _removeSignal(Wire wire) {
var hash = wire.hash;
var signal = wire.signal;

Expand Down
25 changes: 13 additions & 12 deletions lib/src/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class Wire
///
int replies = 0;

Wire(Object scope, String signal, WireListener listener, int replies)
{
Wire(Object scope, String signal, WireListener listener, int replies) {
_scope = scope;
_signal = signal;
_listener = listener;
Expand All @@ -74,8 +73,7 @@ class Wire
/// Public Methods
///
///**********************************************************************************************************
void transfer(data)
{
void transfer(data) {
// Call a listener in this Wire.
_listener(this, data);
}
Expand All @@ -85,17 +83,20 @@ class Wire
/// Public Static Methods - API
///
///**********************************************************************************************************
static Wire add(Object scope, String signal, WireListener listener, {int replies = 0})
{ return _LAYER.add(Wire(scope, signal, listener, replies)); }
static Wire add(Object scope, String signal, WireListener listener,
{int replies = 0}) {
return _LAYER.add(Wire(scope, signal, listener, replies));
}

static bool send(String signal, [data])
{ return _LAYER.send(signal, data); }
static bool send(String signal, [data]) {
return _LAYER.send(signal, data);
}

static bool remove(String signal, {Object scope, WireListener listener})
{ return _LAYER.remove(signal, scope, listener); }
static bool remove(String signal, {Object scope, WireListener listener}) {
return _LAYER.remove(signal, scope, listener);
}

static WireData data(String param, [dynamic value])
{
static WireData data(String param, [dynamic value]) {
var wd = _STORE.get(param);
if (value != null) wd.value = value is Function ? value(wd.value) : value;
return wd;
Expand Down
5 changes: 2 additions & 3 deletions lib/src/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ part of wire;
/// Github: https://github.com/DQvsRA
/// License: APACHE LICENSE, VERSION 2.0
///
class WireStore
{
class WireStore {
final Map<String, WireData> _map = <String, WireData>{};
dynamic get(String key) {
if (!_map.containsKey(key)) {
Expand All @@ -15,4 +14,4 @@ class WireStore

return _map[key];
}
}
}
2 changes: 1 addition & 1 deletion lib/wire.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
library wire;

export 'src/main.dart';
export 'src/main.dart';
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: wire
description: Wire is a pub/sub library, event bus with data container, utilize only String key
version: 0.3.1
version: 0.3.2
homepage: https://github.com/DQvsRA/Wire

environment:
Expand Down

0 comments on commit 3fb35a6

Please sign in to comment.