Created
September 17, 2020 21:26
-
-
Save diatche/7969f828d9dfb807485cd7f29a5dd612 to your computer and use it in GitHub Desktop.
Test Gun recall function
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
<script src="https://cdn.jsdelivr.net/gh/amark/gun@master/gun.js"></script> | |
<script src="https://cdn.jsdelivr.net/gh/amark/gun@master/sea.js"></script> | |
<!-- <script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script> --> | |
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script> | |
<script> | |
;(() => { | |
// Reset by uncommenting the next line, run once and comment out again. | |
// sessionStorage.clear(); | |
localStorage.clear(); | |
let gun = new Gun(); | |
let user = gun.user(); | |
let pub = ''; | |
gun.on('auth', function (...args) { | |
pub = user.is.pub; | |
console.log('user is: ' + user.is.pub); | |
this.to.next(...args); | |
}); | |
// Recall is sync, as it uses session storage. | |
user.recall({ sessionStorage: true }, ack => { | |
// But, this seems to be only called when there IS a recall | |
console.log('recall ack: ' + JSON.stringify(_.pick(ack, ['ok', 'err', 'sea']), null, 2)); | |
}); | |
if (!pub) { | |
console.log('no recall'); | |
let runID = 'test-' + new Date().toISOString(); | |
user.create(runID, '123', ack => { | |
console.log('create user ack: ' + JSON.stringify(ack, null, 2)); | |
// One does not simply recall without calling auth() :) | |
user.auth(runID, '123', ack => { | |
console.log('auth user ack: ' + JSON.stringify(_.pick(ack, ['ok', 'err', 'sea']), null, 2)); | |
}); | |
}); | |
} | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment