Browse Source

Add Subject.value;

bjorn 10 years ago
parent
commit
e9ecdea883
2 changed files with 10 additions and 2 deletions
  1. 5 1
      doc/README.md
  2. 5 1
      rx.lua

+ 5 - 1
doc/README.md

@@ -424,10 +424,14 @@ Subjects function both as an Observer and as an Observable. Subjects inherit all
 
 ---
 
-#### `.create()`
+#### `.create(value)`
 
 Creates a new Subject.
 
+Arguments:
+
+- `value` (`*`) - The initial value.
+
 Returns:
 
 - `Subject`

+ 5 - 1
rx.lua

@@ -662,9 +662,11 @@ local Subject = setmetatable({}, Observable)
 Subject.__index = Subject
 
 --- Creates a new Subject.
+-- @arg {*} value - The initial value.
 -- @returns {Subject}
-function Subject.create()
+function Subject.create(value)
   local self = {
+    value = value,
     observers = {}
   }
 
@@ -682,6 +684,8 @@ end
 --- Pushes a value to the Subject. It will be broadcasted to all Observers.
 -- @arg {*} value
 function Subject:onNext(value)
+  self.value = value
+
   for i = 1, #self.observers do
     self.observers[i]:onNext(value)
   end