-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
defmodule Observables.CombineLatestSilent do | ||
@moduledoc false | ||
use Observables.GenObservable | ||
|
||
# silent == :left or :right | ||
def init([left_initial, right_initial, silent]) do | ||
Logger.debug("CombineLatest: #{inspect(self())}") | ||
{:ok, {:left, left_initial, :right, right_initial, :silent, silent}} | ||
end | ||
|
||
def handle_event(value, state) do | ||
{:left, l, :right, r, :silent, s} = state | ||
|
||
case {value, l, r, s} do | ||
# No values yet. | ||
{{:left, vl}, nil, nil, _} -> | ||
{:novalue, {:left, vl, :right, nil, :silent, s}} | ||
|
||
{{:right, vr}, nil, nil, _} -> | ||
{:novalue, {:left, nil, :right, vr, :silent, s}} | ||
|
||
# Have one value, and got a newever version of that value. | ||
{{:left, vl}, _, nil, _} -> | ||
{:novalue, {:left, vl, :right, nil, :silent, s}} | ||
|
||
{{:right, vr}, nil, _, _} -> | ||
{:novalue, {:left, nil, :right, vr, :silent, s}} | ||
|
||
# Already have the other value. | ||
{{:left, vl}, nil, vr, :right} -> | ||
{:value, {vl, vr}, {:left, vl, :right, vr, :silent, s}} | ||
|
||
{{:left, vl}, nil, vr, :left} -> | ||
{:novalue, {:left, vl, :right, vr, :silent, s}} | ||
|
||
{{:right, vr}, vl, nil, :right} -> | ||
{:novalue, {:left, vl, :right, vr, :silent, s}} | ||
|
||
{{:right, vr}, vl, nil, :left} -> | ||
{:value, {vl, vr}, {:left, vl, :right, vr, :silent, s}} | ||
|
||
# We have a history for both, and now we got a new one. | ||
{{:left, vl}, _, vr, :left} -> | ||
{:novalue, {:left, vl, :right, vr, :silent, s}} | ||
|
||
{{:left, vl}, _, vr, :right} -> | ||
{:value, {vl, vr}, {:left, vl, :right, vr, :silent, s}} | ||
|
||
{{:right, vr}, vl, _, :left} -> | ||
{:value, {vl, vr}, {:left, vl, :right, vr, :silent, s}} | ||
|
||
{{:right, vr}, vl, _, :right} -> | ||
{:novalue, {:left, vl, :right, vr, :silent, s}} | ||
end | ||
end | ||
|
||
def handle_done(_pid, _state) do | ||
Logger.debug("#{inspect(self())}: combinelatest has one dead dependency, going on.") | ||
{:ok, :continue} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters