mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-07-26 19:51:24 +00:00
build
config
img
lib
locales
qortal-ui-core
qortal-ui-crypto
api
bitcoin
deps
transactions
utils
randomBase58Generator.js
stateAwait.js
wallet
PhraseWallet.js
api.js
constants.js
createTransaction.js
createWallet.js
decryptStoredWallet.js
fetch-request.js
kdf.js
registerUsername.js
storeWallet.js
tradeRequest.js
api.js
api_deps.js
config.js
package.json
qortal-ui-plugins
scripts
snap
.editorconfig
.gitattributes
.gitignore
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
build-setup.js
build.bat
build.js
build.sh
electron-builder.yml
electron.js
install-dependencies.sh
package.json
push-updates-with-travis-build.sh
run_server.bat
server.js
set-up-snap.sh
update-package-json.js
watch-inline.js
watch.js
32 lines
784 B
JavaScript
32 lines
784 B
JavaScript
import { store } from '../../api.js'
|
|
|
|
let subscriptions = []
|
|
|
|
// Have to wait with init because something import stateAwait before the store gets initialized
|
|
let initialized = false
|
|
const init = () => {
|
|
initialized = true
|
|
store.subscribe(() => {
|
|
const state = store.getState()
|
|
|
|
subscriptions = subscriptions.filter(fn => fn(state))
|
|
})
|
|
}
|
|
|
|
export const stateAwait = fn => {
|
|
return new Promise((resolve, reject) => {
|
|
// Check immediately...then if not true store it
|
|
if (!initialized) {
|
|
init()
|
|
}
|
|
if (fn(store.getState())) resolve()
|
|
subscriptions.push(state => {
|
|
if (fn(state)) {
|
|
resolve()
|
|
return true
|
|
}
|
|
return false
|
|
})
|
|
})
|
|
}
|