Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamBrodzinski committed Oct 31, 2015
1 parent 5b92895 commit b6b1831
Showing 1 changed file with 23 additions and 35 deletions.
58 changes: 23 additions & 35 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,58 +91,46 @@ Enum.reject([1, 2, 3, 4], (n) => n % 2 == 0) [1, 2, 3, 4] |> Enum.reject((n
```


#### Plays well with React
We've added a bit of sugar for creating React render function so that you don't have to wrap it in parens and use a `return` keyword. It must be the *last* function in the module for this to work.

#### Pattern Matching Coming Soon!
Pattern matching can eliminate the use of if statements and can really clean up code. This is on the backlog but PRs are welcome!
```elixir
# must use ::ReactStateComponent to module name to activate React sugar

defmodule Complex::ReactStateComponent do
def getInitialState do
return { isReady: false }
defmodule MyUtils do
def count([]) do
return 0
end

def render(props, state) do
<div>
<h1>Hello World</h1>
<p>Is ready: {state.isReady}</p>
</div>
def count([head|tail]) do
return 1 + count(tail)
end
end

```


#### Plays well with React
We've added a bit of sugar for creating React stateless components so that you don't have to wrap it in parens and use a `return` keyword. It must be the *last* function in the module for this to work.


```elixir
# however stateless React components work best!
# using ::ReactComponent adds render sugar (no parens and return needed)
# Stateless React components work great in RedScript modules. We've added optional
# sugar to add parens and a return in the component function. Just add ::ReactComponent
# to the module name and place the component first

defmodule MySimple::ReactComponent do
defp handle_click(e) do
alert("Hello World")
end

def Simple(props) do
defmodule TodoItem::ReactComponent do
def component(props) do
<div>
<h1>Stateless Component</h1>
<p>Is ready: { props.is_ready }</p>
<h1>Name: { state.player_name }</h1>
<p>Is selected: { props.is_selected }</p>
<input type='button' onClick={ handle_click } />
</div>
end
end
```

#### Pattern Matching Coming Soon!
Pattern matching can eliminate the use of if statements and can really clean up code. This is on the backlog but PRs are welcome!
```elixir
defmodule MyUtils do
def count([]) do
return 0
end

def count([head|tail]) do
return 1 + count(tail)
defp handle_click(e) do
alert("Hello World")
end
end

```


##### [More syntax:](https://github.com/AdamBrodzinski/RedScript/blob/master/spec.md)

0 comments on commit b6b1831

Please sign in to comment.