Skip to content

chore: Refactor to reduce the importance of Config#89

Merged
rzane merged 60 commits into
mainfrom
rzane/move-split-registry
Jan 9, 2026
Merged

chore: Refactor to reduce the importance of Config#89
rzane merged 60 commits into
mainfrom
rzane/move-split-registry

Conversation

@rzane

@rzane rzane commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

Config

Currently, Config is a grab bag of a bunch of unrelated things, and we pass it everywhere.

In this PR, my primary motivation is to split the config into multiple objects, each of which has responsibility. The loadConfig function does not perform any type coersion. It just parses window.TT and returns the raw data.

Client

Uses the configured url to perform HTTP requests against the API. This object has functions like getVisitor(). These functions are intended to be pretty low-level and should not contain any business logic.

Storage

StorageProvider defines an interface for storing the visitorId.

Currently, the only storage adapter is createCookieStorage(). This storage adapter accepts a cookie name and domain to store the visitor ID in a cookie.

In the future, we could allow clients to configure other storage adapters (e.g. localStorage or AsyncStorage in React Native).

SplitRegistry and Assignments

No real changes here, but we're passing these around instead of passing Config.

Visitor

Previously, we were passing around Visitor to a bunch of functions, mostly so they could access logError and the splitRegistry. The Visitor has a very complex setup, and passing simpler arguments makes testing much easier.

Misc

Code consolidation:

  • Merged mixpanelAnalytics.ts into analyticsProvider.ts
  • Merged split.ts into splitRegistry.ts
  • Renamed api.ts to client/request.ts
  • Deleted assignmentOverride.ts (logic moved inline to session.ts)
  • Deleted test-utils.ts (tests now create dependencies directly)

Renames:

  • getABVariants()getFalseVariant() (returns just the false variant now, not both)
  • Assignment.fromJsonArray()Assignment.fromV1Assignment() (handles single item, not array)

Test improvements:

  • Stopped assigning to visitor.logError directly; now uses visitor.setErrorLogger()
  • Stopped accessing private properties in tests, allowing us to use private elements
  • Fixed noisy output from tests

rzane and others added 30 commits January 7, 2026 10:35
- Change calculateVariant signature to accept options object with visitor, splitRegistry, and splitName
- Remove getSplit helper function (inline the logic)
- Update visitor.ts to pass splitRegistry explicitly
- Update calculateVariant tests to use new signature

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add splitRegistry to Options type
- Update getABVariants to use splitRegistry parameter instead of visitor.config.splitRegistry
- Update visitor.ts ab() method to pass splitRegistry explicitly
- Update abConfiguration tests to pass splitRegistry

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add splitRegistry to Options type
- Update validateVariants to accept splitRegistry parameter
- Update vary to use splitRegistry parameter instead of visitor.config.splitRegistry
- Update visitor.ts vary() method to pass splitRegistry explicitly
- Update vary tests to pass splitRegistry

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add config to Options type
- Update persistAssignment to accept config parameter
- Update sendAssignmentNotification to use config parameter instead of visitor.config
- Update visitor.ts _notify() method to pass config explicitly
- Update assignmentNotification tests to pass config

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add config to Options type
- Update persistAssignmentOverride to use config parameter instead of visitor.config
- Update session.ts call site to pass config explicitly
- Update assignmentOverride tests to pass config

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Update calculateVariant expectations to use new object parameter syntax
- Update sendAssignmentNotification expectations to include config parameter
- Update persistAssignmentOverride expectation to include config parameter
- Use shorthand property syntax in test expectations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@rzane rzane requested a review from samandmoore January 7, 2026 15:59
@rzane rzane force-pushed the rzane/move-split-registry branch from 052ef78 to d979324 Compare January 7, 2026 18:52
@rzane rzane force-pushed the rzane/move-split-registry branch from b11de05 to e0216b6 Compare January 7, 2026 19:08
@rzane rzane force-pushed the rzane/move-split-registry branch from 9b017c0 to f946c44 Compare January 8, 2026 22:31

@samandmoore samandmoore left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domainlgtm platformlgtm

(reviewed live)

@rzane rzane merged commit 8bb29ac into main Jan 9, 2026
5 checks passed
@rzane rzane deleted the rzane/move-split-registry branch January 9, 2026 18:49
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

Successfully merging this pull request may close these issues.

2 participants