-
Notifications
You must be signed in to change notification settings - Fork 28
feat: Add experimental debug override functionality. #132
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
Merged
pranjal-jately-ld
merged 15 commits into
launchdarkly:main
from
pranjal-jately-ld:add-flag-override-capability
Sep 5, 2025
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
97ea230
feat: Add debug override capabilities for plugins
pranjal-jately-ld 3cf00c0
feat: Enhance debug override functionality with removal and clearing …
pranjal-jately-ld 9441c92
feat: Implement getAllOverrides method and enhance flag handling
pranjal-jately-ld 697798a
Add flag store facade for centralized flag access
zubhav 8a7f2ff
Refactor setOverride to use flagStore.get method
zubhav bfbc9a9
fix: add objectHasOwnProperty checks to flagStore
pranjal-jately-ld 3086a44
Refactor flag handling for better readability
zubhav 28e6e42
Remove unnecessary comments and code in initialize function
zubhav 74f44ed
Update handling of flag changes to not wait for Promise
zubhav dd1a828
test: add tests for debug override functionality
pranjal-jately-ld ce4a44f
style: revert code formatting changes
pranjal-jately-ld c40f020
fix: restore missing allFlags implementation logic
pranjal-jately-ld 2cbe74c
refactor: add lazy initialization for flagOverrides with optimizations
pranjal-jately-ld 40a34b9
feat: implement FlagStore for centralized flag management
pranjal-jately-ld 5d306fc
docs: enhance typings and FlagStore documentation
pranjal-jately-ld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
const utils = require('./utils'); | ||
|
||
function FlagStore() { | ||
let flags = {}; | ||
let flagOverrides; | ||
pranjal-jately-ld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function get(key) { | ||
// Check overrides first, then real flags | ||
if (flagOverrides && utils.objectHasOwnProperty(flagOverrides, key) && flagOverrides[key]) { | ||
return flagOverrides[key]; | ||
} | ||
|
||
if (flags && utils.objectHasOwnProperty(flags, key) && flags[key] && !flags[key].deleted) { | ||
return flags[key]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function getFlagsWithOverrides() { | ||
const result = {}; | ||
|
||
// Add all flags first | ||
for (const key in flags) { | ||
const flag = get(key); | ||
if (flag) { | ||
result[key] = flag; | ||
} | ||
} | ||
|
||
// Override with any flagOverrides (they take precedence) | ||
if (flagOverrides) { | ||
for (const key in flagOverrides) { | ||
const override = get(key); | ||
if (override) { | ||
result[key] = override; | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
function setFlags(newFlags) { | ||
flags = { ...newFlags }; | ||
} | ||
|
||
function setOverride(key, value) { | ||
if (!flagOverrides) { | ||
flagOverrides = {}; | ||
} | ||
flagOverrides[key] = { value }; | ||
} | ||
|
||
function removeOverride(key) { | ||
if (!flagOverrides || !flagOverrides[key]) { | ||
return; // No override to remove | ||
} | ||
|
||
delete flagOverrides[key]; | ||
|
||
// If no more overrides, reset to undefined for performance | ||
if (Object.keys(flagOverrides).length === 0) { | ||
flagOverrides = undefined; | ||
} | ||
} | ||
|
||
function clearAllOverrides() { | ||
kinyoklion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!flagOverrides) { | ||
return {}; // No overrides to clear, return empty object for consistency | ||
} | ||
|
||
const clearedOverrides = { ...flagOverrides }; | ||
flagOverrides = undefined; // Reset to undefined | ||
return clearedOverrides; | ||
} | ||
|
||
function getFlags() { | ||
return flags; | ||
} | ||
|
||
function getFlagOverrides() { | ||
return flagOverrides || {}; | ||
} | ||
|
||
return { | ||
clearAllOverrides, | ||
get, | ||
getFlagOverrides, | ||
getFlags, | ||
getFlagsWithOverrides, | ||
removeOverride, | ||
setFlags, | ||
setOverride, | ||
}; | ||
} | ||
|
||
module.exports = FlagStore; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.