Преглед изворни кода

Step 5: Add inverse data flow.

Frederic G. MARAND пре 10 година
родитељ
комит
b74a5b8cab
1 измењених фајлова са 34 додато и 12 уклоњено
  1. 34 12
      public/scripts/thinking.js

+ 34 - 12
public/scripts/thinking.js

@@ -26,7 +26,7 @@ let ProductRow = React.createClass({
   render: function () {
     let name = this.props.product.stocked
       ? this.props.product.name
-      : <span style={{ color: 'red' }}>{this.props.product.name}</span>;
+      : <span style={{ color: "red" }}>{this.props.product.name}</span>;
     return (
       <tr>
         <td>{name}</td>
@@ -84,13 +84,30 @@ let SearchBar = React.createClass({
     console.log("Get Initial State", this.name, "Props", this.props);
     return null;
   },
+  handleChange: function (e) {
+    this.props.onUserInput(
+      this.refs.filterTextInput.value,
+      this.refs.inStockOnlyInput.checked
+    );
+  },
   render: function () {
     return (
       <form>
-        <input type="text" placeholder="Search..." value={this.props.filterText} />
+        <input
+          type="text"
+          placeholder="Search..."
+          ref="filterTextInput"
+          value={this.props.filterText}
+          onChange={this.handleChange}
+        />
         <p>
-          <input type="checkbox" checked={this.props.inStockOnly} />
-          {' '}
+          <input
+            type="checkbox"
+            ref="inStockOnlyInput"
+            checked={this.props.inStockOnly}
+            onChange={this.handleChange}
+          />
+          {" "}
           Only show products in stock
         </p>
       </form>
@@ -105,18 +122,23 @@ let FilterableProductTable = React.createClass({
   },
   getInitialState: function () {
     let state = {
-      filterText: "ball",
-      inStockOnly: true
+      filterText: "",
+      inStockOnly: false
     };
     console.log("Get Initial State", this.name, state, "Props", this.props);
     return state;
   },
+  handleUserInput: function (filterText, inStockOnly) {
+    console.log("FPT.OSC", arguments);
+    this.setState({ filterText: filterText, inStockOnly: inStockOnly });
+  },
   render: function () {
     return (
       <div>
         <SearchBar
           filterText={this.state.filterText}
           inStockOnly={this.state.inStockOnly}
+          onUserInput={this.handleUserInput}
         />
         <ProductTable
           products={this.props.products}
@@ -129,12 +151,12 @@ let FilterableProductTable = React.createClass({
 });
 
 let 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'}
+  { 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" }
 ];
 
 ReactDOM.render(

PANIC: session(release): write data/sessions/3/c/3c766211d15935b6: no space left on device

PANIC

session(release): write data/sessions/3/c/3c766211d15935b6: no space left on device
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/session@v1.0.3/session.go:204 (0xb13e07)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:80 (0x967b75)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:157 (0x9512ee)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:135 (0x951205)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:124 (0x967cc4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:114 (0x967bf6)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/recovery.go:161 (0x15baec4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/logger.go:40 (0x96b257)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:157 (0x9512ee)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:135 (0x951205)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:124 (0x967cc4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/router.go:187 (0x972959)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/router.go:304 (0x973a01)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/macaron.go:218 (0x96c572)
/my/cache/.heroku/go/go1.26.3/go/src/net/http/server.go:3311 (0x85a5cd)
/my/cache/.heroku/go/go1.26.3/go/src/net/http/server.go:2073 (0x837f6f)
/my/cache/.heroku/go/go1.26.3/go/src/runtime/asm_amd64.s:1771 (0x493380)