Skip to content

Commit

Permalink
Improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
willybrauner committed Oct 18, 2023
1 parent 3adc9c1 commit 1fa208f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,19 @@ function Router(props: {
cache.set(urlWithoutHash, newRoute.props ?? {});
}
else if (newRoute.getStaticProps) {
log(props.id, "firstRoute > isClient > request getStaticProps");
log(props.id, "firstRoute > isClient > request getStaticProps & set cache")
await requestStaticPropsAndCacheIt()
}
}
// CLIENT > NOT FIRST ROUTE
else {
const cacheData = cache.get(urlWithoutHash)
if (cacheData) {
log(props.id, "Not firstRoute > isClient > assign dataFromCache to newRoute.props");
log(props.id, "not firstRoute > isClient > assign dataFromCache to newRoute.props");
Object.assign(newRoute.props, cacheData);
}
else if (newRoute.getStaticProps) {
log(props.id, "Not firstRoute > isClient > request getStaticProps");
log(props.id, "not firstRoute > isClient > request getStaticProps");
await requestStaticPropsAndCacheIt()
}

Expand Down
3 changes: 0 additions & 3 deletions src/core/LangService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,6 @@ class LangService<TLang = any> {
showLangInUrl = this.showLangInUrl()
): TRoute[] {
if (routes?.some((el) => !!el._langPath)) {
log(
"Routes have already been formatted by 'addLangParamToRoutes()', return routes."
);
return routes;
}

Expand Down
5 changes: 3 additions & 2 deletions src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ export function getRouteFromUrl({
"/",
);
const matcher = match(currentRoutePath)(urlWithoutHashAndQuery);
log(id, `"${urlWithoutHashAndQuery}" match with "${currentRoutePath}"?`, !!matcher);
// prettier-ignore
log(id, `url "${urlWithoutHashAndQuery}" match path "${currentRoutePath}"?`,!!matcher);

// if current route path match with the param url
if (matcher) {
Expand Down Expand Up @@ -323,7 +324,7 @@ export function getRouteFromUrl({
_context: pParent ? formatRouteObj(pParent) : formattedCurrentRoute,
};

log(id, "getRouteFromUrl: MATCH routeObj", routeObj);
log(id, "match", routeObj);
return routeObj;
}

Expand Down
8 changes: 3 additions & 5 deletions src/core/staticPropsCache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Routers } from "./Routers";
import debug from "@wbe/debug";
const componentName: string = "staticPropsCache";
const componentName: string = "cache";
const log = debug(`router:${componentName}`);

/**
Expand All @@ -13,16 +13,14 @@ export function staticPropsCache(cache = Routers.staticPropsCache) {
*/
const get = (key: string): any => {
const dataAlreadyExist = Object.keys(cache).some((el) => el === key);

if (!dataAlreadyExist) {
log(`"${key}"page data doesn't exist in cache.`);
log(`"${key}" data doesn't exist in cache.`);
return null;
}
const dataCache = cache[key];
log("current page data is already in 'cache', we use it.", dataCache);
log("data is already in cache, return it.", dataCache);
return dataCache;
};

/**
* Set Data in static props cache
*/
Expand Down

0 comments on commit 1fa208f

Please sign in to comment.