Coder Social home page Coder Social logo

hackyourfuture's People

Contributors

nos111 avatar

Watchers

 avatar

hackyourfuture's Issues

The html/css is a bit better but not good yet

The HTML is a lot better. But you still have an h4 without using h3 so it looks like youre trying to make the text smaller by using a different html element != semantically correct.

As for the layout. The page would look a lot better if you used two columns so the image is loaded on the right.

You can improve createElement by passing it an object

IT's a lot more readable, look:

var sectionEl = {
    type: "section",
    parent: "info",
    message: "<a href="#">'+data.name+" profile",[["id","name"]]",
}
createElement(sectionEl);
function createElement(htmlElement){
    var element = document.createElement(htmlElement.type);
}

Im getting a GET file error

N/A:1 GET file:///Users/local/Documents/HYF/Javascript/Module%202/repos/Nour/assignment5/N/A net::ERR_FILE_NOT_FOUND

Nice helperfunction!

altough it would look a lot nicer if you passed it an array of attributes ;) Then you can make it as long as you want.
Or, if you want to go full pro: pass the function an object. The object would have a property called attributes an inside it would be stored an array :)

I would put initOnLoad at the top

It's called before initSearch so it should prob be at the top. Init functions set up or kickstart the rest of your code and as such are best put at the top of your code.

It's best not to use alerts

They are quite intrusive and some people have them disabled. In this case you could use a text above the searchfield.

Uncaight TypeErrors

Your page generates some errors both in the jquery and the js code along the lines of:

jquery.js:528 Uncaught TypeError: Cannot use 'in' operator to search for 'length' in False
    at isArrayLike (jquery.js:528)
    at Function.each (jquery.js:359)
    at Object.success (homework.js:73)
    at fire (jquery.js:3317)
    at Object.fireWith [as resolveWith] (jquery.js:3447)
    at done (jquery.js:9272)
    at XMLHttpRequest.<anonymous> (jquery.js:9514)

I have a feeling you are adding double event listeners

I think this line of code willa dd a new event listener everytime you search for a new user. There's another event listener that you remove, but you don't seem to remove this one.

I cant be sure as the rate limit has been reached for my machine. Maybe because youre duplicating requests because of this issue...

document.getElementById("repos").addEventListener('click',reposInit);

Half your uses of map are "correct"

So the first two uses where you store the result of the mapping function are the intended use of map. But the other two instances where you use map to execute some logic for each element in the array but don't return anything or do anything with the returned array are not as good.

Consider the following piece of code. HEre you could just as easily have used .forEach()

reposInfo.map( function(object,i){
            var repoLi = {type:'li',
                          parentId:'repos-list',
                          attribute:[['id',i],['class','repo']]
                         };
            createElement(repoLi).addEventListener('mouseover',reposHover);
            var repoNameElement = {type:'h4',
                                   parentId:i,
                                   text:object.name
                                  };
            createElement(repoNameElement)
        });

see https://stackoverflow.com/questions/354909/is-there-a-difference-between-foreach-and-map for reference.

Both js and jquery are now executed on keyup

They both execute an API request and they both overwrite the DOM!
That's quite an interesting situation, because the one that finishes last will overwrite the other. So if the js one is slower than the jq one, it overwrites the jq results and vise versa!

You could improve this line

var link = 'https://api.github.com/users/nos111';

To
var link = 'https://api.github.com/users/' + userName;

The var is already there :)

Youre still cheating a bit in your createlement

I understand you think it looks icer if you put everything in one line like this:

createElement("section","info",'<a href="#">'+data.name+" profile",[["id","name"]]).addEventListener('click',nameClick);

But it's not as readable, and it's more error prone than this:

var ul = createElement("ul");
var li = createElement("li");
ul.appendChild(li);

That way I can see what happens and it's clear what is added to what. In your code it's really hard to figure out how you are attaching the html nodes you create tot the document. It looks like youre adding them to an element with id "info" but there's also a variable info in your code so it's not clear.

Why are you creating the lisdiv var everytime keyup is triggered?

By creating the listDiv var inside that function, you're essentially recreating that var EVERYTIME a key up is triggered in the searchbox. You are also executing the elementById query everytime. Instead, it would be better to have a global listDiv var which points to the HTML element, since the reference will never change.
Then all you have to do is execute listDiv.innerHTML = " "; inside the function

Cool you made an initialiser function

You called it page which is not very clear
How about calling it init()
And why is it necessary that this function sets the info innerhtml to "", wouldnt that happen anyway on first pageload?

You can improve your local data structure

I understand what youre doing by info = data; but that's essentially just making a copy of all the incoming data.
Imagine a structure where you decide what is stored in it and add some data of your own

In regards to the mouseover function

First off, it should be int he form of addEventListener.
Second, the way you wrote it, if you mouse over ANYTHING in the document that doesn't have "text"+i as ID, it will trigger the else and try to set the visibility of that item. But think about all the elements that you don't want to do this on, like the body for instance.

This is why your page generates so many errors in the console.

Good job coing both the jQuery and the Js solutions!

While the jQuery code is indeed shorter, it's also a lot less extendable and managable because you put everything in one function. What would happen now if the OMDB API went down? The jQuery code would just get stuck somewhere inside that function.

One tip on promises

So I'm not 100% ure on this, but it might be easier if you just have inputcatcher return a promise. Then you don't need to do this trick:

var link = inputCatcher();
    var promise = Promise.resolve(link);

Other than that, great usage of promises! ๐Ÿ’

createElement works great now!

Definitely ready for re-use in other programs, good job!
Why did you decide to use new Map() instead of just creating an array?

jsonFile is a confusing var name

Understand that by calling that URL, you are executing an HTTP request. The response will be a string, that string will be in the syntax of JSON which means you can convert it to JSON, but at no time are you actually downloading a JSON file.

collaboratorsRequest seems to do something different than its name implies

You should prob just change the name and the description because now it seems to load the event data for that repo.

Also it would be nice to make this line more readable by dividing it into more lines.

  var link = 'https://api.github.com/repos/' + userName + '/' + reposInfo[parseInt(hoverEvent.target.id)].name +'/events';

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.