Skip to content

Instantly share code, notes, and snippets.

Dean Radcliffe deanius

Block or report user

Report or block deanius

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View angular.js
class AppComponent {
// Bind to this with userCardNumber.value
userCardNumber = new BehaviorSubject<String>();
// Bind to this with userCardNumber | async
userCardValues = this.userCardNumber.asObservable()
constructor() {
}
@deanius
deanius / await-what?.js
Created Jan 13, 2019
Where await can go wrong
View await-what?.js
//
async function() {
let likeCount = 0
for(let one of many) {
likeCount = likeCount + (await fetch(`/users/${one}`)).response.likes
}
console.log(`There are ${likeCount} likes.`)
}()
View rx-all-pipe.js
let download$ = fromEvent(document, "click", ".downloadable").pipe(
map(e => months[e.target.attribues["data-month"]]),
map(month => ({
type: "download/start",
payload: { file: month + ".csv" }
})))
agent.on("download/start", ({ action }) => {
const { filename } = action.payload
return ajax({ url: "download.php?file=" + filename }).pipe(
View rx-7-concatmap.js
let result$ = download$.concatMap(action => {
const { filename } = action.payload
return ajax( /* same AJAX stuff as before */ )
})
result$.tap(action => {
// save to localStorage
}).subscribe()
View rx-6-ajax.js
agent.on('download/start', ({ action }) => {
const { filename } = action.payload
return ajax({ url: 'download.php?file=' + filename })
.map(result => ({
type: 'download/complete',
payload: {
bytes: result.response,
filename
}
})
View rx-5-rx-storage.js
result$.tap(action => {
const { filename, bytes } = action.payload
localStorage.set(filename, bytes)
console.log('Saved ' + filename)
}).subscribe()
View rx-4-storage.js
let download$ = (simulated or real download requests)
let result$ = (simulated or real results of downloads)
// TODO create result$ from download$
agent.on('download/complete', ({ action }) => {
const { filename, bytes } = action.payload
localStorage.set(filename, bytes)
console.log('Saved ' + filename)
})
View rx-3-real.js
// A series of user-initiated download start requests
let download$ = fromEvent(document, 'click', '.downloadable')
.map(e => months[e.target.attribues['data-month']])
.map(month => ({
type: 'download/start',
payload: { file: month + '.csv' }
})
View rx-2-html.html
<a class="downloadable" data-month="0">Download January</a>
<a class="downloadable" data-month="1">Download February</a>
You can’t perform that action at this time.