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.

Revisions

  1. diatche created this gist Sep 17, 2020.
    40 changes: 40 additions & 0 deletions recall-test.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    <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/[email protected]/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>