This file contains hidden or 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
var observableStream = Rx.Observable.create(function (observer) { | |
var url1 = 'http://hello-universe.com'; | |
var url2 = 'http://hello-world.com'; | |
var defaultValue = {}; | |
observer.onNext(defaultValue); | |
$.get(url1).then(function(data) { | |
observer.onNext(data); | |
return $.get(url2); |
This file contains hidden or 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
var PromiseArray = []; | |
el.addEventListener('scroll', function(e) { | |
PromiseArray.push(new Promise(...)); | |
forEachForPromise(); | |
}); | |
function forEachForPromises() { | |
PromiseArray.filter(function(promise) { | |
promise.then(function(data) { |
This file contains hidden or 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
$.get('http://get-user-info.com').then(function(user) { | |
if (user.didPay) { | |
showSomethingCool(); | |
} | |
}); |
This file contains hidden or 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
el.addEventListener('scrollWhenScrollNotAtTop', realCallback); | |
$.ajax('http://get-user-info.com').ifUserDidPay(showSomethingColl); |
This file contains hidden or 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
{"answers":["function(console) {\n\tvar names = [\"Ben\", \"Jafar\", \"Matt\", \"Priya\", \"Brian\"],\n\t\tcounter;\n\n\tfor(counter = 0; counter < names.length; counter++) {\n\t\tconsole.log(names[counter]);\n\t}\n}\n\t\t","function(console) {\n\tvar names = [\"Ben\", \"Jafar\", \"Matt\", \"Priya\", \"Brian\"];\n\n\tnames.forEach(function(name) {\n\t\tconsole.log(name);\n\t});\n}\n\t\t","function() {\n\tvar newReleases = [\n\t\t{\n\t\t\t\"id\": 70111470,\n\t\t\t\"title\": \"Die Hard\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/DieHard.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [4.0],\n\t\t\t\"bookmark\": []\n\t\t},\n\t\t{\n\t\t\t\"id\": 654356453,\n\t\t\t\"title\": \"Bad Boys\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/BadBoys.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [5.0],\n\t\t\t\"bookmark\": [{ id: 432534, time: 65876586 }]\n\t\t},\n\t\t{\n\t\t\t\"id\": 654 |
This file contains hidden or 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
var btn = document.getElementById('button'); | |
btn.addEventListener('click', function () { | |
if (window.__VALID_USER__) { | |
console.log('Hello, Universe'); | |
} | |
}); |
This file contains hidden or 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
el.addEventListener('scroll', function () { | |
if (pageYOffset !== 0) { | |
realCallback(); | |
} | |
}); | |
el.addEventListener('touchmove', function () { | |
if (pageYOffset !== 0) { | |
realCallback(); | |
} |
This file contains hidden or 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
var arr = [1, 2, 3, 4, 5, 6]; | |
var filteredArr = arr.filter(function(item) { | |
return item % 2 === 0; | |
}); | |
var mappedFilteredArr = filteredArr.map(function (item) { | |
return item * 2; | |
}); |
This file contains hidden or 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
var btn = document.getElementById('button'); | |
btn.addEventListener('click', function () { | |
console.log('Hello, Universe'); | |
}); |
This file contains hidden or 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 listen(element, eventName) { | |
return new Observable(observer => { | |
// Create an event handler which sends data to the sink | |
let handler = event => observer.next(event); | |
// Attach the event handler | |
element.addEventListener(eventName, handler, true); | |
// Return a function which will cancel the event stream | |
return () => { |