Skip to content

Instantly share code, notes, and snippets.

@qls0ulp
Forked from domenic/not-bad-code.js
Created July 4, 2020 09:07
Show Gist options
  • Save qls0ulp/18eea6db21d43386bafdb44d8ddd8758 to your computer and use it in GitHub Desktop.
Save qls0ulp/18eea6db21d43386bafdb44d8ddd8758 to your computer and use it in GitHub Desktop.

Revisions

  1. @domenic domenic revised this gist Nov 11, 2015. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions not-bad-code.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    function getUserDetail(username) {
    if (userCache[username]) {
    return Promise.resolve(userCache[username]);
    }
    if (userCache[username]) {
    return Promise.resolve(userCache[username]);
    }

    // Use the fetch API to get the information
    return fetch('users/' + username + '.json')
    // Use the fetch API to get the information
    return fetch('users/' + username + '.json')
    .then(function(result) {
    userCache[username] = result;
    reutrn result;
    userCache[username] = result;
    return result;
    })
    .catch(function() {
    throw new Error('Could not find user: ' + username);
    throw new Error('Could not find user: ' + username);
    });
    }
  2. @domenic domenic revised this gist Nov 11, 2015. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions not-bad-code.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    function getUserDetail(username) {
    if (userCache[username]) {
    return Promise.resolve(userCache[username]);
    }
    if (userCache[username]) {
    return Promise.resolve(userCache[username]);
    }

    // Use the fetch API to get the information
    return fetch('users/' + username + '.json')
    .then(function(result) {
    userCache[username] = result;
    reutrn result;
    })
    .catch(function() {
    throw new Error('Could not find user: ' + username);
    });
    // Use the fetch API to get the information
    return fetch('users/' + username + '.json')
    .then(function(result) {
    userCache[username] = result;
    reutrn result;
    })
    .catch(function() {
    throw new Error('Could not find user: ' + username);
    });
    }
  3. @domenic domenic created this gist Nov 11, 2015.
    15 changes: 15 additions & 0 deletions not-bad-code.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    function getUserDetail(username) {
    if (userCache[username]) {
    return Promise.resolve(userCache[username]);
    }

    // Use the fetch API to get the information
    return fetch('users/' + username + '.json')
    .then(function(result) {
    userCache[username] = result;
    reutrn result;
    })
    .catch(function() {
    throw new Error('Could not find user: ' + username);
    });
    }