( self: Context<Services>, key: string, service: Types.NoInfer<S> )
| 785 | * @since 4.0.0 |
| 786 | */ |
| 787 | export const addUnsafe = <Services, I, S>( |
| 788 | self: Context<Services>, |
| 789 | key: string, |
| 790 | service: Types.NoInfer<S> |
| 791 | ): Context<Services | I> => { |
| 792 | const impl = self as ContextImpl<Services> |
| 793 | const cacheRoot = cacheKeys.has(key) ? undefined : impl.cacheRoot |
| 794 | if (impl.depth >= MaxDepth) { |
| 795 | // Rebase the overlay chain into a flat map, keeping the cacheRoot so a |
| 796 | // rebase on an ordinary key does not invalidate fiber caches |
| 797 | const map = new Map(impl.mapUnsafe) |
| 798 | map.set(key, service) |
| 799 | return makeImpl(cacheRoot, map, undefined, 0) |
| 800 | } |
| 801 | |
| 802 | return makeImpl( |
| 803 | cacheRoot, |
| 804 | impl.base, |
| 805 | { key, value: service, parent: impl.overlay }, |
| 806 | impl.depth + 1 |
| 807 | ) |
| 808 | } |
| 809 | |
| 810 | /** |
| 811 | * Adds or removes a service depending on an `Option`. |
no test coverage detected