Created
January 22, 2019 23:21
-
-
Save learner-long-life/f3560b61fc79a4a1b086688cabe9666d to your computer and use it in GitHub Desktop.
Statebus Dev Diary Day #1
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
Hi bus drivers, | |
Thanks for the great framework! I've gotten it to work for my use case and just wanted to give you a shout out. | |
I'm writing values into statebus from a node client into a node server (running on localhost:80) and accessing | |
it from a webpage like this | |
<script type="statebus"> | |
dom.BODY = -> | |
DIV {}, | |
width: 100 | |
fetch('/abc').value | |
</script><script src="https://stateb.us/client6.js" server="http://localhost:80"></script> | |
I found that using absolute paths (leading slash) was necessary to persist values across refreshes from the web client, | |
but that from the server, the paths look relative, possibly b/c the "server scope" is considered a single thing, | |
but it's useful to consider every browser connection / refresh its own local scope. | |
If so, that's different than in the past when relative key paths used localStorage and persisted across browser refreshes. | |
I started up the server like so, and say messages showing a different client connecting with every refresh. | |
Cool! | |
o master.save('connections') .ec0cc437-a051-4705-8a21-8913b21f7f72 = undefined [master14] | |
• ↵ [master14] | |
GET /_connect_to_statebus_/websocket 0ms (unfinished) | |
o master.save('connections') .4bbe4745-dcae-46c6-abe4-b281a0b8ed08 = {"client":"4bbe4745-dcae-46c6-abe4-b281a [master15] | |
• ↵ [master15] | |
o client12.save('current_user') = {"key":"current_user","client":"c1mldiufma1s4ycpxtg4kb1wl8x90lst"} [client120] | |
o master.save('connections') .4bbe4745-dcae-46c6-abe4-b281a0b8ed08.user = undefined [master16] | |
• ↵ [master16] | |
* client12.dirty('current_user') | |
^ Fetched client12('abc') = {"key":"abc","value":"my big fat greek value"} [bus3] | |
saved db: 1.296ms | |
o master.save('connections') .4bbe4745-dcae-46c6-abe4-b281a0b8ed08 = undefined [master17] | |
• ↵ [master17] | |
GET /_connect_to_statebus_/websocket 0ms (unfinished) | |
Then I killed the server and restarted it: | |
$ node -i -e "const bus = require('statebus').serve()" | |
> Encryption OFF | |
o master.save('connections') .2be60f0c-db8a-46f1-ab3d-85ab3a06784c = undefined [master1] | |
• ↵ [master1] | |
SockJS v0.3.19 bound to "/_connect_to_statebus_" | |
Listening on http://<host>:80 | |
saved db: 5.132ms | |
> a = fetch(GET /_connect_to_statebus_/websocket 3ms (unfinished) | |
o master.save('connections') .0629aea2-01d5-45c4-a28f-3106c1e3c5a0 = {"client":"0629aea2-01d5-45c4-a28f-3106c [master2] | |
• ↵ [master2] | |
o client0.save('current_user') = {"key":"current_user","client":"tvg65u9uu1edb5wp1joegsag1pfgran5a"} [client00] | |
o master.save('connections') .0629aea2-01d5-45c4-a28f-3106c1e3c5a0.user = undefined [master3] | |
• ↵ [master3] | |
* client0.dirty('current_user') | |
^ Fetched client0('abc') = {"key":"abc","value":"my large latin content"} [master0] | |
"saved db: 1.225ms | |
abc") | |
ReferenceError: fetch is not defined | |
> a = bus.fetch("abc") | |
{ key: 'abc', value: 'my large latin content' } | |
> a.value = "my big fat greek value" | |
'my big fat greek value' | |
> bus.save(a) | |
o master.save('abc') .value = "my big fat greek value" [master4] | |
• ↵ [master4] | |
undefined | |
> • client0.save.fire('abc') .value = "my big fat greek value" [master4] | |
saved db: 1.418ms | |
^ Fetched client0('abc') <no diff> [master4] | |
It persists across | |
Paul |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment