falsandtru / pjax-api

The advanced PJAX superior to SPA.
https://falsandtru.github.io/pjax-api/
Apache License 2.0
318 stars 28 forks source link

How do you use the sequence property? #48

Closed Yahav closed 2 years ago

Yahav commented 2 years ago

Lets say i'd like to add a header to the requests and do something after the response but before the DOM change, how would i go about that?

falsandtru commented 2 years ago

You can see a sample code of the sequence option in tests.

https://github.com/falsandtru/pjax-api/blob/v3.33.2/test/integration/package.ts#L65

Yahav commented 2 years ago

I really don't get it. any real life (no tests) usage of this available?

falsandtru commented 2 years ago

No. That sample is very readable. You should write your code by rewriting that sample.

Yahav commented 2 years ago

I tried the following, just to see what happens:

const sequence = {
    async fetch(r, req) {
        console.log('fetch', r, req);
        return 1;
    },
    async unload(r, res) {
        console.log('unload', r, red);
        return 2;
    },
    async content(r, areas) {
        console.log('content', r, areas);
        return 3;
    },
    async ready(r) {
        console.log('ready', r);
        return 4;
    },
    async load(r, events) {
        console.log('load', r, events);
        done();
    }
};

new Pjax({
    sequence: sequence,
    areas: [
        // Try the first query.
        '#site-content, #navbarMenuDesktop .ui.header, #casterfmCloudProperties',
    ]
});

when loading a page, after the first console.log (fetch), it just redirects...

falsandtru commented 2 years ago

You must remove done().

Yahav commented 2 years ago

removed, still happens

Yahav commented 2 years ago

I think its related to the args of one of the functions because when i run it like this it works:

const sequence = {
  async fetch() {
    return 1;
  },
  async unload() {
    return 2;
  },
  async content() {
    return 3;
  },
  async ready() {
    return 4;
  },
  async load() {
  }
};
falsandtru commented 2 years ago

Misspelling

    async unload(r, res) {
        console.log('unload', r, red); // <-
        return 2;
    },
Yahav commented 2 years ago

Yap, got that. still trying to figure out how do i add headers to the request in stage one.

falsandtru commented 2 years ago

See https://falsandtru.github.io/pjax-api/api/pjax/config/

Yahav commented 2 years ago

Which one of the sequence is fired only after all the additional scripts has finished loading?

falsandtru commented 2 years ago

Same as https://falsandtru.github.io/pjax-api/api/event/