lbry-desktop/ui/js/triggers.js

103 lines
2 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 {
2017-05-04 05:44:08 +02:00
shouldFetchFeaturedUris,
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 {
2017-05-04 05:44:08 +02:00
doFetchFeaturedUris,
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-05-07 14:50:32 +02:00
import {
shouldSearch,
} from 'selectors/search'
import {
doSearch,
} from 'actions/search'
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({
2017-05-04 05:44:08 +02:00
selector: shouldFetchFeaturedUris,
action: doFetchFeaturedUris,
2017-04-23 11:56:50 +02:00
})
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-05-07 14:50:32 +02:00
triggers.push({
selector: shouldSearch,
action: doSearch,
})
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
}