MCPcopy Index your code
hub / github.com/TanStack/router / _resolveBlockerOpts

Function _resolveBlockerOpts

packages/solid-router/src/useBlocker.tsx:85–135  ·  view source on GitHub ↗
(
  opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,
  condition?: boolean | any,
)

Source from the content-addressed store, hash-verified

83}
84
85function _resolveBlockerOpts(
86 opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,
87 condition?: boolean | any,
88): UseBlockerOpts {
89 if (opts === undefined) {
90 return {
91 shouldBlockFn: () => true,
92 withResolver: false,
93 }
94 }
95
96 if ('shouldBlockFn' in opts) {
97 return opts
98 }
99
100 if (typeof opts === 'function') {
101 const shouldBlock = Boolean(condition ?? true)
102
103 const _customBlockerFn = async () => {
104 if (shouldBlock) return await opts()
105 return false
106 }
107
108 return {
109 shouldBlockFn: _customBlockerFn,
110 enableBeforeUnload: shouldBlock,
111 withResolver: false,
112 }
113 }
114
115 const shouldBlock = Solid.createMemo(() => Boolean(opts.condition ?? true))
116
117 const _customBlockerFn = async () => {
118 if (shouldBlock() && opts.blockerFn !== undefined) {
119 return await opts.blockerFn()
120 }
121 return shouldBlock()
122 }
123
124 return {
125 get shouldBlockFn() {
126 return _customBlockerFn
127 },
128 get enableBeforeUnload() {
129 return shouldBlock()
130 },
131 get withResolver() {
132 return opts.blockerFn === undefined
133 },
134 }
135}
136
137export function useBlocker<
138 TRouter extends AnyRouter = RegisteredRouter,

Callers 1

useBlockerFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected