• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LouisBrunner / dnd-multi-backend / 6261880530

21 Sep 2023 12:49PM CUT coverage: 98.498%. Remained the same
6261880530

Pull #190

github

LouisBrunner
fix(build): issue due to upgrade to esbuild 0.18+
Pull Request #190: fix(build): issue due to upgrade to esbuild 0.18+ (fixes #189)

63 of 67 branches covered (0.0%)

Branch coverage included in aggregate %.

265 of 266 relevant lines covered (99.62%)

37.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/packages/react-dnd-multi-backend/src/hooks/useMultiCommon.ts
1
import { useContext } from 'react'
57✔
2
import { DragDropManager, Backend } from 'dnd-core'
3
import { DndContext, DndContextType } from 'react-dnd'
9✔
4
import { MultiBackendSwitcher } from 'dnd-multi-backend'
5

6
type Fn<Spec, Res> = (spec: Spec) => Res
7

8
interface DragDropManagerImpl extends DragDropManager {
9
  receiveBackend(backend: Backend): void
10
}
11

12
const useForBackend = <Spec, Res>(spec: Spec, fn: Fn<Spec, Res>, manager: DragDropManagerImpl, backend: Backend): Res => {
9✔
13
  const previous = manager.getBackend()
12✔
14
  manager.receiveBackend(backend)
12✔
15
  const result = fn(spec)
12✔
16
  manager.receiveBackend(previous)
12✔
17
  return result
12✔
18
}
19

20
export const useMultiCommon = <Spec, Res>(spec: Spec, fn: Fn<Spec, Res>): [Res, Record<string, Res>] => {
9✔
21
  const dndContext = useContext<DndContextType>(DndContext)
30✔
22
  const dndBackend = dndContext?.dragDropManager?.getBackend()
30!
23
  if (dndBackend === undefined) {
30✔
24
    throw new Error('could not find backend, make sure you are using a <DndProvider />')
24✔
25
  }
26

27
  const result = fn(spec)
6✔
28
  const multiResult: Record<string, Res> = {}
6✔
29
  const backends = (dndBackend as MultiBackendSwitcher).backendsList()
6✔
30
  for (const backend of backends) {
6✔
31
    multiResult[backend.id] = useForBackend(spec, fn, dndContext.dragDropManager as DragDropManagerImpl, backend.instance)
12✔
32
  }
33

34
  return [result, multiResult]
6✔
35
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc