Gabriel Rohden

fix(num) Fix num issues with operator overloads

@@ -217,81 +217,75 @@ class RxBool extends _RxImpl<bool> { @@ -217,81 +217,75 @@ class RxBool extends _RxImpl<bool> {
217 } 217 }
218 } 218 }
219 219
220 -/// Base Rx class for `num` Types (`double` and `int`) as mostly share the same  
221 -/// operator overload, we centralize the common code here.  
222 -abstract class _BaseRxNum<T> extends _RxImpl<num> {  
223 - _BaseRxNum operator +(num val) {  
224 - subject.add(_value += val);  
225 - return this;  
226 - }  
227 -  
228 - _BaseRxNum operator -(num val) {  
229 - subject.add(_value -= val);  
230 - return this;  
231 - }  
232 -  
233 - _BaseRxNum operator /(num val) {  
234 - subject.add(_value /= val);  
235 - return this;  
236 - }  
237 -  
238 - _BaseRxNum operator *(num val) {  
239 - subject.add(_value *= val);  
240 - return this;  
241 - } 220 +/// Rx class for `num` Types (`double` and `int`) shared comparison operations
  221 +abstract class _RxNumComparators<T extends num> extends _RxImpl<T> {
  222 + bool operator <=(T other) => _value <= other;
242 223
243 - _BaseRxNum operator ~/(num val) {  
244 - subject.add(_value ~/ val);  
245 - return this;  
246 - } 224 + bool operator >=(T other) => _value >= other;
247 225
248 - _BaseRxNum operator %(num val) {  
249 - subject.add(_value % val);  
250 - return this;  
251 - } 226 + bool operator <(T other) => _value < other;
252 227
253 - bool operator <=(num other) => _value <= other;  
254 - bool operator >=(num other) => _value >= other;  
255 - bool operator <(num other) => _value < other;  
256 - bool operator >(num other) => _value > other; 228 + bool operator >(T other) => _value > other;
257 } 229 }
258 230
259 /// Rx class for `double` Type. 231 /// Rx class for `double` Type.
260 -class RxDouble extends _BaseRxNum<double> { 232 +class RxDouble extends _RxNumComparators<double> {
261 RxDouble([double initial]) { 233 RxDouble([double initial]) {
262 _value = initial; 234 _value = initial;
263 } 235 }
  236 +
  237 + double operator *(double val) => _value * val;
  238 +
  239 + double operator -(double val) => _value - val;
  240 +
  241 + double operator +(double val) => _value + val;
  242 +
  243 + double operator /(double val) => _value / val;
  244 +
  245 + double operator %(double val) => _value % val;
264 } 246 }
265 247
266 /// Rx class for `num` Type. 248 /// Rx class for `num` Type.
267 -class RxNum extends _BaseRxNum<num> { 249 +class RxNum extends _RxNumComparators<num> {
268 RxNum([num initial]) { 250 RxNum([num initial]) {
269 _value = initial; 251 _value = initial;
270 } 252 }
  253 +
  254 + num operator *(num val) => _value * val;
  255 +
  256 + num operator -(num val) => _value - val;
  257 +
  258 + num operator +(num val) => _value + val;
  259 +
  260 + num operator /(num val) => _value / val;
  261 +
  262 + num operator %(num val) => _value % val;
271 } 263 }
272 264
273 -/// Rx class for `String` Type.  
274 -class RxString extends _RxImpl<String> {  
275 - RxString([String initial]) { 265 +/// Rx class for `int` Type.
  266 +class RxInt extends _RxNumComparators<int> {
  267 + RxInt([int initial]) {
276 _value = initial; 268 _value = initial;
277 } 269 }
278 270
279 - RxString operator +(String val) {  
280 - subject.add(_value += val);  
281 - return this;  
282 - } 271 + int operator %(int val) => _value % val;
283 272
284 - RxString operator *(int val) {  
285 - subject.add(_value *= val);  
286 - return this;  
287 - } 273 + int operator *(int val) => _value * val;
  274 +
  275 + int operator -(int val) => _value - val;
  276 +
  277 + int operator +(int val) => _value + val;
  278 +
  279 + double operator /(int val) => _value / val;
288 } 280 }
289 281
290 -/// Rx class for `int` Type.  
291 -class RxInt extends _BaseRxNum<int> {  
292 - RxInt([int initial]) { 282 +/// Rx class for `String` Type.
  283 +class RxString extends _RxImpl<String> {
  284 + RxString([String initial]) {
293 _value = initial; 285 _value = initial;
294 } 286 }
  287 +
  288 + String operator +(String val) => _value + val;
295 } 289 }
296 290
297 /// Foundation class used for custom `Types` outside the common native Dart 291 /// Foundation class used for custom `Types` outside the common native Dart