local function g(g)return debug.traceback(g)end local function r(r,J)return function(Q)if typeof(Q)=="\102\117\110\099\116\105\111\110"then local r,O=xpcall(function()return Q(J)end,g)if not r then J._errorReporter.reportReducerError(J:getState(),Q,{message="\067\097\117\103\104\116 \101\114\114\111\114 \105\110 \116\104\117\110\107";thrownValue=O})return nil end return O end return r(Q)end end return r

local function tracebackReporter(message)
	return debug.traceback(message)
end

local function thunkMiddleware(nextDispatch, store)
	return function(action)
		if typeof(action) == "function" then
			local ok, result = xpcall(function()
				return action(store)
			end, tracebackReporter)

			if not ok then
				-- report the error and move on so it's non-fatal app
				store._errorReporter.reportReducerError(store:getState(), action, {
					message = "Caught error in thunk",
					thrownValue = result,
				})
				return nil
			end

			return result
		end

		return nextDispatch(action)
	end
end

return thunkMiddleware
