Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Ramu Narasinga
Ramu Narasinga

Posted on • Edited on • Originally published atthinkthroo.com

State management in react-scan codebase.

In this article, we review how the store is managed in react-scan source code. The below code is picked frompackages/scan/core/src/index.ts.

export const Store: StoreType = {  wasDetailsOpen: signal(true),  isInIframe: signal(    typeof window !== 'undefined' && window.self !== window.top,  ),  inspectState: signal<States>({    kind: 'uninitialized',  }),  monitor: signal<Monitor | null>(null),  fiberRoots: new Set<Fiber>(),  reportData: new Map<number, RenderData>(),  legacyReportData: new Map<string, RenderData>(),  lastReportTime: signal(0),};
Enter fullscreen modeExit fullscreen mode

You will find Set, Map but I don’t know what signal here is. Let’s find out.

signal is imported from preact as shown below

import { type Signal, signal } from '@preact/signals';
Enter fullscreen modeExit fullscreen mode

Signals in Preact

Signals are reactive primitives for managing application state.

What makes Signals unique is that state changes automatically update components and UI in the most efficient way possible. Automatic state binding and dependency tracking allows Signals to provide excellent ergonomics and productivity while eliminating the most common state management footguns.

Signals are effective in applications of any size, with ergonomics that speed up the development of small apps, and performance characteristics that ensure apps of any size are fast by default.

Read more aboutSignals.

How this state is used in react-scan?

Isearched for signals and found that it is used in 30 files.

Image description

I have picked some instances where this state is used.

core/monitor/performance.ts

// todo: update monitoring api to expose filters for component namesexport function initPerformanceMonitoring(options?: Partial<PathFilters>) {  const filters = { ...DEFAULT_FILTERS, ...options };  const monitor = Store.monitor.value;  if (!monitor) return;
Enter fullscreen modeExit fullscreen mode

scan/web/views/index.tsx

export const Content = () => {  const isInspecting = useComputed(    () => Store.inspectState.value.kind === 'inspecting',  );  return (    <div
Enter fullscreen modeExit fullscreen mode

scan/src/web/widget/resize-handle.tsx

 const updateVisibility = () => {      const isFocused = Store.inspectState.value.kind === 'focused';      const shouldShow = signalWidgetViews.value.view !== 'none';      const isVisible =        (isFocused || shouldShow) &&        getHandleVisibility(          position,          signalWidget.value.corner,          signalWidget.value.dimensions.isFullWidth,          signalWidget.value.dimensions.isFullHeight,        );
Enter fullscreen modeExit fullscreen mode

About me:

Hey, my name isRamu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.

I am open to work on interesting projects. Send me an email atramu.narasinga@gmail.com

My Github — https://github.com/ramu-narasinga

My website — https://ramunarasinga.com

My Youtube channel — https://www.youtube.com/@ramu-narasinga

Learning platform — https://thinkthroo.com

Codebase Architecture — https://app.thinkthroo.com/architecture

Best practices — https://app.thinkthroo.com/best-practices

Production-grade projects — https://app.thinkthroo.com/production-grade-projects

References:

  1. https://github.com/aidenybai/react-scan/blob/main/packages/scan/src/core/index.ts#L260

  2. https://github.com/search?q=repo%3Aaidenybai%2Freact-scan%20Store&type=code

  3. https://github.com/aidenybai/react-scan?tab=readme-ov-file#api-reference

  4. https://preactjs.com/guide/v10/signals/

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.
  • Location
    India
  • Joined

More fromRamu Narasinga

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp