Pavel 7 år sedan
förälder
incheckning
38810e46dc

+ 1 - 0
hw1/Weather/js/index.js

@@ -36,6 +36,7 @@ get('https://raw.githubusercontent.com/David-Haim/CountriesToCitiesJSON/master/c
       option.value = keys[i];
       option.value = keys[i];
       select.appendChild(option);
       select.appendChild(option);
   }
   }
+
   select.onchange = function(e){
   select.onchange = function(e){
       console.log(this.value)
       console.log(this.value)
       console.log(document.getElementById("main").value)
       console.log(document.getElementById("main").value)

+ 1 - 1
hw2/createReactTable/src/Table1.js

@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
 import Data from './data.js';
 import Data from './data.js';
 import './css/Table1-style.css';
 import './css/Table1-style.css';
 
 
-function createReactTable(data,root1){
+function createReactTable(data,root1){ 
   class Table1 extends Component {
   class Table1 extends Component {
     render() {
     render() {
       return React.createElement('table',{className:'Table1'},
       return React.createElement('table',{className:'Table1'},

+ 43 - 46
hw2/weatherGenerator/files/js/index.js

@@ -29,56 +29,53 @@ function show(obj){
 }
 }
 
 
 function* myGenerator(){
 function* myGenerator(){
-  var object = yield get('https://raw.githubusercontent.com/David-Haim/CountriesToCitiesJSON/master/countriesToCities.json');
-  var keys = Object.keys(object);
-  var select = document.createElement("select");
-  for (var i = 0; i < keys.length; i++) {
-      var option = document.createElement("option");
-      option.innerHTML = keys[i];
-      option.value = keys[i];
-      select.appendChild(option);
-  }
-  select.onchange = function(){
-    var g1 = select1();
-    g1.next();
-  }
-   function* select1(e){
-      var select = document.createElement("select");
-      for (var i = 0; i < object[this.value].length; i++) {
-          var option = document.createElement("option")
-          option.innerHTML = object[this.value][i];
-          select.appendChild(option);
-      }
-      if(selects.children.length > 1){
-          selects.replaceChild(select, document.getElementById("main").nextElementSibling);
-      }
-      else
-          selects.appendChild(select);
-          debugger;
-        var obj = yield get("https://query.yahooapis.com/v1/public/yql?" + 'q=' + encodeURIComponent("select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\'" + select.value + "\') and u='c'") + '&format=json');
-        show(obj);
-      select2.onchange = function(){
-        var g2 = select1();
-        g2.next();
-      }
-      function* select2(){
-        var obj = yield get("https://query.yahooapis.com/v1/public/yql?" + 'q=' + encodeURIComponent("select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\'" + this.value + "\') and u='c'") + '&format=json');
-        show(obj);
-      }
-  }
-  selects.appendChild(select);
-  select.id = "main"
+    var object = yield get('https://raw.githubusercontent.com/David-Haim/CountriesToCitiesJSON/master/countriesToCities.json');
+    var keys = Object.keys(object);
+    var select = document.createElement("select");
+    for (var i = 0; i < keys.length; i++) {
+        var option = document.createElement("option");
+        option.innerHTML = keys[i];
+        option.value = keys[i];
+        select.appendChild(option);
+    }
+
+    select.onchange = function(){
+      run(onchange1);
+    }
+    function* onchange1(e){
+        var select = document.createElement("select");
+        for (var i = 0; i < object[document.getElementById("main").value].length; i++) {
+            var option = document.createElement("option")
+            option.innerHTML = object[document.getElementById("main").value][i];
+            select.appendChild(option);
+        }
+        if(selects.children.length > 1){
+            selects.replaceChild(select, document.getElementById("main").nextElementSibling);
+        }
+        else
+            selects.appendChild(select);
+          var obj = yield get("https://query.yahooapis.com/v1/public/yql?" + 'q=' + encodeURIComponent("select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\'" + select.value + "\') and u='c'") + '&format=json');
+          show(obj);
+        select.onchange = function(){
+          get("https://query.yahooapis.com/v1/public/yql?" + 'q=' + encodeURIComponent("select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\'" + this.value + "\') and u='c'") + '&format=json').then(function(obj){
+            show(obj);
+          })
+        }
+    }
+    selects.appendChild(select);
+    select.id = "main"
+
 }
 }
 
 
 function run(g){
 function run(g){
-  var iter = g();
-  function next(result){
-      console.log(iter.next(result))
-      let {value, done} = iter.next(result)
-      if (typeof value === 'object' && 'then' in value){
-          value.then(next,(e) => iter.throw(e))
+  var gen = g();
+  function handle(result){
+      if(!result.done){
+        result.value.then(function(data){
+          return handle(gen.next(data));
+        })
       }
       }
   }
   }
-  next();
+  return handle(gen.next());
 }
 }
 run(myGenerator);
 run(myGenerator);

+ 1 - 0
hw2/weatherGenerator/weatherGenerator.md

@@ -0,0 +1 @@
+http://homeworkreactjs.pavelefimen95.fe.a-level.com.ua/hw2/weatherGenerator/files