Skip to content

Commit 91d6bf0

Browse files
authored
Merge pull request #31 from geolessel/add-specs
chore: Add typespecs and deprecation attributes
2 parents 4be9020 + 4b7efa6 commit 91d6bf0

File tree

8 files changed

+30
-23
lines changed

8 files changed

+30
-23
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ install:
99
- mix deps.get
1010
- npm install
1111
elixir:
12-
- 1.4.2
12+
- 1.6.3
1313

1414
matrix:
1515
include:
16+
- elixir: 1.6
17+
- elixir: 1.5
1618
- elixir: 1.4
1719
- elixir: 1.3
18-
- elixir: 1.2

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies in `mix.exs`:
3030

3131
```elixir
3232
def deps do
33-
[{:react_phoenix, "~> 0.5.1"}]
33+
[{:react_phoenix, "~> 0.5.2"}]
3434
end
3535
```
3636

@@ -130,7 +130,7 @@ Once installed, you can use `react_component` in your views by:
130130

131131
1. Making sure that the component you'd like rendered is in the global namespace.
132132
You can do that in `app.js` like this (for example):
133-
133+
134134
```javascript
135135
import MyComponent from "./components/my_component"
136136
window.Components = {
@@ -151,7 +151,7 @@ Once installed, you can use `react_component` in your views by:
151151
<span id="my-react-span"><%= @react_html %></span>
152152
<%= ReactPhoenix.ClientSide.react_component("Components.Characters", %{people: people}, target_id: "my-react-span") %>
153153
```
154-
154+
155155
This will render a special `div` element in your html output that will then be recognized by the
156156
javascript helper as a div that should be turned into a React component. It will then render the
157157
named component in that `div` (or a different element specified by ID via the `target_id` option).
@@ -173,5 +173,5 @@ rendering is likely all you'll need for now.
173173

174174
This package is heavily inspired by the [react-rails](https://github.com/reactjs/react-rails) project.
175175

176-
For more detailed documentation, check out the hex docs at
176+
For more detailed documentation, check out the hex docs at
177177
[https://hexdocs.pm/react_phoenix](https://hexdocs.pm/react_phoenix)

lib/react_phoenix.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ defmodule ReactPhoenix do
99
As of v0.4.0, please use `ReactPhoenix.ClientSide.react_component/2` instead. Provided for backward
1010
compatability for versions < 0.4.0.
1111
"""
12+
@deprecated "Use ReactPhoenix.ClientSide.react_component"
1213
def react_component(name, props \\ %{}),
1314
do: ReactPhoenix.ClientSide.react_component(name, props)
1415

@@ -18,6 +19,7 @@ defmodule ReactPhoenix do
1819
As of v0.4.0, please use `ReactPhoenix.ClientSide.react_component/3` instead. Provided for backward
1920
compatability for versions < 0.4.0.
2021
"""
22+
@deprecated "Use ReactPhoenix.ClientSide.react_component"
2123
def react_component(name, props, opts),
2224
do: ReactPhoenix.ClientSide.react_component(name, props, opts)
2325
end

lib/react_phoenix/client_side.ex

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ defmodule ReactPhoenix.ClientSide do
2525
The resulting `<div>` tag is formatted specifically for the included javascript
2626
helper to then turn into your named React component.
2727
"""
28+
@spec react_component(name :: String.t()) :: Phoenix.HTML.safe()
2829
def react_component(name), do: react_component(name, %{})
2930

3031
@doc """
@@ -43,6 +44,7 @@ defmodule ReactPhoenix.ClientSide do
4344
The resulting `<div>` tag is formatted specifically for the included javascript
4445
helper to then turn into your named React component and then pass in the props specified.
4546
"""
47+
@spec react_component(name :: String.t(), props :: list | map) :: Phoenix.HTML.safe()
4648
def react_component(name, props) when is_list(props) do
4749
react_component(name, Enum.into(props, %{}))
4850
end
@@ -66,15 +68,17 @@ defmodule ReactPhoenix.ClientSide do
6668
6769
```
6870
<%= ReactPhoenix.ClientSide.react_component(
69-
"MyComponent",
70-
%{language: "elixir", awesome: true},
71-
target_id: "react-div"
71+
"MyComponent", # <- component name
72+
%{language: "elixir", awesome: true}, # <- props
73+
target_id: "react-div" # <- options
7274
) %>
7375
```
7476
7577
The resulting `<div>` tag is formatted specifically for the included javascript
7678
helper to then turn into your named React component and then pass in the props specified.
7779
"""
80+
@spec react_component(name :: String.t(), props :: map, opts :: [target_id: String.t()]) ::
81+
Phoenix.HTML.safe()
7882
def react_component(name, props, opts) when is_map(props) do
7983
props = Poison.encode!(props)
8084

mix.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
defmodule ReactPhoenix.Mixfile do
22
use Mix.Project
33

4-
@version "0.5.1"
4+
@version "0.5.2"
55
@source_url "https://github.com/geolessel/react-phoenix"
66

77
def project do
88
[
99
app: :react_phoenix,
1010
version: @version,
11-
elixir: "~> 1.2",
11+
elixir: "~> 1.3",
1212
build_embedded: Mix.env() == :prod,
1313
start_permanent: Mix.env() == :prod,
1414
package: package(),
@@ -32,6 +32,7 @@ defmodule ReactPhoenix.Mixfile do
3232
defp deps do
3333
[
3434
{:ex_doc, ">= 0.0.0", only: :dev},
35+
{:dialyxir, "~> 0.5", only: :dev},
3536
{:phoenix_html, "~> 2.9"},
3637
{:poison, "~> 2.2 or ~> 3.0"}
3738
]

mix.lock

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
%{"earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], []},
2-
"ex_doc": {:hex, :ex_doc, "0.15.1", "d5f9d588fd802152516fccfdb96d6073753f77314fcfee892b15b6724ca0d596", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
3-
"fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], []},
4-
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], []},
5-
"phoenix_html": {:hex, :phoenix_html, "2.9.3", "1b5a2122cbf743aa242f54dced8a4f1cc778b8bd304f4b4c0043a6250c58e258", [:mix], [{:plug, "~> 1.0", [hex: :plug, optional: false]}]},
6-
"plug": {:hex, :plug, "1.3.5", "7503bfcd7091df2a9761ef8cecea666d1f2cc454cbbaf0afa0b6e259203b7031", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]},
1+
%{
2+
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], []},
3+
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], []},
4+
"ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
5+
"mime": {:hex, :mime, "1.2.0", "78adaa84832b3680de06f88f0997e3ead3b451a440d183d688085be2d709b534", [:mix], []},
6+
"phoenix_html": {:hex, :phoenix_html, "2.11.0", "ead10dd1e36d5b8b5cc55642ba337832ec62617efd5765cddaa1a36c8b3891ca", [:mix], [{:plug, "~> 1.5", [hex: :plug, optional: false]}]},
7+
"plug": {:hex, :plug, "1.5.0", "224b25b4039bedc1eac149fb52ed456770b9678bbf0349cdd810460e1e09195b", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.1", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]},
78
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []},
8-
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []},
9-
"porcelain": {:hex, :porcelain, "2.0.3", "2d77b17d1f21fed875b8c5ecba72a01533db2013bd2e5e62c6d286c029150fdc", [:mix], []},
10-
"std_json_io_2": {:hex, :std_json_io_2, "0.2.0", "208ae14f548e662125136921269456e026c692535c1946b173fa7e4549f5aa23", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, optional: false]}, {:poison, "~> 3.0", [hex: :poison, optional: false]}, {:poolboy, "~> 1.5.1", [hex: :poolboy, optional: false]}, {:porcelain, "~> 2.0.3", [hex: :porcelain, optional: false]}]}}
9+
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-phoenix",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"scripts": {
55
"release": "node ./node_modules/babel-cli/bin/babel src/react_phoenix.js | node ./node_modules/uglify-js/bin/uglifyjs - --mangle --compress --output priv/js/react_phoenix.js"
66
},

0 commit comments

Comments
 (0)