Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setStyle calls cause unnecessary code execution #148

Open
Ledzz opened this issue Nov 26, 2024 · 0 comments
Open

setStyle calls cause unnecessary code execution #148

Ledzz opened this issue Nov 26, 2024 · 0 comments

Comments

@Ledzz
Copy link
Contributor

Ledzz commented Nov 26, 2024

When frequently calling ref.current.setStyle on container, there's some unneccessary code executed. If we do the same but by passing property as signal and updating this signal, code works much faster.
I found that this line causes this problem: computed body runs, handlers object is created, and this effect runs, even if handlers weren't changed.

Moving handlers object creation fixes the problem:

export function computedHandlers(
  style: Signal<Properties | undefined>,
  properties: Signal<Properties | undefined>,
  defaultProperties: Signal<AllOptionalProperties | undefined>,
  hoveredSignal: Signal<Array<number>>,
  activeSignal: Signal<Array<number>>,
  dynamicHandlers?: Signal<EventHandlers | undefined>,
  defaultCursor?: string,
) {
  const handlers: EventHandlers = {}
  
  return computed(() => {
    addHandlers(handlers, dynamicHandlers?.value)
    addHoverHandlers(handlers, style.value, properties.value, defaultProperties.value, hoveredSignal, defaultCursor)
    addActiveHandlers(handlers, style.value, properties.value, defaultProperties.value, activeSignal)
    return handlers
  })
}

But I don't know if this solution is OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant