aboutsummaryrefslogtreecommitdiffstats
path: root/alv
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-05-11 17:24:51 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:23:21 +0000
commit4ca20944892bebc0ddac7aa23ed8abef5d537209 (patch)
treefe1f4de29ec578ddc7c226739287796fc9b70353 /alv
parentmake <num! 4> == <num= 4> (diff)
downloadalive-4ca20944892bebc0ddac7aa23ed8abef5d537209.tar.gz
alive-4ca20944892bebc0ddac7aa23ed8abef5d537209.zip
make EvtStreams carry a single value
Diffstat (limited to 'alv')
-rw-r--r--alv/result/evt.moon21
1 files changed, 9 insertions, 12 deletions
diff --git a/alv/result/evt.moon b/alv/result/evt.moon
index ad4c102..a89aa74 100644
--- a/alv/result/evt.moon
+++ b/alv/result/evt.moon
@@ -16,15 +16,16 @@ class EvtStream extends Result
--- get the sequence of current events (if any).
--
- -- Returns `events` if `dirty`, or an empty table otherwise.
+ -- Returns `value` if `dirty`, or `nil` otherwise.
-- Asserts `@type == type` if `type` is given.
--
-- @tparam[opt] type.Type type the type to check for
-- @tparam[optchain] string msg message to throw if type don't match
- -- @treturn {any,...} `events`
+ -- @treturn ?any `value`
unwrap: (type, msg) =>
assert type == @type, msg or "#{@} is not a #{type}" if type
- if @dirty! then @events else {}
+ @value
+ if @dirty! then @value
--- create a mutable copy of this stream.
--
@@ -37,8 +38,7 @@ class EvtStream extends Result
__call: (...) => @unwrap ...
__tostring: =>
- events = table.concat [@type\pp e for e in *@events], ' '
- "<#{@type}#{@metatype} #{events}>"
+ "<#{@type}#{@metatype} #{if @dirty then @type\pp @value else 'nil'}>"
--- the type of this Result's value.
-- @tfield type.Type type
@@ -65,15 +65,13 @@ class EvtStream extends Result
--- push an event value into the stream.
--
-- Marks this stream as dirty for the remainder of the current tick.
- add: (event) =>
- if not @dirty!
- @events = {}
-
+ set: (event) =>
+ assert not @dirty!, "#{@} is already dirty!"
@updated = COPILOT.T
- table.insert @events, event
+ @value = event
--- the wrapped Lua value.
- -- @tfield {any,...} events
+ -- @tfield any value
--- static functions
-- @section static
@@ -84,7 +82,6 @@ class EvtStream extends Result
-- @tparam type.Type type the type
new: (type) =>
super type
- @events = {}
{
:EvtStream