Skip to content

Commit

Permalink
Merge 36c653f into d1161cd
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed May 7, 2018
2 parents d1161cd + 36c653f commit 15566e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
12 changes: 9 additions & 3 deletions lib/Store.lua
Expand Up @@ -48,12 +48,18 @@ function Store.new(reducer, initialState, middlewares)
table.insert(self._connections, connection)

if middlewares then
local dispatch = Store.dispatch
local unboundDispatch = self.dispatch
local dispatch = function(...)
return unboundDispatch(self, ...)
end

for _, middleware in ipairs(middlewares) do
dispatch = middleware(dispatch)
dispatch = middleware(dispatch, self)
end

self.dispatch = dispatch
self.dispatch = function(self, ...)
return dispatch(...)
end
end

return self
Expand Down
6 changes: 3 additions & 3 deletions lib/loggerMiddleware.lua
Expand Up @@ -39,9 +39,9 @@ local loggerMiddleware = {
outputFunction = print,
}

function loggerMiddleware.middleware(next)
return function(store, action)
local result = next(store, action)
function loggerMiddleware.middleware(nextDispatch, store)
return function(action)
local result = nextDispatch(action)

loggerMiddleware.outputFunction(("Action dispatched: %s\nState changed to: %s"):format(
prettyPrint(action),
Expand Down
6 changes: 3 additions & 3 deletions lib/thunkMiddleware.lua
Expand Up @@ -4,12 +4,12 @@
This middleware consumes the function; middleware further down the chain
will not receive it.
]]
local function thunkMiddleware(next)
return function(store, action)
local function thunkMiddleware(nextDispatch, store)
return function(action)
if typeof(action) == "function" then
return action(store)
else
return next(store, action)
return nextDispatch(action)
end
end
end
Expand Down

0 comments on commit 15566e3

Please sign in to comment.