Skip to content

Commit d876a8a

Browse files
committed
Updated to work with latest version of ElixirScript in master
1 parent d6540be commit d876a8a

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ defmodule Todo.Mixfile do
3939
{:phoenix_live_reload, "~> 1.0", only: :dev},
4040
{:gettext, "~> 0.11"},
4141
{:cowboy, "~> 1.0"},
42-
{:elixir_script, git: "[email protected]:elixirscript/elixirscript.git", ref: "b3277f8c01f20e9c2c00557a55af8b08f10f3857"},
42+
{:elixir_script, git: "[email protected]:elixirscript/elixirscript.git", ref: "4d40ad36f9dedb2bd6793aafc2e5553f4a4cbb92"},
4343
{:fs, "2.12.0", override: true}
4444
]
4545
end

priv/elixir_script/data/http.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export default {
22
fetch: function(...args) {
33
return fetch(...args);
44
},
5-
stringify: JSON.stringify,
5+
stringify: function(map) {
6+
return JSON.stringify(map);
7+
},
68
log: console.log
79
};

priv/elixir_script/react.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
import React from 'react';
2-
export default React;
2+
3+
function mapToObject(map) {
4+
const object = {};
5+
6+
for ([key, value] of map.entries()) {
7+
if (value instanceof Map) {
8+
object[key] = mapToObject(value);
9+
} else {
10+
object[key] = value;
11+
}
12+
}
13+
14+
return object;
15+
}
16+
17+
function createElement(tag, attributes, elements) {
18+
const props = mapToObject(attributes);
19+
return React.createElement(tag, props, ...elements);
20+
}
21+
22+
export default {
23+
createElement
24+
};

web/static/exjs/data.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,35 @@ defmodule Todo.Data do
1212
end
1313

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

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

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

web/static/exjs/main.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
defmodule Main do
22
use ReactUI
33

4-
defp process_event(%{} = event) do
4+
defp process_event(event) do
55
if event.which == 13 do
66
Todo.Data.add(event.target.value)
7-
ElixirScript.JS.mutate(event.target, %{"value" => ""})
7+
ElixirScript.JS.mutate(event.target, "value", "")
88
else
99
Data.Http.log(event)
1010
end

web/static/exjs/react_ui.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule ReactUI do
2121
{ inner, attributes } = do_tag(inner, attrs)
2222

2323
quote do
24-
React.createElement(unquote(tag), unquote(attributes), unquote_splicing(inner))
24+
React.createElement(unquote(tag), unquote(attributes), unquote(inner))
2525
end
2626
end
2727

@@ -32,7 +32,7 @@ defmodule ReactUI do
3232
{ inner, attributes } = do_tag(inner, attributes)
3333

3434
quote do
35-
React.createElement(unquote(tag), unquote(attributes), unquote_splicing(inner))
35+
React.createElement(unquote(tag), unquote(attributes), unquote(inner))
3636
end
3737
end
3838
end

0 commit comments

Comments
 (0)