diff options
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | graffiti.js | 13 | ||||
-rw-r--r-- | index.html (renamed from test.html) | 2 | ||||
-rw-r--r-- | plugins/vue/plugin.js | 2 | ||||
-rw-r--r-- | src/auth.js (renamed from auth.js) | 0 | ||||
-rw-r--r-- | src/logoot.js (renamed from utils/logoot.js) | 0 |
6 files changed, 13 insertions, 12 deletions
@@ -1,6 +1,4 @@ -# Graffiti for Vanilla Javascript +# Graffiti Javascript Library -This is the base Javascript library that interfaces with the [Graffiti server](https://github.com/graffiti-garden/server). -We recommend not using this vanilla library itself but instead using framework plugins that are built on top of it like the [Graffiti plugin for Vue.JS](https://github.com/graffiti-garden/graffiti-x-vue). - -If you create a [local Graffiti instance](https://github.com/graffiti-garden/server#local-usage) and a local webserver in this directory (*e.g.* `python3 -m http.server`) and navigate to `test.html` (*e.g.* [http://localhost:8000/test.html](http://localhost:8000/test.html)) you should be able to log in and test each of the Graffiti primitives: `subscribe`, `unsubscribe`, `update`, `remove`. These primitives will be robust to spamming and network interruptions. +This is the base Javascript library that interfaces with the [Graffiti server](https://github.com/graffiti-garden/graffiti-server). +It also includes a plugin that extends it to operate with the [Vue.js framework](https://vuejs.org/). diff --git a/graffiti.js b/graffiti.js index d28b64d..9b92b4f 100644 --- a/graffiti.js +++ b/graffiti.js @@ -1,4 +1,5 @@ -import Auth from './auth.js' +import Auth from './src/auth.js' +//import Collection from './src/collection.js' export default class { @@ -36,10 +37,12 @@ export default class { this.#connect() } - async waitTilOpen() { - await new Promise(resolve => { - this.eventTarget.addEventListener("graffitiOpen", () => resolve() ) - }) + async opened() { + if (!this.open) { + await new Promise(resolve => { + this.eventTarget.addEventListener("graffitiOpen", () => resolve() ) + }) + } } #connect() { @@ -33,7 +33,7 @@ // Connect to a local Graffiti instance // (see the server README for how to n locally) window.graffiti = new Graffiti("http://localhost:5001") - await graffiti.waitTilOpen() + await graffiti.opened() // Log in automatically if not already // and supply a log out button diff --git a/plugins/vue/plugin.js b/plugins/vue/plugin.js index e5483c6..2c61f40 100644 --- a/plugins/vue/plugin.js +++ b/plugins/vue/plugin.js @@ -12,7 +12,7 @@ export default { // These ID need to change after opening app.config.globalProperties.$graffitiID = ref(null) - graffiti.waitTilOpen().then(()=> { + graffiti.opened().then(()=> { app.config.globalProperties.$graffitiID.value = graffiti.myID }) diff --git a/utils/logoot.js b/src/logoot.js index c8c7c02..c8c7c02 100644 --- a/utils/logoot.js +++ b/src/logoot.js |