This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fetchData(){ | |
return Promise.resolve({ name : 'John' }) | |
} | |
async function fetchAndLogData () { | |
const data = await fetchData(); | |
console.log(data); | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Factory function/method | |
function factoryFunction (){ | |
return { | |
field : 'value', | |
method : function() { return 5; } | |
} | |
} | |
const myNewObjectA = factoryFunction(); | |
// Constructor Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reverseStr(str) { | |
if (str.length <= 1) return str; | |
var firstChar = str[0]; | |
var restStr = str.substr(1); | |
return (restStr.length > 1 ? reverseStr(restStr) : restStr) + | |
firstChar; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert From/To Binary/Decimal/Hexadecimal in JavaScript | |
* https://gist.github.com/faisalman | |
* | |
* Copyright 2012-2015, Faisalman <fyzlman@gmail.com> | |
* Licensed under The MIT License | |
* http://www.opensource.org/licenses/mit-license | |
*/ | |
(function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vuex from 'vuex'; | |
import vue from 'vue'; | |
import * as api from './api'; | |
vue.use(vuex); | |
export default new vuex.Store({ | |
state: { | |
users: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> {{userProfile.name}} </div> | |
</template> | |
<script> | |
export default { | |
// here goes ... name, computed, mapping my state etc... | |
beforeMount(){ | |
this.$store.dispatch('fetchUserProfile'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Imports */ | |
const request = require('request-promise-native') | |
const assert = require('assert') | |
/* My API call*/ | |
async function getBooks({query, startIndex, maxResults}) { | |
const response = await request({ | |
method: 'GET', | |
url: 'https://www.googleapis.com/books/v1/volumes', | |
json: true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request-promise-native') | |
async function getBooks({query, startIndex, maxResults}) { | |
const response = await request({ | |
method: 'GET', | |
url: 'https://www.googleapis.com/books/v1/volumes', | |
json: true, | |
qs: { | |
q: query, | |
startIndex: startIndex, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function* myFunc(){ | |
// Do something | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function* searchBooks({query, pages}) { | |
for (let currentPage = 0; currentPage < pages; currentPage++) { | |
const books = await getBooks({ | |
query : query, | |
startIndex: currentPage, | |
maxResults: 2 | |
}) | |
yield books | |
} | |
} |
OlderNewer