( current: RemoteSettings, next: Partial<RemoteSettings>, )
| 338 | // updates columns partially and merges `flags`, so a patch is enough. |
| 339 | // Client-only flags never leave the device. |
| 340 | const 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 | |
| 375 | export const SettingsContextProvider = ({ |
| 376 | children, |
no test coverage detected