lbry-desktop/ui/js/triggers.js

73 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-04-22 15:17:01 +02:00
import {
shouldFetchTransactions,
shouldGetReceiveAddress,
} from 'selectors/wallet'
2017-04-23 11:56:50 +02:00
import {
shouldFetchFeaturedContent,
shouldFetchDownloadedContent,
shouldFetchPublishedContent,
shouldFetchCurrentUriFileInfo,
shouldFetchCurrentUriCostInfo,
2017-04-23 11:56:50 +02:00
} from 'selectors/content'
2017-04-22 15:17:01 +02:00
import {
doFetchTransactions,
doGetNewAddress,
} from 'actions/wallet'
2017-04-23 11:56:50 +02:00
import {
doFetchFeaturedContent,
doFetchDownloadedContent,
doFetchPublishedContent,
doFetchCurrentUriFileInfo,
doFetchCurrentUriCostInfo,
2017-04-23 11:56:50 +02:00
} from 'actions/content'
2017-04-22 15:17:01 +02:00
const triggers = []
triggers.push({
selector: shouldFetchTransactions,
action: doFetchTransactions,
})
triggers.push({
selector: shouldGetReceiveAddress,
action: doGetNewAddress
})
2017-04-23 11:56:50 +02:00
triggers.push({
selector: shouldFetchFeaturedContent,
action: doFetchFeaturedContent,
})
triggers.push({
selector: shouldFetchDownloadedContent,
action: doFetchDownloadedContent,
})
triggers.push({
selector: shouldFetchPublishedContent,
action: doFetchPublishedContent,
})
triggers.push({
selector: shouldFetchCurrentUriFileInfo,
action: doFetchCurrentUriFileInfo,
})
triggers.push({
selector: shouldFetchCurrentUriCostInfo,
action: doFetchCurrentUriCostInfo,
})
2017-04-22 15:17:01 +02:00
const runTriggers = function() {
triggers.forEach(function(trigger) {
const state = app.store.getState();
const should = trigger.selector(state)
if (trigger.selector(state)) app.store.dispatch(trigger.action())
});
}
module.exports = {
triggers: triggers,
runTriggers: runTriggers
}