Skip to content

Instantly share code, notes, and snippets.

@diatche
Created September 17, 2020 21:26
Show Gist options
  • Save diatche/7969f828d9dfb807485cd7f29a5dd612 to your computer and use it in GitHub Desktop.
Save diatche/7969f828d9dfb807485cd7f29a5dd612 to your computer and use it in GitHub Desktop.
Test Gun recall function
<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