diff --git a/lib/kino/vega_lite.ex b/lib/kino/vega_lite.ex index 9b1cda4..ce506ff 100644 --- a/lib/kino/vega_lite.ex +++ b/lib/kino/vega_lite.ex @@ -12,8 +12,7 @@ defmodule Kino.VegaLite do |> Vl.mark(:line) |> Vl.encode_field(:x, "x", type: :quantitative) |> Vl.encode_field(:y, "y", type: :quantitative) - |> Kino.VegaLite.new() - |> Kino.render() + |> Kino.VegaLite.render() for i <- 1..300 do point = %{x: i / 10, y: :math.sin(i / 10)} @@ -52,6 +51,18 @@ defmodule Kino.VegaLite do ) end + @doc """ + Renders and returns a new kino with the given VegaLite definition. + + It is equivalent to: + + vega_lite |> Kino.VegaLite.new() |> Kino.render() + """ + @spec render(VegaLite.t()) :: t() + def render(vl) when is_struct(vl, VegaLite) do + vl |> new() |> Kino.render() + end + @doc """ Appends a single data point to the graphic dataset. @@ -145,6 +156,7 @@ defmodule Kino.VegaLite do The callback is run for the first time immediately upon registration. """ + @deprecated "Use Kino.listen/3 instead" @spec periodically(t(), pos_integer(), term(), (term() -> {:cont, term()} | :halt)) :: :ok def periodically(kino, interval_ms, acc, fun) do Kino.JS.Live.cast(kino, {:periodically, interval_ms, acc, fun}) diff --git a/test/kino/vega_lite_test.exs b/test/kino/vega_lite_test.exs index 8034e1a..6719c0c 100644 --- a/test/kino/vega_lite_test.exs +++ b/test/kino/vega_lite_test.exs @@ -93,26 +93,6 @@ defmodule Kino.VegaLiteTest do assert_broadcast_event(kino, "push", %{data: [], dataset: nil, window: 0}) end - test "periodically/4 evaluates the given callback in background until stopped" do - kino = start_kino() - - parent = self() - - Kino.VegaLite.periodically(kino, 1, 1, fn n -> - send(parent, {:ping, n}) - - if n < 2 do - {:cont, n + 1} - else - :halt - end - end) - - assert_receive {:ping, 1} - assert_receive {:ping, 2} - refute_receive {:ping, 3}, 5 - end - defp start_kino() do Vl.new() |> Vl.mark(:point)