MCPcopy Create free account
hub / github.com/dailydotdev/apps / getRemoteSettingsPatch

Function getRemoteSettingsPatch

packages/shared/src/contexts/SettingsContext.tsx:340–373  ·  view source on GitHub ↗
(
  current: RemoteSettings,
  next: Partial<RemoteSettings>,
)

Source from the content-addressed store, hash-verified

338// updates columns partially and merges `flags`, so a patch is enough.
339// Client-only flags never leave the device.
340const getRemoteSettingsPatch = (
341 current: RemoteSettings,
342 next: Partial<RemoteSettings>,
343): Partial<RemoteSettings> => {
344 const patch = Object.keys(next).reduce((changed, key) => {
345 if (
346 key === 'flags' ||
347 isSameSettingValue(next[key], current[key as keyof RemoteSettings])
348 ) {
349 return changed;
350 }
351
352 return { ...changed, [key]: next[key] };
353 }, {} as Partial<RemoteSettings>);
354
355 const currentFlags: Partial<SettingsFlags> = current.flags ?? {};
356 const nextFlags: Partial<SettingsFlags> = next.flags ?? {};
357 const changedFlags = Object.keys(nextFlags).filter(
358 (flag) =>
359 !isClientOnlyFlag(flag) &&
360 !isSameSettingValue(nextFlags[flag], currentFlags[flag]),
361 );
362
363 if (!changedFlags.length) {
364 return patch;
365 }
366
367 return {
368 ...patch,
369 flags: Object.fromEntries(
370 changedFlags.map((flag) => [flag, nextFlags[flag]]),
371 ) as SettingsFlags,
372 };
373};
374
375export const SettingsContextProvider = ({
376 children,

Callers 1

setSettingsFunction · 0.85

Calls 2

isSameSettingValueFunction · 0.85
isClientOnlyFlagFunction · 0.85

Tested by

no test coverage detected