-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathjs.ex
More file actions
108 lines (89 loc) · 2.13 KB
/
Copy pathjs.ex
File metadata and controls
108 lines (89 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
defmodule JS do
@moduledoc """
This module defines macros and functions which implement
JavaScript functionality that may not translate easily to
Elixir. For instance, creating a new object, or updating
an existing one.
"""
@doc """
Creates new JavaScript objects.
ex:
JS.new User, ["first_name", "last_name"]
"""
defmacro new(module, params)
@doc """
Updates an existing JavaScript object.
ex:
JS.update elem, %{"width" => 100}
"""
defmacro update(object, map)
@doc """
Updates an existing JavaScript object.
ex:
JS.update elem, "width", 100
"""
defmacro update(object, key, value)
@doc """
Returns the type of the given value
"""
defmacro typeof(value)
@doc """
Determines if value is an instance of type.
"""
defmacro instanceof(value, type)
@doc """
Throws the term given
"""
defmacro throw(term)
@doc """
Returns a reference to the global JavaScript object.
In browsers this would be window or self.
In node this would be the global object.
"""
def global() do
Bootstrap.Core.global()
end
@doc """
Defines a generator. This is compiled into a generator function in JavaScript.
defgen and defgenp are currently the only ways to use process in Elixirscript right now.
"""
defmacro defgen(call, expr \\ nil) do
quote do
def unquote(call), unquote(expr)
end
end
@doc """
Defines a private generator. This is compiled into a generator function in JavaScript.
"""
defmacro defgenp(call, expr \\ nil) do
quote do
defp unquote(call), unquote(expr)
end
end
@doc """
Determines if term is a generator
"""
def is_generator(term) do
term.constructor.name === "GeneratorFunction"
end
@doc """
Yields the current generator function
"""
defmacro yield()
@doc """
Yields the current generator function with the given term
"""
defmacro yield(term)
@doc """
Yields control to the given generator
"""
defmacro yield_to(gen)
@doc """
Creates a breakpoint for JavaScript debuggers to stop at
"""
defmacro debugger()
@doc """
The current JavaScript context
"""
defmacro this()
end