Giter VIP home page Giter VIP logo

Comments (20)

frederikhors avatar frederikhors commented on June 16, 2024

I would like a method like: getKeyStartsWith(key: string) to find for example keys like: /players?page=1.

And then I can search values for the playerId I need in detail page.

What do you think?

from sswr.

ConsoleTVs avatar ConsoleTVs commented on June 16, 2024

You've got:

https://github.com/ConsoleTVs/sswr/blob/master/src/index.ts#L105

and

https://github.com/ConsoleTVs/sswr/blob/master/src/index.ts#L115

from sswr.

frederikhors avatar frederikhors commented on June 16, 2024

It works. But.

As I said I'm using it for a "classic" list/detail and here what happens:

  1. I'm on the /players list page
  2. I have fetched data with /players key
  3. I move on the /players/1 detail page
  4. On detail page I use get("/players") to populate my initialData to speed up UX
  5. BUT during this navigation from /players to /players/1 the key /players is refetched in background hence the get("/players") does not return data, only a Promise, useless in this case

But if I need a Promise I can use getOrWait() instead.

So I think we should not "change" the cache during refetching because we need to get() something even if is stale.

What do you think?

from sswr.

frederikhors avatar frederikhors commented on June 16, 2024

I think we need a method like getStartingWith(key: string).

from sswr.

ConsoleTVs avatar ConsoleTVs commented on June 16, 2024

Why not just use the mutate to populate other keys or just use useSWR with revalidation set to false? There is a bunch of options you can pass to it!

from sswr.

frederikhors avatar frederikhors commented on June 16, 2024

Why not just use the mutate to populate other keys

I cannot, because I'm checking for data already in cache during new fetch...

or just use useSWR with revalidation set to false

The players list is refetching because I'm using a variable, and it can depends on other usecases.

Cannot be this the solution.

from sswr.

benbender avatar benbender commented on June 16, 2024

What you are trying to achieve is probably not possible.

  1. You are fetching the endpoint for /players and retrieve one(!) object (most likely parsed from a json-string)
  2. You are navigating to /players/1 and want the cache to know which part of the data in the cache belongs to player with id 1. Problem is that this information isn't retrieved by the cache.

To achieve such behaviour you could either:
a) parse your one object on the first fetch and populate the cache with individual objects
b) use graphql which has such features because of fragments and strong typing on both ends (f.e. with urql's graphcache).

But there is no way to get this for free. You have to type and/or parse your data at some point.

from sswr.

frederikhors avatar frederikhors commented on June 16, 2024

It's possible.

I'm getting the players object which is like this:

{ players: [{id: "1", name: "Name"}, ...and others] }

and with a .find() I can find my player/1.

from sswr.

frederikhors avatar frederikhors commented on June 16, 2024

It's doable right now with svelte-query.

from sswr.

ConsoleTVs avatar ConsoleTVs commented on June 16, 2024
{ players: [{id: "1", name: "Name"}, ...and others] }

Just find the player with id = 1 and put it in the cache:

mutate('player/1', {id: "1", name: "Name"})

from sswr.

frederikhors avatar frederikhors commented on June 16, 2024

Just find the player with id = 1

This is what I'm asking you!

If I use get() and the query is re-fetching I cannot find players (already fetched before) because I get a promise!

from sswr.

frederikhors avatar frederikhors commented on June 16, 2024

mutate or initialData is not a problem!

from sswr.

ConsoleTVs avatar ConsoleTVs commented on June 16, 2024

You have to change step 4 from your list.

  • I'm on the /players list page
  • I have fetched data with /players key
  • I populate the cache /players/${id} for each fetched player using mutate()
  • I move on the /players/1 detail page
  • UX will first show the stale / cached data while it re-validates it in the background.

from sswr.

frederikhors avatar frederikhors commented on June 16, 2024

I populate the cache /players/${id} for each fetched player using mutate()

But I don't know if a use will need this.

I'm opening a new page and in background the previous list is refetching (for many reasons).

This is not a valid solution.

from sswr.

ConsoleTVs avatar ConsoleTVs commented on June 16, 2024

How would this be done in https://swr.vercel.app otherwise?

from sswr.

frederikhors avatar frederikhors commented on June 16, 2024

I don't know, But it's doable in this project, the problem is we need to swap the data for that key only when the promise is resolved, not before.

IMO.

from sswr.

benbender avatar benbender commented on June 16, 2024

IMHO:
a) your sentences make no sense, are incomplete, plain false or simply not understandable.
b) no github-repo is your personal support-forum
c) "This is what I'm asking you!"? Are you nuts or simply rude? @ConsoleTVs provides a lib, developed in his freetime, free of charge, he even provides support and you dare to demand anything? Be grateful and nothing else. Period.
d) I'm out. I'll no longer answer questions or similar by you.

from sswr.

frederikhors avatar frederikhors commented on June 16, 2024

@benbender I love you. 😄

from sswr.

benbender avatar benbender commented on June 16, 2024

My verdict has fallen: you are plainly arrogant. For no obvious reason. #kthxbye #block

from sswr.

frederikhors avatar frederikhors commented on June 16, 2024

I really don't understand your behavior, @benbender.

Did you block me simply because I told you I love you? To avoid replying and wasting your time reading a reply to a useless message you wrote.

A message that doesn't make sense: I wasn't "demanding" anything from @ConsoleTVs; and among other things, as you well know and as @ConsoleTVs can tell, I am helping and collaborating with various PR on this splendid project.

You did not understand my question and you get angry, it seems like childish behavior to me.

Grow, live and let live.

Lots of little kisses.

from sswr.

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.