Created
March 8, 2016 16:03
-
-
Save neurosnap/29bf8dc5c2aa0fcb4909 to your computer and use it in GitHub Desktop.
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 main(sources) { | |
const auth$ = Auth(sources); | |
const apiDomain = getAPIDomain(); | |
const apiMailboxes = `${apiDomain}/mailboxes`; | |
const getMailboxes$ = auth$.state$.map(accInfo => { | |
console.log(accInfo); | |
return { | |
url: apiMailboxes, | |
method: 'GET', | |
headers: { | |
'Content-Type': 'application/vnd.api+json', | |
'X-Authorization': accInfo.token | |
} | |
}; | |
}); | |
const mailboxes$ = sources.HTTP | |
.filter(res$ => { return res$.request.url.indexOf(apiMailboxes) === 0 }) | |
.mergeAll() | |
.map(res => JSON.parse(res.text)) | |
.map(data => { | |
return data.mailboxes; | |
}); | |
const getThreads$ = Rx.Observable.combineLatest(auth$.state$, mailboxes$, | |
(accInfo, mailboxes) => { | |
console.log(accInfo, mailboxes); | |
let mailHTTP = []; | |
for (let i = 0; i < mailboxes.length; i++) { | |
let mailbox = mailboxes[i]; | |
let apiThreads = `${apiDomain}/mailboxes/${mailbox.id}/threads/folder/in`; | |
mailHTTP.push({ | |
url: apiThreads, | |
method: 'GET', | |
header: { | |
'Content-Type': 'application/vnd.api+json', | |
'X-Authorization': accInfo.token | |
} | |
}); | |
} | |
return mailHTTP; | |
}); | |
const threads$ = sources.HTTP | |
.mergeAll() | |
.map(res => JSON.parse(res.text)) | |
.map(data => { | |
return data.threads; | |
}).startWith(false); | |
const vtree$ = view(auth$, mailboxes$); | |
return { | |
DOM: vtree$, | |
HTTP: Rx.Observable.merge(auth$.HTTP, getMailboxes$, getThreads$) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment