Przeglądaj źródła

combineLatest -> combine; Update documentation;

bjorn 10 lat temu
rodzic
commit
691b4a98eb
4 zmienionych plików z 14 dodań i 13 usunięć
  1. 5 4
      doc/README.md
  2. 1 1
      rx.lua
  3. 7 7
      tests/combine.lua
  4. 1 1
      tests/observable.lua

+ 5 - 4
doc/README.md

@@ -11,11 +11,11 @@ RxLua
   - [subscribe](#subscribeonnext-onerror-oncomplete)
   - [fromValue](#fromvaluevalue)
   - [fromRange](#fromrangeinitial-limit-step)
-  - [fromTable](#fromtabletable-iterator)
+  - [fromTable](#fromtabletable-iterator-keys)
   - [fromCoroutine](#fromcoroutinecoroutine)
   - [dump](#dumpname)
   - [changes](#changescomparator)
-  - [combineLatest](#combinelatestobservables-combinator)
+  - [combine](#combineobservables-combinator)
   - [compact](#compact)
   - [concat](#concatsources)
   - [distinct](#distinct)
@@ -162,7 +162,7 @@ Returns:
 
 ---
 
-#### `.fromTable(table, iterator)`
+#### `.fromTable(table, iterator, keys)`
 
 Creates an Observable that produces values from a table.
 
@@ -170,6 +170,7 @@ Arguments:
 
 - `table` (`table`) - The table used to create the Observable.
 - `[iterator=pairs]` (`function`) - An iterator used to iterate the table, e.g. pairs or ipairs.
+- `keys` (`boolean`) - Whether or not to also emit the keys of the table.
 
 Returns:
 
@@ -215,7 +216,7 @@ Returns:
 
 ---
 
-#### `:combineLatest(observables, combinator)`
+#### `:combine(observables, combinator)`
 
 Returns a new Observable that runs a combinator function on the most recent values from a set of Observables whenever any of them produce a new value. The results of the combinator function are produced by the new Observable.
 

+ 1 - 1
rx.lua

@@ -207,7 +207,7 @@ end
 -- @arg {function} combinator - A function that combines the latest result from each Observable and
 --                              returns a single value.
 -- @returns {Observable}
-function Observable:combineLatest(...)
+function Observable:combine(...)
   local sources = {...}
   local combinator = table.remove(sources)
   table.insert(sources, 1, self)

+ 7 - 7
tests/combineLatest.lua → tests/combine.lua

@@ -1,6 +1,6 @@
-describe('combineLatest', function()
+describe('combine', function()
   it('returns the observable it is called on if only the identity function is passed as an argument', function()
-    local observable = Rx.Observable.fromRange(1, 5):combineLatest(function(x) return x end)
+    local observable = Rx.Observable.fromRange(1, 5):combine(function(x) return x end)
     expect(observable).to.produce(1, 2, 3, 4, 5)
   end)
 
@@ -9,7 +9,7 @@ describe('combineLatest', function()
     local observableB = Rx.Observable.fromValue('b')
     local observableC = Rx.Observable.fromValue('c')
     local combinator = spy()
-    Rx.Observable.combineLatest(observableA, observableB, observableC, combinator):subscribe()
+    Rx.Observable.combine(observableA, observableB, observableC, combinator):subscribe()
     expect(combinator).to.equal({{'a', 'b', 'c'}})
   end)
 
@@ -17,7 +17,7 @@ describe('combineLatest', function()
     local observableA = Rx.Subject.create()
     local observableB = Rx.Subject.create()
     local onNext = spy()
-    Rx.Observable.combineLatest(observableA, observableB, function(a, b) return a + b end):subscribe(Rx.Observer.create(onNext))
+    Rx.Observable.combine(observableA, observableB, function(a, b) return a + b end):subscribe(Rx.Observer.create(onNext))
     expect(#onNext).to.equal(0)
     observableA:onNext(1)
     observableB:onNext(2)
@@ -30,7 +30,7 @@ describe('combineLatest', function()
     local observableA = Rx.Subject.create()
     local observableB = Rx.Subject.create()
     local complete = spy()
-    Rx.Observable.combineLatest(observableA, observableB, function() end):subscribe(nil, nil, complete)
+    Rx.Observable.combine(observableA, observableB, function() end):subscribe(nil, nil, complete)
 
     expect(#complete).to.equal(0)
     observableA:onNext(1)
@@ -47,13 +47,13 @@ describe('combineLatest', function()
     local observableA = Rx.Subject.create()
     local observableB = Rx.Subject.create()
     local errored = spy()
-    Rx.Observable.combineLatest(observableA, observableB, function() end):subscribe(nil, errored)
+    Rx.Observable.combine(observableA, observableB, function() end):subscribe(nil, errored)
     expect(#errored).to.equal(0)
     observableB:onError()
     expect(#errored).to.equal(1)
   end)
 
   it('should error if the combinator is absent', function()
-    expect(Rx.Observable.combineLatest(Rx.Observable.fromRange(1, 3)).subscribe).to.fail()
+    expect(Rx.Observable.combine(Rx.Observable.fromRange(1, 3)).subscribe).to.fail()
   end)
 end)

+ 1 - 1
tests/observable.lua

@@ -149,6 +149,6 @@ describe('Observable', function()
   end)
 
   dofile('tests/changes.lua')
-  dofile('tests/combineLatest.lua')
+  dofile('tests/combine.lua')
   dofile('tests/compact.lua')
 end)