Skip to content

Refactor colorIndex global state #24

@malston

Description

@malston

Summary

The colorIndex in colorManager.js is module-level state that could cause interference between concurrent operations.

Current Behavior

let colorIndex = 0;

export function getNextColor() {
  const color = COLORS[colorIndex % COLORS.length];
  colorIndex++;
  return color;
}

Proposed Solution

Use a generator function or pass color iterator as parameter to avoid shared mutable state.

export function* colorGenerator() {
  let index = 0;
  while (true) {
    yield COLORS[index % COLORS.length];
    index++;
  }
}

Priority

Medium

Related

Split from #3 (item #8)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions