Sfoglia il codice sorgente

Observable.changes -> Observable.distinctUntilChanged;

bjorn 9 anni fa
parent
commit
253c926d3b
5 ha cambiato i file con 12 aggiunte e 12 eliminazioni
  1. 2 2
      doc/README.md
  2. 1 1
      rx.lua
  3. 1 1
      src/observable.lua
  4. 7 7
      tests/distinctUntilChanged.lua
  5. 1 1
      tests/observable.lua

+ 2 - 2
doc/README.md

@@ -17,7 +17,7 @@ RxLua
   - [fromTable](#fromtabletable-iterator-keys)
   - [fromTable](#fromtabletable-iterator-keys)
   - [fromCoroutine](#fromcoroutinecoroutine)
   - [fromCoroutine](#fromcoroutinecoroutine)
   - [dump](#dumpname-formatter)
   - [dump](#dumpname-formatter)
-  - [changes](#changescomparator)
+  - [distinctUntilChanged](#distinctuntilchangedcomparator)
   - [combine](#combineobservables-combinator)
   - [combine](#combineobservables-combinator)
   - [compact](#compact)
   - [compact](#compact)
   - [concat](#concatsources)
   - [concat](#concatsources)
@@ -213,7 +213,7 @@ Subscribes to this Observable and prints values it produces.
 
 
 ---
 ---
 
 
-#### `:changes(comparator)`
+#### `:distinctUntilChanged(comparator)`
 
 
 Returns an Observable that only produces values from the original if they are different from the previous value.
 Returns an Observable that only produces values from the original if they are different from the previous value.
 
 

+ 1 - 1
rx.lua

@@ -206,7 +206,7 @@ end
 -- the previous value.
 -- the previous value.
 -- @arg {function} comparator - A function used to compare 2 values. If unspecified, == is used.
 -- @arg {function} comparator - A function used to compare 2 values. If unspecified, == is used.
 -- @returns {Observable}
 -- @returns {Observable}
-function Observable:changes(comparator)
+function Observable:distinctUntilChanged(comparator)
   comparator = comparator or util.eq
   comparator = comparator or util.eq
 
 
   return Observable.create(function(observer)
   return Observable.create(function(observer)

+ 1 - 1
src/observable.lua

@@ -121,7 +121,7 @@ end
 -- the previous value.
 -- the previous value.
 -- @arg {function} comparator - A function used to compare 2 values. If unspecified, == is used.
 -- @arg {function} comparator - A function used to compare 2 values. If unspecified, == is used.
 -- @returns {Observable}
 -- @returns {Observable}
-function Observable:changes(comparator)
+function Observable:distinctUntilChanged(comparator)
   comparator = comparator or util.eq
   comparator = comparator or util.eq
 
 
   return Observable.create(function(observer)
   return Observable.create(function(observer)

+ 7 - 7
tests/changes.lua → tests/distinctUntilChanged.lua

@@ -1,35 +1,35 @@
-describe('changes', function()
+describe('distinctUntilChanged', function()
   it('produces an error if its parent errors', function()
   it('produces an error if its parent errors', function()
     local observable = Rx.Observable.fromValue(''):map(function(x) return x() end)
     local observable = Rx.Observable.fromValue(''):map(function(x) return x() end)
     expect(observable.subscribe).to.fail()
     expect(observable.subscribe).to.fail()
-    expect(observable:changes().subscribe).to.fail()
+    expect(observable:distinctUntilChanged().subscribe).to.fail()
   end)
   end)
 
 
   describe('with the default comparator', function()
   describe('with the default comparator', function()
     it('produces a value if it is the first value or different from the previous', function()
     it('produces a value if it is the first value or different from the previous', function()
-      local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs):changes()
+      local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs):distinctUntilChanged()
       expect(observable).to.produce(1, 3, 1, 4, 5)
       expect(observable).to.produce(1, 3, 1, 4, 5)
     end)
     end)
 
 
     it('produces the first value if it is nil', function()
     it('produces the first value if it is nil', function()
-      local observable = Rx.Observable.fromValue(nil):changes()
+      local observable = Rx.Observable.fromValue(nil):distinctUntilChanged()
       expect(observable).to.produce({{}})
       expect(observable).to.produce({{}})
     end)
     end)
 
 
     it('produces multiple onNext arguments but only uses the first argument to check for equality', function()
     it('produces multiple onNext arguments but only uses the first argument to check for equality', function()
-      local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs, true):changes()
+      local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs, true):distinctUntilChanged()
       expect(observable).to.produce({{1, 1}, {3, 3}, {1, 4}, {4, 5}, {5, 6}})
       expect(observable).to.produce({{1, 1}, {3, 3}, {1, 4}, {4, 5}, {5, 6}})
     end)
     end)
   end)
   end)
 
 
   describe('with a custom comparator', function()
   describe('with a custom comparator', function()
     it('produces a value if it is the first value or the comparator returns false when passed the previous value and the current value', function()
     it('produces a value if it is the first value or the comparator returns false when passed the previous value and the current value', function()
-      local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs):changes(function(x, y) return x % 2 == y % 2 end)
+      local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs):distinctUntilChanged(function(x, y) return x % 2 == y % 2 end)
       expect(observable).to.produce(1, 4, 5)
       expect(observable).to.produce(1, 4, 5)
     end)
     end)
 
 
     it('produces the first value if it is nil', function()
     it('produces the first value if it is nil', function()
-      local observable = Rx.Observable.fromValue(nil):changes(function(x, y) return true end)
+      local observable = Rx.Observable.fromValue(nil):distinctUntilChanged(function(x, y) return true end)
       expect(observable).to.produce({{}})
       expect(observable).to.produce({{}})
     end)
     end)
   end)
   end)

+ 1 - 1
tests/observable.lua

@@ -150,11 +150,11 @@ describe('Observable', function()
   describe('dump', function()
   describe('dump', function()
   end)
   end)
 
 
-  dofile('tests/changes.lua')
   dofile('tests/combine.lua')
   dofile('tests/combine.lua')
   dofile('tests/compact.lua')
   dofile('tests/compact.lua')
   dofile('tests/concat.lua')
   dofile('tests/concat.lua')
   dofile('tests/distinct.lua')
   dofile('tests/distinct.lua')
+  dofile('tests/distinctUntilChanged.lua')
   dofile('tests/filter.lua')
   dofile('tests/filter.lua')
   dofile('tests/find.lua')
   dofile('tests/find.lua')
   dofile('tests/first.lua')
   dofile('tests/first.lua')