async provide in plugin #11141
Unanswered
idc77
asked this question in
Help/Questions
Replies: 2 comments
-
|
You call One way to handle this could be to provide an empty install: (app, options) => {
const dbRef = ref()
app.provide(SurrealClientSymbol, dbRef)
const db = new Surreal();
db.connect(/* ... */).then(()=> {
dbRef.value = db
})
}const db = inject(SurrealClientSymbol) // a ref, initially empty
const blogs = ref()
watch(db, () => {
if (db.value) {
blogs.value = db.select("blog")
}
}) |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
If you need to wait for the resource before mounting the app, then you could do something like what vue-router does by having an let ready
const promise = new Promise(resolve => {
ready = resolve
})
export default {
install: async (app, options) => {
const db = new Surreal()
app.provide(SurrealClientSymbol, db)
await db.connect("ws://127.0.0.1:8000/rpc", { ... })
ready()
},
isReady: () => promise,
}And in import myPlugin from '...'
app.use(myPlugin)
await myPlugin.isReady()
app.mount('#app') |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to provide a const but I'm getting errors
Beta Was this translation helpful? Give feedback.
All reactions