Comments (7)
It seems to be hard to support the custom cache feature in v1 unless developers write their own injecting spy functionality into all mutations.
from swr-devtools.
Hey, I just found this project and it's looking great! Would love to contribute as much as I can.
Do you think if it's possible to build it as a middleware?
<SWRConfig value={{ middlewares: [swrdevtools] }}>
Since SWRConfig
supports extending, you can make the above a component (so you can inject the UI there too):
<SWRDevTools>
<MainApp />
</SWRDevTools>
The good part is, you can access to the active cache inside a middleware (config.cache
), and you can provide a custom cache implementation as well by overriding config.cache
.
Also, since the import { cache } from 'swr'
is gone in 1.0, a way to get the global cache is SWRConfig.default.cache
.
from swr-devtools.
Update: I'm working on a new hook to expose the mutate
method in vercel/swr#1361, it should cover this use case (as well as many other pain points).
from swr-devtools.
@shuding Thank you! That looks amazing and I think this covers my use case 👍
I started considering that swr-devtools
only supports v1 in the near future.
from swr-devtools.
The Cache interface of swr v1 only has get
, set
, and delete
methods, which means I cannot subscribe changes in the Cache and cannot list all cache data.
https://github.com/vercel/swr/blob/master/src/types.ts#L170-L174
For that reasons, I would have to wrap a cache to add capabilities like subscribe()
and keys()
in __SWR_DEVTOOLS__.launch(cache)
.
from swr-devtools.
I've started supporting v1 at 90a9775.
I've noticed that v1 doesn't expose keys()
as an interface, so I cannot retrieve all cache data before opening the devtool panel.
from swr-devtools.
@shuding Thank you for being interested in this project!
Yeah, That's a great idea for v1 support. I didn't come up with using config.cache
, and it would be the best place to handle a cache. That also gives us the capability of observing fetch requests.
One thing that is not clear is that how to support mutation from a devtool panel. (#8) To mutate a cache, SWR Devtools has to keep the reference of the mutate
method to support this, but middlewares would not be able to get the reference. So I have to find a way to pass the mutate
method to the middleware.
from swr-devtools.
Related Issues (20)
- Performance Issue with large data HOT 2
- Theme Switcher dosn't work
- Add a test to guarantee web-accessible.js doesn't not include React
- After a short period of time, Cache and History tabs stop updating HOT 2
- How to disable SWR-devtools on Production HOT 3
- swr-devtools.vercel.app has been blocked HOT 1
- Doesn't work on brave browser without SWRDevTools component HOT 3
- Pretty Printed Key? HOT 1
- Support `useSWRSubscription`
- Uncaught Error: Extension context invalidated HOT 5
- SWRDevTools tab doesn't render anything HOT 1
- Extension causing pages to error. HOT 8
- doesn't work in nextjs13 project with chrome HOT 9
- revalidateFirstPage has been never resolved
- Display config values
- Empty extension HOT 27
- Support SSR HOT 3
- Avoid throwing an Error when passing non-serializable values
- Feat: Add manual dark mode support HOT 1
- swr-devtools not working on edge.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swr-devtools.