Created
December 24, 2018 11:03
-
-
Save alant/23c9005390b3141d8053c7c225fc74f5 to your computer and use it in GitHub Desktop.
This file contains 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* pollSagaWorker(dataKey) { | |
while (true) { | |
const contracts = yield select(getContracts); | |
if (contracts.SimpleStorage.synced) { | |
const storedValueObj = contracts.SimpleStorage.storedData_[dataKey]; | |
if (storedValueObj && storedValueObj.value) { | |
yield put({ type: 'GOT_STORED_VALUE', storedValue: storedValueObj.value }); | |
} | |
} | |
yield call(delay, 200); | |
} | |
} | |
function* getStoredValueWatcher() { | |
while (true) { | |
yield take('GET_STORED_VALUE'); | |
yield put({ type: 'GETTING_STORED_VALUE' }); | |
const drizzle = yield select(getDrizzle); | |
const dataKey = drizzle.contracts.SimpleStorage.methods.storedData_.cacheCall(); | |
yield race([ | |
call(pollSagaWorker, dataKey), | |
take('GOT_STORED_VALUE') | |
]) | |
} | |
} | |
export default function* root() { | |
... | |
yield getStoredValueWatcher(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment