Skip to content

Commit 1ea6114

Browse files
committed
Got working with latest version of elixirscript master
1 parent 49d3b9a commit 1ea6114

File tree

14 files changed

+58
-24
lines changed

14 files changed

+58
-24
lines changed

.tool-versions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
erlang 20.0
2-
elixir ref-v1.5.0-rc.0
3-
nodejs 8.1.0
2+
elixir ref-v1.5.0-rc.1
3+
nodejs 8.1.0

mix.exs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ defmodule Todo.Mixfile do
1212
deps: deps(),
1313
elixir_script: [
1414
input: [Main],
15-
output: "web/static/js/build",
16-
js_modules: [
17-
{React, "react"},
18-
{ReactDOM, "react-dom"}
19-
]
15+
output: "web/static/js/build"
2016
]
2117
]
2218
end
@@ -43,7 +39,7 @@ defmodule Todo.Mixfile do
4339
{:phoenix_live_reload, "~> 1.0", only: :dev},
4440
{:gettext, "~> 0.11"},
4541
{:cowboy, "~> 1.0"},
46-
{:elixir_script, github: "elixirscript/elixirscript"},
42+
{:elixir_script, git: "git@github.com:elixirscript/elixirscript.git"},
4743
{:fs, "2.12.0", override: true}
4844
]
4945
end

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%{"cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [:make, :rebar], [{:cowlib, "~> 1.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
22
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
3-
"elixir_script": {:git, "https://github.com/elixirscript/elixirscript.git", "9f4630dbfcd5455a41eb94b6a757245fe6e76507", []},
3+
"elixir_script": {:git, "git@github.com:elixirscript/elixirscript.git", "b3277f8c01f20e9c2c00557a55af8b08f10f3857", []},
44
"estree": {:hex, :estree, "2.6.0", "86a301b0c355fa55c19e7ef9dceb1b1e983c6df526a2b7846818a38c258fc3fb", [:mix], [], "hexpm"},
55
"fs": {:hex, :fs, "2.12.0", "ad631efacc9a5683c8eaa1b274e24fa64a1b8eb30747e9595b93bec7e492e25e", [:rebar3], [], "hexpm"},
66
"gettext": {:hex, :gettext, "0.13.0", "daafbddc5cda12738bb93b01d84105fe75b916a302f1c50ab9fb066b95ec9db4", [:mix], [], "hexpm"},

priv/elixir_script/data/http.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
fetch: function(...args) {
3+
return fetch(...args);
4+
},
5+
stringify: JSON.stringify,
6+
log: console.log
7+
};

priv/elixir_script/document.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
getElementById: function(id) {
3+
return document.getElementById(id);
4+
}
5+
};

priv/elixir_script/react.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import React from 'react';
2+
export default React;

priv/elixir_script/react_dom.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
export default ReactDOM;

web/static/exjs/data.ex

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
defmodule Todo.Data do
22
def list() do
3-
JS.fetch("/api/todo").then(fn(response) ->
3+
Data.Http.fetch("/api/todo").then(fn(response) ->
44
response.json()
55
end).then(fn(todos) ->
66
todos
77
|> Enum.map(fn(x) -> %Todo.Models.Todo{ id: x.id, completed: x.completed, title: x.title } end)
88
|> Main.update()
99
end).catch(fn(err) ->
10-
:console.debug(err)
10+
Data.Http.log(err)
1111
end)
1212
end
1313

1414
def add(the_title) do
15-
JS.fetch("/api/todo", %{
15+
Data.Http.fetch("/api/todo", %{
1616
"method" => "post",
1717
"headers" => %{
1818
"Content-type" => "application/json"
1919
},
20-
"body" => JS.JSON.stringify(%{"title" => the_title})
20+
"body" => Data.Http.stringify(%{"title" => the_title})
2121
}).then(fn(response) ->
2222
list()
2323
end).catch(fn(err) ->
24-
JS.console.debug(err)
24+
Data.Http.log(err)
2525
end)
2626
end
2727

2828
def remove(id) do
29-
JS.fetch("/api/todo/" <> id, %{ "method" => "delete" }).then(fn(response) ->
29+
Data.Http.fetch("/api/todo/" <> id, %{ "method" => "delete" }).then(fn(response) ->
3030
list()
3131
end).catch(fn(err) ->
32-
JS.console.debug(err)
32+
Data.Http.log(err)
3333
end)
3434
end
3535

3636
def update(id, completed) do
37-
JS.fetch("/api/todo/" <> id, %{
37+
Data.Http.fetch("/api/todo/" <> id, %{
3838
"method" => "put",
3939
"headers" => %{
4040
"Content-type" => "application/json"
4141
},
42-
"body" => JS.JSON.stringify(%{ "completed" => completed })
42+
"body" => Data.Http.stringify(%{ "completed" => completed })
4343
}).then(fn(response) ->
4444
list()
4545
end).catch(fn(err) ->
46-
JS.console.debug(err)
46+
Data.Http.log(err)
4747
end)
4848
end
4949
end

web/static/exjs/data_http.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule Data.Http do
2+
use ElixirScript.FFI
3+
4+
foreign fetch(url)
5+
foreign fetch(url, init)
6+
foreign stringify(data)
7+
foreign log(data)
8+
end

web/static/exjs/document.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defmodule Document do
2+
use ElixirScript.FFI
3+
4+
foreign getElementById(id)
5+
end

0 commit comments

Comments
 (0)