diff --git a/README.md b/README.md
index 80942982..31a4700d 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,10 @@
-[](https://heroku.com/deploy)
# React Tutorial
-This is the React comment box example from [the React tutorial](http://facebook.github.io/react/docs/tutorial.html).
+This are the examples from [the React tutorial](http://facebook.github.io/react/docs/tutorial.html).
## To use
-There are several simple server implementations included. They all serve static files from `public/` and handle requests to `comments.json` to fetch or add data. Start a server with one of the following:
-
### Node
```sh
@@ -15,43 +12,5 @@ npm install
node server.js
```
-### Python
-
-```sh
-pip install -r requirements.txt
-python server.py
-```
-
-### Haskell
-
-```sh
-cabal sandbox init
-cabal install --only-dependencies
-ghc Server.hs
-./Server
-```
-
-### Ruby
-```sh
-ruby server.rb
-```
-
-### PHP
-```sh
-php server.php
-```
-
-### Go
-```sh
-go run server.go
-```
-
-### Lua
-
-```sh
-go get github.com/xyproto/algernon
-# or brew install algernon
-algernon server.lua
-```
-
-And visit . Try opening multiple tabs!
+And visit .
+Try opening multiple tabs! try changing and saving the 'comments.json' while server is running! Check the browser again!
diff --git a/Server.hs b/Server.hs
deleted file mode 100644
index 577622f8..00000000
--- a/Server.hs
+++ /dev/null
@@ -1,62 +0,0 @@
--- This file provided by Facebook is for non-commercial testing and evaluation
--- purposes only. Facebook reserves all rights not expressly granted.
---
--- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
--- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
--- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
--- FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
--- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
--- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
-
-{-# LANGUAGE OverloadedStrings #-}
-
-module Main (main) where
-
-import Web.Scotty
-
-import Control.Monad (mzero)
-import Control.Monad.Trans
-import Network.Wai.Middleware.Static
-import Network.Wai.Middleware.RequestLogger (logStdoutDev)
-import Data.ByteString.Lazy (readFile, writeFile, fromStrict)
-import qualified Data.ByteString as BS (readFile)
-import Prelude hiding (readFile, writeFile)
-import Data.Aeson hiding (json)
-import Data.Text
-import Data.Maybe (fromJust)
-
-data Comment = Comment {
- commentText :: Text,
- author :: Text
- } deriving (Eq, Show, Ord)
-
-instance FromJSON Comment where
- parseJSON (Object v) = Comment <$>
- v .: "text" <*>
- v .: "author"
- parseJSON _ = mzero
-
-instance ToJSON Comment where
- toJSON (Comment ctext author) = object ["text" .= ctext, "author" .= author]
-
-
-main :: IO ()
-main = scotty 3000 $ do
-
- middleware $ staticPolicy (noDots >-> addBase "public")
- middleware logStdoutDev
-
- get "/" $ file "./public/index.html"
-
- get "/comments.json" $ do
- comments <- liftIO $ readFile "comments.json"
- json $ fromJust $ (decode comments :: Maybe [Comment])
-
- post "/comments.json" $ do
- comments <- liftIO $ BS.readFile "comments.json"
- let jsonComments = fromJust $ (decode $ fromStrict comments :: Maybe [Comment])
- author <- param "author"
- comment <- param "text"
- let allComments = jsonComments ++ [Comment comment author]
- liftIO $ writeFile "comments.json" (encode allComments)
- json allComments
diff --git a/app.json b/app.json
deleted file mode 100644
index aa3e6afd..00000000
--- a/app.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "name": "React Tutorial Server",
- "description": "Code from the React tutorial",
- "keywords": [ "react", "reactjs", "tutorial" ],
- "repository": "https://github.com/reactjs/react-tutorial",
- "logo": "https://facebook.github.io/react/img/logo.svg",
- "website": "http://facebook.github.io/react/docs/tutorial.html",
- "success_url": "/",
- "env" : {
- "BUILDPACK_URL": "https://github.com/heroku/heroku-buildpack-nodejs.git"
- }
-}
-
diff --git a/comments.json b/comments.json
index 61f5ef60..25d99c4e 100644
--- a/comments.json
+++ b/comments.json
@@ -6,5 +6,33 @@
{
"author": "Paul O’Shannessy",
"text": "React is *great*!"
+ },
+ {
+ "author": "sasas",
+ "text": "asasas"
+ },
+ {
+ "author": "aaaa",
+ "text": "aaaa"
+ },
+ {
+ "author": "aaaa111",
+ "text": "aaaa"
+ },
+ {
+ "author": "aaaa222",
+ "text": "aaaa"
+ },
+ {
+ "author": "aaaa3333",
+ "text": "aaaa"
+ },
+ {
+ "author": "aaaa4444",
+ "text": "aaaa"
+ },
+ {
+ "author": "dssfsf",
+ "text": "sfdsfsf"
}
-]
+]
\ No newline at end of file
diff --git a/package.json b/package.json
index e7491981..afd88a5b 100644
--- a/package.json
+++ b/package.json
@@ -14,7 +14,7 @@
},
"repository": {
"type": "git",
- "url": "https://github.com/reactjs/react-tutorial.git"
+ "url": "https://github.com/flado/react-tutorial.git"
},
"keywords": [
"react",
@@ -24,9 +24,9 @@
],
"author": "petehunt",
"bugs": {
- "url": "https://github.com/reactjs/react-tutorial/issues"
+ "url": "https://github.com/flado/react-tutorial/issues"
},
- "homepage": "https://github.com/reactjs/react-tutorial",
+ "homepage": "https://github.com/flado/react-tutorial",
"engines" : {
"node" : "0.12.x"
}
diff --git a/public/comments-index.html b/public/comments-index.html
new file mode 100644
index 00000000..8a8bb442
--- /dev/null
+++ b/public/comments-index.html
@@ -0,0 +1,16 @@
+
+
+
+
diff --git a/public/scripts/productTableExample.js b/public/scripts/productTableExample.js
new file mode 100644
index 00000000..646414bf
--- /dev/null
+++ b/public/scripts/productTableExample.js
@@ -0,0 +1,128 @@
+
+var FilterableProductTable = React.createClass({
+ getInitialState: function() {
+ return { filterText: '', inStockOnly: false }
+ },
+ handleUserInput: function(txt, stockOnly) {
+ this.setState({
+ filterText: txt,
+ inStockOnly: stockOnly
+ });
+ },
+
+ render: function() {
+ return (
+
+ );
+ }
+});
+
+var SearchBar = React.createClass({
+ handleChange: function() {
+ this.props.onUserInput(
+ this.refs.filterTextInput.getDOMNode().value,
+ this.refs.inStockOnlyInput.getDOMNode().checked
+ );
+ },
+ render: function() {
+ return (
+
+ );
+ }
+});
+
+var ProductTable = React.createClass({
+ render: function() {
+ var rows = [];
+ var lastCategory = null;
+ var filterText = this.props.filterText.toLowerCase();
+ var inStockOnly = this.props.inStockOnly;
+
+ this.props.products.forEach(function(product) {
+ if (product.category !== lastCategory) {
+ rows.push(
);
+ }
+ if (product.name.toLowerCase().indexOf(filterText) > -1) {
+ if (inStockOnly) {
+ if (product.stocked) {
+ rows.push(
);
+ }
+ } else {
+ rows.push(
);
+ }
+ }
+ lastCategory = product.category;
+ });
+
+ return (
+
+
+
+ | Name |
+ Price |
+
+
+ {rows}
+
+ );
+ }
+});
+
+var ProductCategoryRow = React.createClass({
+ render: function() {
+ return (
| {this.props.category} |
|---|
);
+ }
+});
+
+var ProductRow = React.createClass({
+ render: function() {
+ var name = this.props.product.stocked ?
+ this.props.product.name :
+
+ {this.props.product.name}
+ ;
+ return (
+
+ | {name} |
+ {this.props.product.price} |
+
+ );
+ }
+});
+
+
+var PRODUCTS = [
+ {category: 'Sporting Goods', price: '$49.99', stocked: true, name: 'Football'},
+ {category: 'Sporting Goods', price: '$9.99', stocked: true, name: 'Baseball'},
+ {category: 'Sporting Goods', price: '$29.99', stocked: false, name: 'Basketball'},
+ {category: 'Electronics', price: '$99.99', stocked: true, name: 'iPod Touch'},
+ {category: 'Electronics', price: '$399.99', stocked: false, name: 'iPhone 5'},
+ {category: 'Electronics', price: '$199.99', stocked: true, name: 'Nexus 7'}
+];
+
+React.render(
, document.body);
diff --git a/react-scotty.cabal b/react-scotty.cabal
deleted file mode 100644
index a3024211..00000000
--- a/react-scotty.cabal
+++ /dev/null
@@ -1,28 +0,0 @@
--- Initial react-scotty.cabal generated by cabal init. For further
--- documentation, see http://haskell.org/cabal/users-guide/
-
-name: react-scotty
-version: 0.1.0.0
-synopsis: React Haskell code with Scotty
--- description:
-license: GPL-2
-license-file: LICENSE
-author: Sibi
-maintainer: sibi@psibi.in
--- copyright:
-category: Web
-build-type: Simple
--- extra-source-files:
-cabal-version: >=1.10
-
-executable react-scotty
- main-is: Server.hs
- -- other-modules:
- -- other-extensions:
- build-depends: base >=4.8 && <4.9,
- scotty, wai-extra,
- mtl, text, aeson,
- bytestring,
- wai-middleware-static
- -- hs-source-dirs:
- default-language: Haskell2010
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index 632a1efa..00000000
--- a/requirements.txt
+++ /dev/null
@@ -1 +0,0 @@
-Flask==0.10.1
diff --git a/server.go b/server.go
deleted file mode 100644
index 146192d1..00000000
--- a/server.go
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * This file provided by Facebook is for non-commercial testing and evaluation
- * purposes only. Facebook reserves all rights not expressly granted.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package main
-
-import (
- "bytes"
- "encoding/json"
- "fmt"
- "io"
- "io/ioutil"
- "log"
- "net/http"
- "os"
- "sync"
-)
-
-type comment struct {
- Author string `json:"author"`
- Text string `json:"text"`
-}
-
-const dataFile = "./comments.json"
-
-var commentMutex = new(sync.Mutex)
-
-// Handle comments
-func handleComments(w http.ResponseWriter, r *http.Request) {
- // Since multiple requests could come in at once, ensure we have a lock
- // around all file operations
- commentMutex.Lock()
- defer commentMutex.Unlock()
-
- // Stat the file, so we can find its current permissions
- fi, err := os.Stat(dataFile)
- if err != nil {
- http.Error(w, fmt.Sprintf("Unable to stat the data file (%s): %s", dataFile, err), http.StatusInternalServerError)
- return
- }
-
- // Read the comments from the file.
- commentData, err := ioutil.ReadFile(dataFile)
- if err != nil {
- http.Error(w, fmt.Sprintf("Unable to read the data file (%s): %s", dataFile, err), http.StatusInternalServerError)
- return
- }
-
- switch r.Method {
- case "POST":
- // Decode the JSON data
- comments := make([]comment, 0)
- if err := json.Unmarshal(commentData, &comments); err != nil {
- http.Error(w, fmt.Sprintf("Unable to Unmarshal comments from data file (%s): %s", dataFile, err), http.StatusInternalServerError)
- return
- }
-
- // Add a new comment to the in memory slice of comments
- comments = append(comments, comment{Author: r.FormValue("author"), Text: r.FormValue("text")})
-
- // Marshal the comments to indented json.
- commentData, err = json.MarshalIndent(comments, "", " ")
- if err != nil {
- http.Error(w, fmt.Sprintf("Unable to marshal comments to json: %s", err), http.StatusInternalServerError)
- return
- }
-
- // Write out the comments to the file, preserving permissions
- err := ioutil.WriteFile(dataFile, commentData, fi.Mode())
- if err != nil {
- http.Error(w, fmt.Sprintf("Unable to write comments to data file (%s): %s", dataFile, err), http.StatusInternalServerError)
- return
- }
-
- w.Header().Set("Content-Type", "application/json")
- w.Header().Set("Cache-Control", "no-cache")
- io.Copy(w, bytes.NewReader(commentData))
-
- case "GET":
- w.Header().Set("Content-Type", "application/json")
- w.Header().Set("Cache-Control", "no-cache")
- // stream the contents of the file to the response
- io.Copy(w, bytes.NewReader(commentData))
-
- default:
- // Don't know the method, so error
- http.Error(w, fmt.Sprintf("Unsupported method: %s", r.Method), http.StatusMethodNotAllowed)
- }
-}
-
-func main() {
- port := os.Getenv("PORT")
- if port == "" {
- port = "3000"
- }
- http.HandleFunc("/comments.json", handleComments)
- http.Handle("/", http.FileServer(http.Dir("./public")))
- log.Println("Server started: http://localhost:" + port)
- log.Fatal(http.ListenAndServe(":"+port, nil))
-}
diff --git a/server.lua b/server.lua
deleted file mode 100644
index e80bbc59..00000000
--- a/server.lua
+++ /dev/null
@@ -1,38 +0,0 @@
--- This file provided by Facebook is for non-commercial testing and evaluation
--- purposes only. Facebook reserves all rights not expressly granted.
---
--- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
--- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
--- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
--- FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
--- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
--- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
-
---
--- For use with Algernon / Lua
---
--- Project page: https://github.com/xyproto/algernon
--- Web page: http://algernon.roboticoverlords.org/
---
-
-handle("/comments.json", function()
-
- -- Set the headers
- content("application/javascript")
- setheader("Cache-Control", "no-cache")
-
- -- Use a JSON file for the comments
- comments = JFile("comments.json")
-
- -- Handle requests
- if method() == "POST" then
- -- Add the form data table to the JSON document
- comments:add(ToJSON(formdata(), 4))
- end
-
- -- Return the contents of the JSON file
- print(tostring(comments))
-
-end)
-
-servedir("/", "public")
diff --git a/server.php b/server.php
deleted file mode 100644
index 70301a3f..00000000
--- a/server.php
+++ /dev/null
@@ -1,49 +0,0 @@
- $_POST['author'],
- 'text' => $_POST['text']];
-
- $comments = json_encode($commentsDecoded, JSON_PRETTY_PRINT);
- file_put_contents('comments.json', $comments);
- }
- header('Content-Type: application/json');
- header('Cache-Control: no-cache');
- echo $comments;
- } else {
- return false;
- }
-}
diff --git a/server.py b/server.py
deleted file mode 100644
index 7dc15c14..00000000
--- a/server.py
+++ /dev/null
@@ -1,33 +0,0 @@
-# This file provided by Facebook is for non-commercial testing and evaluation
-# purposes only. Facebook reserves all rights not expressly granted.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-# FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
-# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-import json
-import os
-from flask import Flask, Response, request
-
-app = Flask(__name__, static_url_path='', static_folder='public')
-app.add_url_rule('/', 'root', lambda: app.send_static_file('index.html'))
-
-@app.route('/comments.json', methods=['GET', 'POST'])
-def comments_handler():
-
- with open('comments.json', 'r') as file:
- comments = json.loads(file.read())
-
- if request.method == 'POST':
- comments.append(request.form.to_dict())
-
- with open('comments.json', 'w') as file:
- file.write(json.dumps(comments, indent=4, separators=(',', ': ')))
-
- return Response(json.dumps(comments), mimetype='application/json', headers={'Cache-Control': 'no-cache'})
-
-if __name__ == '__main__':
- app.run(port=int(os.environ.get("PORT",3000)))
diff --git a/server.rb b/server.rb
deleted file mode 100644
index 8e40876d..00000000
--- a/server.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-# This file provided by Facebook is for non-commercial testing and evaluation
-# purposes only. Facebook reserves all rights not expressly granted.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-# FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
-# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-require 'webrick'
-require 'json'
-
-port = ENV['PORT'].nil? ? 3000 : ENV['PORT'].to_i
-
-puts "Server started: http://localhost:#{port}/"
-
-root = File.expand_path './public'
-server = WEBrick::HTTPServer.new :Port => port, :DocumentRoot => root
-
-server.mount_proc '/comments.json' do |req, res|
- comments = JSON.parse(File.read('./comments.json'))
-
- if req.request_method == 'POST'
- # Assume it's well formed
- comment = {}
- req.query.each do |key, value|
- comment[key] = value.force_encoding('UTF-8')
- end
- comments << comment
- File.write('./comments.json', JSON.pretty_generate(comments, :indent => ' '))
- end
-
- # always return json
- res['Content-Type'] = 'application/json'
- res['Cache-Control'] = 'no-cache'
- res.body = JSON.generate(comments)
-end
-
-trap 'INT' do server.shutdown end
-
-server.start