swr-devtools
Advanced tools
Comparing version 0.5.0 to 1.0.0
@@ -1,1 +0,2 @@ | ||
export { SWRDevTools, DevToolsMessage } from "./SWRDevTools"; | ||
export { SWRDevTools, SWRDevToolsContext } from "./SWRDevTools"; | ||
export { DevToolsMessage, createSWRDevtools } from "./createSWRDevTools"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SWRDevTools = void 0; | ||
exports.createSWRDevtools = exports.SWRDevToolsContext = exports.SWRDevTools = void 0; | ||
var SWRDevTools_1 = require("./SWRDevTools"); | ||
Object.defineProperty(exports, "SWRDevTools", { enumerable: true, get: function () { return SWRDevTools_1.SWRDevTools; } }); | ||
Object.defineProperty(exports, "SWRDevToolsContext", { enumerable: true, get: function () { return SWRDevTools_1.SWRDevToolsContext; } }); | ||
var createSWRDevTools_1 = require("./createSWRDevTools"); | ||
Object.defineProperty(exports, "createSWRDevtools", { enumerable: true, get: function () { return createSWRDevTools_1.createSWRDevtools; } }); | ||
//# sourceMappingURL=index.js.map |
import React from "react"; | ||
export declare type DevToolsMessage = { | ||
type: "updated_swr_cache"; | ||
payload: { | ||
key: string; | ||
value: any; | ||
}; | ||
} | { | ||
type: "initialized"; | ||
import { EventEmitter } from "./createSWRDevTools"; | ||
export declare type SWRDevToolsContextValue = { | ||
events: EventEmitter | null; | ||
}; | ||
export declare const SWRDevToolsContext: React.Context<SWRDevToolsContextValue>; | ||
export declare const SWRDevTools: ({ children }: { | ||
children: React.ReactNode; | ||
}) => JSX.Element; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -33,42 +26,20 @@ if (k2 === undefined) k2 = k; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SWRDevTools = void 0; | ||
exports.SWRDevTools = exports.SWRDevToolsContext = void 0; | ||
var react_1 = __importStar(require("react")); | ||
var swr_1 = require("swr"); | ||
var swr_cache_1 = require("./swr-cache"); | ||
var injected = new WeakSet(); | ||
// TOOD: we have to support more types | ||
var convertToSerializableObject = function (value) { | ||
return value instanceof Error ? { message: value.message } : value; | ||
}; | ||
var inject = function (cache) { | ||
return (0, swr_cache_1.injectSWRCache)(cache, function (key, value) { | ||
window.postMessage({ | ||
type: "updated_swr_cache", | ||
payload: { | ||
key: key, | ||
value: Object.keys(value).reduce(function (acc, cacheKey) { | ||
var _a; | ||
return (__assign(__assign({}, acc), (_a = {}, _a[cacheKey] = convertToSerializableObject(value[cacheKey]), _a))); | ||
}, {}), | ||
}, | ||
}, "*"); | ||
}); | ||
}; | ||
var swrdevtools = function (useSWRNext) { return function (key, fn, config) { | ||
(0, react_1.useLayoutEffect)(function () { | ||
window.postMessage({ type: "initialized" }, "*"); | ||
}, []); | ||
// FIXME: I'll use mutate to support mutating from a devtool panel. | ||
var cache = (0, swr_1.useSWRConfig)().cache /* , mutate */; | ||
if (!injected.has(cache)) { | ||
inject(cache); | ||
injected.add(cache); | ||
} | ||
return useSWRNext(key, fn, config); | ||
}; }; | ||
var createSWRDevTools_1 = require("./createSWRDevTools"); | ||
exports.SWRDevToolsContext = react_1.default.createContext({ | ||
events: null, | ||
}); | ||
if (typeof window !== "undefined") { | ||
// @ts-expect-error | ||
window.__SWR_DEVTOOLS_REACT__ = react_1.default; | ||
} | ||
var SWRDevTools = function (_a) { | ||
var children = _a.children; | ||
return react_1.default.createElement(swr_1.SWRConfig, { value: { use: [swrdevtools] } }, children); | ||
var _b = (0, react_1.useRef)((0, createSWRDevTools_1.createSWRDevtools)()).current, swrdevtools = _b[0], events = _b[1]; | ||
return (react_1.default.createElement(exports.SWRDevToolsContext.Provider, { value: { events: events } }, | ||
react_1.default.createElement(swr_1.SWRConfig, { value: { use: [swrdevtools] } }, children))); | ||
}; | ||
exports.SWRDevTools = SWRDevTools; | ||
//# sourceMappingURL=SWRDevTools.js.map |
@@ -1,1 +0,2 @@ | ||
export { SWRDevTools, DevToolsMessage } from "./SWRDevTools"; | ||
export { SWRDevTools, SWRDevToolsContext } from "./SWRDevTools"; | ||
export { DevToolsMessage, createSWRDevtools } from "./createSWRDevTools"; |
@@ -1,2 +0,3 @@ | ||
export { SWRDevTools } from "./SWRDevTools"; | ||
export { SWRDevTools, SWRDevToolsContext } from "./SWRDevTools"; | ||
export { createSWRDevtools } from "./createSWRDevTools"; | ||
//# sourceMappingURL=index.js.map |
import React from "react"; | ||
export declare type DevToolsMessage = { | ||
type: "updated_swr_cache"; | ||
payload: { | ||
key: string; | ||
value: any; | ||
}; | ||
} | { | ||
type: "initialized"; | ||
import { EventEmitter } from "./createSWRDevTools"; | ||
export declare type SWRDevToolsContextValue = { | ||
events: EventEmitter | null; | ||
}; | ||
export declare const SWRDevToolsContext: React.Context<SWRDevToolsContextValue>; | ||
export declare const SWRDevTools: ({ children }: { | ||
children: React.ReactNode; | ||
}) => JSX.Element; |
@@ -1,50 +0,17 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import React, { useLayoutEffect } from "react"; | ||
import { useSWRConfig, SWRConfig } from "swr"; | ||
import { injectSWRCache } from "./swr-cache"; | ||
var injected = new WeakSet(); | ||
// TOOD: we have to support more types | ||
var convertToSerializableObject = function (value) { | ||
return value instanceof Error ? { message: value.message } : value; | ||
}; | ||
var inject = function (cache) { | ||
return injectSWRCache(cache, function (key, value) { | ||
window.postMessage({ | ||
type: "updated_swr_cache", | ||
payload: { | ||
key: key, | ||
value: Object.keys(value).reduce(function (acc, cacheKey) { | ||
var _a; | ||
return (__assign(__assign({}, acc), (_a = {}, _a[cacheKey] = convertToSerializableObject(value[cacheKey]), _a))); | ||
}, {}), | ||
}, | ||
}, "*"); | ||
}); | ||
}; | ||
var swrdevtools = function (useSWRNext) { return function (key, fn, config) { | ||
useLayoutEffect(function () { | ||
window.postMessage({ type: "initialized" }, "*"); | ||
}, []); | ||
// FIXME: I'll use mutate to support mutating from a devtool panel. | ||
var cache = useSWRConfig().cache /* , mutate */; | ||
if (!injected.has(cache)) { | ||
inject(cache); | ||
injected.add(cache); | ||
} | ||
return useSWRNext(key, fn, config); | ||
}; }; | ||
import React, { useRef } from "react"; | ||
import { SWRConfig } from "swr"; | ||
import { createSWRDevtools } from "./createSWRDevTools"; | ||
export var SWRDevToolsContext = React.createContext({ | ||
events: null, | ||
}); | ||
if (typeof window !== "undefined") { | ||
// @ts-expect-error | ||
window.__SWR_DEVTOOLS_REACT__ = React; | ||
} | ||
export var SWRDevTools = function (_a) { | ||
var children = _a.children; | ||
return React.createElement(SWRConfig, { value: { use: [swrdevtools] } }, children); | ||
var _b = useRef(createSWRDevtools()).current, swrdevtools = _b[0], events = _b[1]; | ||
return (React.createElement(SWRDevToolsContext.Provider, { value: { events: events } }, | ||
React.createElement(SWRConfig, { value: { use: [swrdevtools] } }, children))); | ||
}; | ||
//# sourceMappingURL=SWRDevTools.js.map |
{ | ||
"name": "swr-devtools", | ||
"version": "0.5.0", | ||
"version": "1.0.0", | ||
"description": "A React component for SWR DevTools", | ||
@@ -52,7 +52,8 @@ "main": "cjs/index.js", | ||
"devDependencies": { | ||
"@types/react": "^17.0.16", | ||
"react": "^17.0.2", | ||
"swr": "^2.0.0-beta.2", | ||
"typescript": "^4.1.3" | ||
} | ||
"@types/react": "^18.0.15", | ||
"react": "^18.2.0", | ||
"swr": "^2.0.0-beta.6", | ||
"typescript": "^4.7.4" | ||
}, | ||
"gitHead": "9e91ff45ca9d84ccd85c9468dd579035c07b9e4f" | ||
} |
@@ -24,10 +24,9 @@ # swr-devtools | ||
```jsx | ||
import ReactDOM from "react-dom"; | ||
import { createRoot } from "react-dom/client"; | ||
import { SWRDevTools } from "swr-devtools"; | ||
ReactDOM.render( | ||
createRoot(document.getElementById("app")).render( | ||
<SWRDevTools> | ||
<MainApp /> | ||
</SWRDevTools>, | ||
document.getElementById("app") | ||
</SWRDevTools> | ||
); | ||
@@ -34,0 +33,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
50755
27
810
0
41
1