Skip to content

Commit

Permalink
Encode nil (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella authored Dec 18, 2024
1 parent 4e7f0fc commit 62ca0d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/live_view_native/stylesheet/encoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ defmodule LiveViewNative.Stylesheet.Encoder do
def encode({name, value}, encoder) when is_atom(name),
do: :json.encode_map(%{{name, value}}, encoder)


def encode(nil, _encoder),
do: ~c(null)

def encode(atom, encoder) when is_atom(atom) do
cond do
Code.ensure_loaded?(atom) ->
Expand Down
7 changes: 7 additions & 0 deletions test/live_view_native/stylesheet/encoder_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule LiveViewNative.Stylesheet.EncoderTest do
use ExUnit.Case

test "nil" do
assert :json.encode(nil, &LiveViewNative.Stylesheet.Encoder.encode/2) == ~c(null)
end
end

0 comments on commit 62ca0d1

Please sign in to comment.