From 23d0ab2105218659f9881d266f87e6c72b668c34 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Thu, 21 Dec 2017 15:15:47 -0500 Subject: [PATCH] 1.1.1 --- CHANGELOG.md | 4 ++ README.md | 20 ++---- lib/base_websocket_client.dart | 123 ++++++--------------------------- pubspec.yaml | 2 +- test/service/common.dart | 2 +- 5 files changed, 33 insertions(+), 118 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3daafa79..5440cb9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,6 @@ +# 1.1.1 +* Deprecated `unwrap`. +* Service streams now pump out `e.data`, rather than the actual event. + # 1.1.0+1 * Added `unwrap`. \ No newline at end of file diff --git a/README.md b/README.md index b97af397..3f09a41e 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ main() async { var Cars = app.service("api/cars"); - Cars.onCreated.listen((e) => print("New car: ${e.data}")); + Cars.onCreated.listen((car) => print("New car: $car")); // Happens asynchronously Cars.create({"brand": "Toyota"}); @@ -148,10 +148,9 @@ main() async { var Cars = app.service("api/cars", type: Car); - Cars.onCreated.listen((e) { + Cars.onCreated.listen((Car car) { // Automatically deserialized into a car :) - Car car = e.data; - + // // I just bought a new 2016 Toyota Camry! print("I just bought a new $car!"); }); @@ -161,15 +160,4 @@ main() async { // Authenticate a WebSocket, if you were not already authenticated... app.authenticateViaJwt(''); -} -``` -**Unwrapping Events** -In several cases, it may be cumbersome or inconsistent to handle events -as `WebSocketEvent`s. Call `unwrap` to receive a `Service` that returns the underlying `data` -objects. - -```dart -foo() async { - var unwrapped = app.service('api/todos').unwrap(); -} -``` \ No newline at end of file +} \ No newline at end of file diff --git a/lib/base_websocket_client.dart b/lib/base_websocket_client.dart index 5ff956d6..4dd793fe 100644 --- a/lib/base_websocket_client.dart +++ b/lib/base_websocket_client.dart @@ -240,39 +240,39 @@ class WebSocketsService extends Service { final StreamController _onAllEvents = new StreamController(); - final StreamController _onIndexed = - new StreamController(); - final StreamController _onRead = - new StreamController(); - final StreamController _onCreated = - new StreamController(); - final StreamController _onModified = - new StreamController(); - final StreamController _onUpdated = - new StreamController(); - final StreamController _onRemoved = - new StreamController(); + final StreamController _onIndexed = + new StreamController(); + final StreamController _onRead = + new StreamController(); + final StreamController _onCreated = + new StreamController(); + final StreamController _onModified = + new StreamController(); + final StreamController _onUpdated = + new StreamController(); + final StreamController _onRemoved = + new StreamController(); /// Fired on all events. Stream get onAllEvents => _onAllEvents.stream; /// Fired on `index` events. - Stream get onIndexed => _onIndexed.stream; + Stream get onIndexed => _onIndexed.stream; /// Fired on `read` events. - Stream get onRead => _onRead.stream; + Stream get onRead => _onRead.stream; /// Fired on `created` events. - Stream get onCreated => _onCreated.stream; + Stream get onCreated => _onCreated.stream; /// Fired on `modified` events. - Stream get onModified => _onModified.stream; + Stream get onModified => _onModified.stream; /// Fired on `updated` events. - Stream get onUpdated => _onUpdated.stream; + Stream get onUpdated => _onUpdated.stream; /// Fired on `removed` events. - Stream get onRemoved => _onRemoved.stream; + Stream get onRemoved => _onRemoved.stream; WebSocketsService(this.socket, this.app, this.path, {this.deserializer}) { listen(); @@ -306,7 +306,7 @@ class WebSocketsService extends Service { app.onServiceEvent.listen((map) { if (map.containsKey(path)) { var event = map[path]; - var transformed = transformEvent(event); + var transformed = transformEvent(event).data; _onAllEvents.add(event); @@ -389,8 +389,9 @@ class WebSocketsService extends Service { return null; } - /// Returns a wrapper that queries this service, but fires the `data` of `WebSocketEvent`s, rather than the events themselves. - Service unwrap() => new _WebSocketsDataService(this); + /// No longer necessary. + @deprecated + Service unwrap() => this; } /// Contains a dynamic Map of [WebSocketEvent] streams. @@ -410,82 +411,4 @@ class WebSocketExtraneousEventHandler { return _events[index].stream; } -} - -class _WebSocketsDataService extends Service { - final WebSocketsService service; - - Stream _onIndexed, _onRead, _onCreated, _onModified, _onUpdated, _onRemoved; - - _WebSocketsDataService(this.service); - - getData(WebSocketEvent e) => e.data; - - @override - Future remove(id, [Map params]) { - return service.remove(id, params); - } - - @override - Future update(id, data, [Map params]) { - return service.update(id, data, params); - } - - @override - Future modify(id, data, [Map params]) { - return service.modify(id, data, params); - } - - @override - Future create(data, [Map params]) { - return service.create(data, params); - } - - @override - Future read(id, [Map params]) { - return service.read(id, params); - } - - @override - Future index([Map params]) { - return service.index(params); - } - - @override - Future close() async {} - - @override - Angel get app { - return service.app; - } - - @override - Stream get onRemoved { - return _onRemoved ??= service.onRemoved.map(getData); - } - - @override - Stream get onUpdated { - return _onUpdated ??= service.onUpdated.map(getData); - } - - @override - Stream get onModified { - return _onModified ??= service.onModified.map(getData); - } - - @override - Stream get onCreated { - return _onCreated ??= service.onCreated.map(getData); - } - - @override - Stream get onRead { - return _onRead ??= service.onRead.map(getData); - } - - @override - Stream get onIndexed { - return _onIndexed ??= service.onIndexed.map(getData); - } -} +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index fd545daf..60129c58 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: angel_websocket description: WebSocket plugin for Angel. environment: sdk: ">=1.19.0" -version: 1.1.0+1 +version: 1.1.1 author: Tobe O homepage: https://github.com/angel-dart/angel_websocket dependencies: diff --git a/test/service/common.dart b/test/service/common.dart index 9e30ab79..4e633106 100644 --- a/test/service/common.dart +++ b/test/service/common.dart @@ -21,7 +21,7 @@ class TodoService extends TypedService { } testIndex(BaseWebSocketClient client) async { - var Todos = client.service('api/todos').unwrap(); + var Todos = client.service('api/todos'); Todos.index(); var indexed = await Todos.onIndexed.first;