Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 52255e5

Browse files
author
Barrie Hadfield
committed
with exceptions
1 parent be7ddab commit 52255e5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

source/_components.html.erb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
class CodeMirror < React::Component::Base
44
param :code, type: String
55
define_state :output_code
6+
define_state :error_message
67
before_mount do
78
state.output_code! params.code
9+
state.error_message! ""
810
end
911
after_mount do
1012
@editor = `CodeMirror(document.getElementById("code"), {
@@ -19,11 +21,21 @@ class CodeMirror < React::Component::Base
1921
end
2022
render(DIV) do
2123
div(id: 'code')
24+
p { state.error_message }
2225
p { state.output_code }
2326
end
2427

2528
def on_change
26-
state.output_code! Opal.compile `#{@editor}.getValue()`
29+
state.error_message! ""
30+
compiled_code = Opal.compile `#{@editor}.getValue()`
31+
state.output_code! compiled_code
32+
`eval(#{compiled_code})`
33+
rescue Exception => e
34+
@time_out = after(0.5) do
35+
# Element[mount_node].render { div.playgroundError { e.message } }
36+
state.error_message! e.message
37+
state.output_code! ""
38+
end
2739
end
2840

2941
end

0 commit comments

Comments
 (0)