lbry-desktop/ui/js/triggers.js

61 lines
1.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 {
shouldFetchFeaturedContent,
shouldFetchDownloadedContent,
shouldFetchPublishedContent,
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,
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,
})
console.log(triggers)
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
}