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
const User = require('./models/user'); | |
description('Tag parser', () => { | |
it('should parse tag stirng to query map, and remove query when user is not exists', async () => { | |
// bob, id: 1 | |
// foo, id: 2 | |
// system is no such user | |
const tagString = 'fav:bob fav:foo fav:system threshold:1'; | |
const queryMap = await tagString | |
.split(/\s+/) |
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
store.subscribe(() => { | |
const state = store.getState(); | |
const action = state.lastAction; | |
switch (action.type) { | |
case FETCH_PUBLIC_REPOS: { | |
$.getJSON(`https://api.github.com/search/repositories?q=language:javascript&per_page=10&page=${action.page}`) | |
.done((data) => { | |
store.dispatch(receivePublicRepos(data.items)); | |
}); |
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
store.subscribe(() => { | |
const state = store.getState(); | |
const action = state.lastAction; | |
switch (action.type) { | |
case FETCH_PUBLIC_REPOS: { | |
$.getJSON(`https://api.github.com/search/repositories?q=language:javascript&per_page=10&page=${action.page}`) | |
.done((data) => { | |
store.dispatch(receivePublicRepos(data.items)); | |
}); | |
break; |
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 toggleBookmark(repoId) { | |
const selectedRepo = repos.find(repo => repo.id === repoId); | |
selectedRepo.is_saved = !selectedRepo.is_saved; | |
$('#app').html(repoList.render({ repos: repos })); | |
if (selectedRepo.is_saved) { | |
const { full_name } = selectedRepo; | |
createBookmark(repoId, full_name); | |
} else { |
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 repos = []; | |
var bookmarks = []; | |
var page = 1; | |
const repoList = $ | |
.templates( | |
'repo-list', | |
{ markup: '#repo-list', templates: { repo: $.templates('#repo') } }, | |
); |
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
// Retry 5 times with waiting for 2 seconds | |
function* updateApi(data) { | |
for(let i = 0; i < 5; i++) { | |
try { | |
const apiResponse = yield call(apiRequest, { data }); | |
return apiResponse; | |
} catch(err) { | |
if(i < 4) { | |
yield call(delay, 2000); | |
} |
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
// Debouncing | |
function* handleInput(input) { | |
// debounce by 500ms | |
yield call(delay, 500) | |
... | |
} | |
function* watchInput() { | |
let task | |
while (true) { |
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
// Throttling | |
function* handleInput(input) { | |
// ... | |
} | |
function* watchInput() { | |
yield throttle(500, 'INPUT_CHANGED', handleInput) | |
} |
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
// Retry 5 times without waiting | |
const inputEpic = (action$) => | |
action$.ofType('INPUT_CHANGED') | |
.retry(5) | |
... | |
// Retry 5 times with waiting for 2 seconds | |
const inputEpic = (action$) => | |
action$.ofType('INPUT_CHANGED') | |
.retryWhen(function(errors) { |
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
// Deboucing | |
const inputEpic = (action$) => | |
action$.ofType('INPUT_CHANGED') | |
.debounceTime(500) | |
... |