Jonny Borges
Committed by GitHub

Merge pull request #560 from roipeker/master

added json support to Rx
1 import 'dart:async'; 1 import 'dart:async';
2 import 'dart:collection'; 2 import 'dart:collection';
  3 +
3 import '../rx_core/rx_interface.dart'; 4 import '../rx_core/rx_interface.dart';
4 5
5 RxInterface getObs; 6 RxInterface getObs;
@@ -22,7 +23,7 @@ class _RxImpl<T> implements RxInterface<T> { @@ -22,7 +23,7 @@ class _RxImpl<T> implements RxInterface<T> {
22 /// ``` 23 /// ```
23 /// 24 ///
24 /// WARNING: still WIP, needs testing! 25 /// WARNING: still WIP, needs testing!
25 - _RxImpl<T> operator >>(T val) { 26 + _RxImpl<T> operator <<(T val) {
26 subject.add(value = val); 27 subject.add(value = val);
27 return this; 28 return this;
28 } 29 }
@@ -102,6 +103,8 @@ class _RxImpl<T> implements RxInterface<T> { @@ -102,6 +103,8 @@ class _RxImpl<T> implements RxInterface<T> {
102 @override 103 @override
103 String toString() => value.toString(); 104 String toString() => value.toString();
104 105
  106 + dynamic toJson() => value;
  107 +
105 /// This equality override works for _RxImpl instances and the internal values. 108 /// This equality override works for _RxImpl instances and the internal values.
106 @override 109 @override
107 bool operator ==(dynamic o) { 110 bool operator ==(dynamic o) {
@@ -285,6 +288,11 @@ class Rx<T> extends _RxImpl<T> { @@ -285,6 +288,11 @@ class Rx<T> extends _RxImpl<T> {
285 Rx([T initial]) { 288 Rx([T initial]) {
286 _value = initial; 289 _value = initial;
287 } 290 }
  291 +
  292 + // TODO: Look for a way to throw the Exception with proper details when the
  293 + // value [T] doesn't implement toJson().
  294 + @override
  295 + dynamic toJson() => (value as dynamic)?.toJson();
288 } 296 }
289 297
290 extension StringExtension on String { 298 extension StringExtension on String {