From b6b1831d65cb6f4a5ccf876907b48b2dc6589863 Mon Sep 17 00:00:00 2001 From: Adam Brodzinski Date: Sat, 31 Oct 2015 19:13:41 -0400 Subject: [PATCH] Update readme.md --- readme.md | 58 ++++++++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/readme.md b/readme.md index 8cb90c6..f871544 100644 --- a/readme.md +++ b/readme.md @@ -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 -
-

Hello World

-

Is ready: {state.isReady}

-
+ 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
-

Stateless Component

-

Is ready: { props.is_ready }

+

Name: { state.player_name }

+

Is selected: { props.is_selected }

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)