Skip to content

Commit dc4f8b2

Browse files
committed
Update to latest version of elixirscript
1 parent 3e42ff2 commit dc4f8b2

File tree

10 files changed

+116
-109
lines changed

10 files changed

+116
-109
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ assets/node_modules
2323
# variables.
2424
/config/prod.secret.exs
2525
assets/js/build/
26+
/.elixir_ls

.tool-versions

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
erlang 20.0
2-
elixir 1.5.0-otp-20
3-
nodejs 8.2.0
1+
erlang 20.1
2+
elixir 1.6.0-otp-20
3+
nodejs 9.5.0

assets/.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"env",
55
{
66
"targets": {
7-
"browsers": ["last 2 versions", "safari >= 7"]
7+
"chrome": 52
88
},
99
"modules": false,
1010
"useBuiltIns": true

assets/js/app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ import '../css/app.css';
1919
// Local files can be imported directly using relative
2020
// paths "./socket" or full ones "web/static/js/socket".
2121
// import socket from "./socket"
22-
import Elixir from './build/elixirscript.build.js';
22+
import Main from './build/Elixir.Todo.Main.js';
2323

24-
Elixir.start(Elixir.Todo.Main, []);
24+
Main.start(Symbol.for('normal'), []);

lib/todo_frontend/data.ex

+40-27
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,63 @@ defmodule Todo.Data do
66
"""
77

88
def list() do
9-
Todo.Data.Http.fetch("/api/todo").then(fn(response) ->
9+
ElixirScript.Web.Window.fetch("/api/todo").then(fn response ->
1010
response.json()
11-
end).then(fn(todos) ->
12-
todos
13-
|> Enum.map(fn(x) -> %Todo.Todo{ id: x.id, completed: x.completed, title: x.title } end)
11+
end).then(fn todos ->
12+
todos
13+
|> Enum.map(fn x -> %Todo.Todo{id: x.id, completed: x.completed, title: x.title} end)
1414
|> Todo.Main.update()
15-
end).catch(fn(err) ->
16-
Todo.Data.Http.log(err)
15+
end).catch(fn err ->
16+
ElixirScript.Web.Console.log(err)
1717
end)
1818
end
1919

2020
def add(the_title) do
21-
Todo.Data.Http.fetch("/api/todo", ElixirScript.JS.map_to_object(%{
22-
"method" => "post",
23-
"headers" => %{
24-
"Content-type" => "application/json"
25-
},
26-
"body" => Todo.Data.Http.stringify(ElixirScript.JS.map_to_object(%{"title" => the_title}))
27-
})).then(fn(response) ->
21+
ElixirScript.Web.Window.fetch(
22+
"/api/todo",
23+
ElixirScript.JS.map_to_object(%{
24+
"method" => "post",
25+
"headers" => %{
26+
"Content-type" => "application/json"
27+
},
28+
"body" =>
29+
ElixirScript.Web.JSON.stringify(ElixirScript.JS.map_to_object(%{"title" => the_title}))
30+
})
31+
).then(fn response ->
2832
list()
29-
end).catch(fn(err) ->
30-
Todo.Data.Http.log(err)
33+
end).catch(fn err ->
34+
ElixirScript.Web.Console.log(err)
3135
end)
3236
end
3337

3438
def remove(id) do
35-
Todo.Data.Http.fetch("/api/todo/" <> id, ElixirScript.JS.map_to_object(%{ "method" => "delete" })).then(fn(response) ->
39+
ElixirScript.Web.Window.fetch(
40+
"/api/todo/" <> id,
41+
ElixirScript.JS.map_to_object(%{"method" => "delete"})
42+
).then(fn response ->
3643
list()
37-
end).catch(fn(err) ->
38-
Todo.Data.Http.log(err)
44+
end).catch(fn err ->
45+
ElixirScript.Web.Console.log(err)
3946
end)
4047
end
4148

4249
def update(id, completed) do
43-
Todo.Data.Http.fetch("/api/todo/" <> id, ElixirScript.JS.map_to_object(%{
44-
"method" => "put",
45-
"headers" => %{
46-
"Content-type" => "application/json"
47-
},
48-
"body" => Todo.Data.Http.stringify(ElixirScript.JS.map_to_object(%{ "completed" => completed }))
49-
})).then(fn(response) ->
50+
ElixirScript.Web.Window.fetch(
51+
"/api/todo/" <> id,
52+
ElixirScript.JS.map_to_object(%{
53+
"method" => "put",
54+
"headers" => %{
55+
"Content-type" => "application/json"
56+
},
57+
"body" =>
58+
ElixirScript.Web.JSON.stringify(
59+
ElixirScript.JS.map_to_object(%{"completed" => completed})
60+
)
61+
})
62+
).then(fn response ->
5063
list()
51-
end).catch(fn(err) ->
52-
Todo.Data.Http.log(err)
64+
end).catch(fn err ->
65+
ElixirScript.Web.Console.log(err)
5366
end)
5467
end
5568
end

lib/todo_frontend/data_http.ex

-12
This file was deleted.

lib/todo_frontend/document.ex

-10
This file was deleted.

lib/todo_frontend/main.ex

+26-20
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ defmodule Todo.Main do
2020
"""
2121

2222
def start(_, _) do
23-
Agent.start(&initial_state/0, [name: :state])
23+
Agent.start(&initial_state/0, name: :state)
2424
render()
2525
Todo.Data.list()
2626
end
@@ -30,7 +30,7 @@ defmodule Todo.Main do
3030
end
3131

3232
def render() do
33-
Agent.get(:state, fn(state) -> state end)
33+
Agent.get(:state, fn state -> state end)
3434
|> view
3535
|> ReactDOM.render("#app")
3636
end
@@ -42,51 +42,57 @@ defmodule Todo.Main do
4242
h1 do
4343
"todos"
4444
end
45-
input [
45+
46+
input(
4647
id: "new-todo",
4748
placeholder: "What needs to be done?",
4849
autoFocus: true,
49-
onKeyPress: fn(event, _) -> process_event(event) end
50-
]
50+
onKeyPress: fn event -> process_event(event) end
51+
)
5152
end
53+
5254
section id: "main" do
5355
ul id: "todo-list" do
54-
Enum.map(todos, fn(todo) ->
55-
{the_completed, checked} = if todo.completed do
56-
{"completed", "checked"}
57-
else
58-
{"", ""}
59-
end
56+
Enum.map(todos, fn todo ->
57+
{the_completed, checked} =
58+
if todo.completed do
59+
{"completed", "checked"}
60+
else
61+
{"", ""}
62+
end
6063

6164
li key: todo.id, className: the_completed do
6265
React.HTML.div className: "view" do
63-
input [
66+
input(
6467
className: "toggle",
6568
type: "checkbox",
6669
checked: todo.completed,
67-
onChange: fn(event) -> Todo.Data.update(todo.id, event.target.checked) end
68-
]
70+
onChange: fn event -> Todo.Data.update(todo.id, event.target.checked) end
71+
)
72+
6973
label do
7074
todo.title
7175
end
72-
button [
76+
77+
button(
7378
className: "destroy",
74-
onClick: fn(event, _) ->
79+
onClick: fn event ->
7580
Todo.Data.remove(todo.id)
7681
end
77-
]
82+
)
7883
end
7984
end
8085
end)
8186
end
8287
end
83-
footer id: "footer"
88+
89+
footer(id: "footer")
8490
end
8591
end
8692
end
8793

8894
def update(todos) do
89-
Agent.update(:state, fn(_) ->
95+
Agent.update(:state, fn _ ->
9096
todos
9197
end)
9298

@@ -98,7 +104,7 @@ defmodule Todo.Main do
98104
Todo.Data.add(event.target.value)
99105
ElixirScript.JS.mutate(event.target, "value", "")
100106
else
101-
Todo.Data.Http.log(event)
107+
ElixirScript.Web.Console.log(event)
102108
end
103109
end
104110
end

mix.exs

+29-24
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,51 @@ defmodule Todo.Mixfile do
22
use Mix.Project
33

44
def project do
5-
[app: :todo,
6-
version: "0.0.1",
7-
elixir: "~> 1.2",
8-
elixirc_paths: elixirc_paths(Mix.env),
9-
compilers: [:phoenix, :gettext] ++ Mix.compilers ++ [:elixir_script],
10-
build_embedded: Mix.env == :prod,
11-
start_permanent: Mix.env == :prod,
12-
deps: deps(),
13-
elixir_script: [
14-
input: [Todo.Main],
15-
output: "assets/js/build"
16-
]
5+
[
6+
app: :todo,
7+
version: "0.0.1",
8+
elixir: "~> 1.6",
9+
elixirc_paths: elixirc_paths(Mix.env()),
10+
compilers: [:phoenix, :gettext] ++ Mix.compilers() ++ [:elixir_script],
11+
build_embedded: Mix.env() == :prod,
12+
start_permanent: Mix.env() == :prod,
13+
deps: deps(),
14+
elixir_script: [
15+
input: [Todo.Main],
16+
output: "assets/js/build"
17+
]
1718
]
1819
end
1920

2021
# Configuration for the OTP application.
2122
#
2223
# Type `mix help compile.app` for more information.
2324
def application do
24-
[mod: {Todo, []},
25-
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext]]
25+
[
26+
mod: {Todo, []},
27+
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext]
28+
]
2629
end
2730

2831
# Specifies which paths to compile per environment.
2932
defp elixirc_paths(:test), do: ["lib", "test/support"]
30-
defp elixirc_paths(_), do: ["lib"]
33+
defp elixirc_paths(_), do: ["lib"]
3134

3235
# Specifies your project dependencies.
3336
#
3437
# Type `mix help deps` for examples and options.
3538
defp deps do
36-
[{:phoenix, "~> 1.3"},
37-
{:phoenix_pubsub, "~> 1.0"},
38-
{:phoenix_html, "~> 2.6"},
39-
{:phoenix_live_reload, "~> 1.0", only: :dev},
40-
{:gettext, "~> 0.11"},
41-
{:cowboy, "~> 1.0"},
42-
{:elixir_script, "~> 0.30"},
43-
{:fs, "~> 2.12", override: true},
44-
{:elixir_script_react, "~> 1.0.1-react"}
39+
[
40+
{:phoenix, "~> 1.3"},
41+
{:phoenix_pubsub, "~> 1.0"},
42+
{:phoenix_html, "~> 2.6"},
43+
{:phoenix_live_reload, "~> 1.0", only: :dev},
44+
{:gettext, "~> 0.11"},
45+
{:cowboy, "~> 1.0"},
46+
{:elixir_script, "~> 0.32.1"},
47+
{:fs, "~> 2.12", override: true},
48+
{:elixir_script_react, "~> 16.2"},
49+
{:elixir_script_web, "~> 0.2"}
4550
]
4651
end
4752
end

mix.lock

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
%{"cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
1+
%{
2+
"cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
23
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
3-
"elixir_script": {:hex, :elixir_script, "0.30.0", "c67b2d9b6cdfa432717f4bffa3f31f476ff5c5bf15cef59142c6a85e7089d530", [:mix], [{:estree, "~> 2.6", [hex: :estree, repo: "hexpm", optional: false]}], "hexpm"},
4-
"elixir_script_react": {:hex, :elixir_script_react, "1.0.1-react.15.6.1", "dc6f46a809100cb2c941e7b189b6626a1ec53889937dec53ff3006622d0bcc3e", [:mix], [{:elixir_script, "~> 0.30", [hex: :elixir_script, repo: "hexpm", optional: false]}], "hexpm"},
4+
"elixir_script": {:hex, :elixir_script, "0.32.1", "c97e753faf1dd8bc93244fec93d7c88c3a7eef85e2bad7eb3e014ba3f1e06931", [:mix], [{:estree, "~> 2.6", [hex: :estree, repo: "hexpm", optional: false]}], "hexpm"},
5+
"elixir_script_react": {:hex, :elixir_script_react, "16.2.0", "b1f1a12b01be3603a84c39e6d1cc544dc967ba835655d29072a249a960e973d1", [:mix], [{:elixir_script, "~> 0.32", [hex: :elixir_script, repo: "hexpm", optional: false]}], "hexpm"},
6+
"elixir_script_web": {:hex, :elixir_script_web, "0.2.0", "78e1c0191c8d3ddc4760dca3248967746a8c0b7d571d8fed773584dca968b9ee", [:mix], [{:elixir_script, "~> 0.32", [hex: :elixir_script, repo: "hexpm", optional: false]}], "hexpm"},
57
"estree": {:hex, :estree, "2.6.1", "0a17cc0e9e35315dc4fcd79d30a746b1f3e9ed654be6084ce882ab491165ae22", [:mix], [], "hexpm"},
8+
"file_system": {:hex, :file_system, "0.2.4", "f0bdda195c0e46e987333e986452ec523aed21d784189144f647c43eaf307064", [:mix], [], "hexpm"},
69
"fs": {:hex, :fs, "2.12.0", "ad631efacc9a5683c8eaa1b274e24fa64a1b8eb30747e9595b93bec7e492e25e", [:rebar3], [], "hexpm"},
7-
"gettext": {:hex, :gettext, "0.13.1", "5e0daf4e7636d771c4c71ad5f3f53ba09a9ae5c250e1ab9c42ba9edccc476263", [:mix], [], "hexpm"},
8-
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], [], "hexpm"},
9-
"phoenix": {:hex, :phoenix, "1.3.0", "1c01124caa1b4a7af46f2050ff11b267baa3edb441b45dbf243e979cd4c5891b", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
10-
"phoenix_html": {:hex, :phoenix_html, "2.10.3", "432dec9e04372eeb7a6dbf59a778cf43eb44518441932217371fa535f2bcfd80", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
11-
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.0.8", "4333f9c74190f485a74866beff2f9304f069d53f047f5fbb0fb8d1ee4c495f73", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2-rc", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
10+
"gettext": {:hex, :gettext, "0.15.0", "40a2b8ce33a80ced7727e36768499fc9286881c43ebafccae6bab731e2b2b8ce", [:mix], [], "hexpm"},
11+
"mime": {:hex, :mime, "1.2.0", "78adaa84832b3680de06f88f0997e3ead3b451a440d183d688085be2d709b534", [:mix], [], "hexpm"},
12+
"phoenix": {:hex, :phoenix, "1.3.2", "2a00d751f51670ea6bc3f2ba4e6eb27ecb8a2c71e7978d9cd3e5de5ccf7378bd", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
13+
"phoenix_html": {:hex, :phoenix_html, "2.11.0", "ead10dd1e36d5b8b5cc55642ba337832ec62617efd5765cddaa1a36c8b3891ca", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
14+
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.1.3", "1d178429fc8950b12457d09c6afec247bfe1fcb6f36209e18fbb0221bdfe4d41", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
1215
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.2", "bfa7fd52788b5eaa09cb51ff9fcad1d9edfeb68251add458523f839392f034c1", [:mix], [], "hexpm"},
13-
"plug": {:hex, :plug, "1.4.3", "236d77ce7bf3e3a2668dc0d32a9b6f1f9b1f05361019946aae49874904be4aed", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
16+
"plug": {:hex, :plug, "1.5.0", "224b25b4039bedc1eac149fb52ed456770b9678bbf0349cdd810460e1e09195b", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
1417
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
15-
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"}}
18+
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"},
19+
}

0 commit comments

Comments
 (0)