Code Monkey home page Code Monkey logo

Comments (5)

CTNicholas avatar CTNicholas commented on June 7, 2024 2

Hey @saiprakash2, we've just released a new option that simplifies this. If we take the original code snippet, you can see the before and after in the snippet below, enabled by nextCursor.

let cursor: string | null = null;

while (true) {
  const resp = await client.getRooms({ startingAfter: cursor });
  doSomethingWithRooms(resp.data);  // current page

  if (resp.nextPage === null) {
    break; // Done paginating
  } else {
    // ❌ Before
    cursor = resp.nextPage.split("startingAfter=")[1].split("&")[0];

    // ✅ After
    cursor = resp.nextCursor;
  }
}

You need to udpate all your packages to 1.9.7 to see this. Find more information under liveblocks.getRooms.

from liveblocks.

nvie avatar nvie commented on June 7, 2024 1

Are you talking about improving REST api server responses here instead of updating liveblocks/node client?

Exactly, it would be nicer to have the data available directly instead of having to parse it out in the node client, which feels like a bit of a hack!

Is REST api code open sourced?

Unfortunately the REST API is not open source.

from liveblocks.

saiprakash2 avatar saiprakash2 commented on June 7, 2024

Hii @nvie ,
I have one suggestion here. Can't we do this cursor = resp.nextPage.split("startingAfter=")[1].split("&")[0]; in the api itself so that we can send cursor value in the server responses. In that way they dont' have to do the parsing.
If it is null then no more pagination or if it has value then they can use it to fetch the next set of data.
This might be an easy fix.
Please let me know if it works or I will look into it bit more 🙂.

from liveblocks.

nvie avatar nvie commented on June 7, 2024

Yep! That’s my preferred approach too. We can let the server send those cursor and limit fields back in those responses, right next to the nextPage field with that value in there.

from liveblocks.

saiprakash2 avatar saiprakash2 commented on June 7, 2024

Hi @nvie,
Are you talking about improving REST api server responses here instead of updating liveblocks/node client?
Is REST api code open sourced?

from liveblocks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.