added json support to Rx
resolves the value (for native types) or "toJson()" in custom classes.
Showing
1 changed file
with
6 additions
and
0 deletions
| 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; | 
| @@ -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,9 @@ class Rx<T> extends _RxImpl<T> { | @@ -285,6 +288,9 @@ class Rx<T> extends _RxImpl<T> { | ||
| 285 | Rx([T initial]) { | 288 | Rx([T initial]) { | 
| 286 | _value = initial; | 289 | _value = initial; | 
| 287 | } | 290 | } | 
| 291 | + | ||
| 292 | + @override | ||
| 293 | + dynamic toJson() => (value as dynamic)?.toJson(); | ||
| 288 | } | 294 | } | 
| 289 | 295 | ||
| 290 | extension StringExtension on String { | 296 | extension StringExtension on String { | 
- 
Please register or login to post a comment