lbry-desktop/ui/js/triggers.js

92 lines
1.9 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,
2017-04-28 17:14:44 +02:00
} from 'selectors/content'
import {
shouldFetchCurrentUriFileInfo,
2017-04-28 17:14:44 +02:00
} from 'selectors/file_info'
import {
shouldFetchCurrentUriCostInfo,
2017-04-28 17:14:44 +02:00
} from 'selectors/cost_info'
import {
shouldFetchCurrentUriAvailability,
} from 'selectors/availability'
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,
2017-04-28 17:14:44 +02:00
} from 'actions/content'
import {
doFetchCurrentUriFileInfo,
2017-04-28 17:14:44 +02:00
} from 'actions/file_info'
import {
doFetchCurrentUriCostInfo,
2017-04-28 17:14:44 +02:00
} from 'actions/cost_info'
import {
doFetchCurrentUriAvailability,
} from 'actions/availability'
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,
})
triggers.push({
selector: shouldFetchCurrentUriAvailability,
action: doFetchCurrentUriAvailability,
})
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
}