Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
local Store = require(script.Store) | ||
local createReducer = require(script.createReducer) | ||
local combineReducers = require(script.combineReducers) | ||
local makeActionCreator = require(script.makeActionCreator) | ||
local loggerMiddleware = require(script.loggerMiddleware) | ||
local thunkMiddleware = require(script.thunkMiddleware) | ||
|
||
return { | ||
Store = Store, | ||
createReducer = createReducer, | ||
combineReducers = combineReducers, | ||
makeActionCreator = makeActionCreator, | ||
loggerMiddleware = loggerMiddleware.middleware, | ||
thunkMiddleware = thunkMiddleware, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--[[ | ||
A helper function to define a Rodux action creator with an associated name. | ||
]] | ||
local function makeActionCreator(name, fn) | ||
assert(type(name) == "string", "Bad argument #1: Expecteda string name for the action creator") | ||
assert(type(fn) == "function", "Bad argument #2: Expected a function that creates action objects") | ||
|
||
return setmetatable({ | ||
name = name, | ||
}, { | ||
__call = function(self, ...) | ||
local result = fn(...) | ||
|
||
assert(type(result) == "table", "Invalid action: An action creator must return a table") | ||
|
||
result.type = name | ||
|
||
return result | ||
end | ||
}) | ||
end | ||
|
||
return makeActionCreator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
return function() | ||
local makeActionCreator = require(script.Parent.makeActionCreator) | ||
|
||
it("should set the name of the actionCreator creator", function() | ||
local FooAction = makeActionCreator("foo", function() | ||
return {} | ||
end) | ||
|
||
expect(FooAction.name).to.equal("foo") | ||
end) | ||
|
||
it("should return a table when called as a function", function() | ||
local FooAction = makeActionCreator("foo", function() | ||
return {} | ||
end) | ||
|
||
expect(FooAction()).to.be.a("table") | ||
end) | ||
|
||
it("should set the type of the action creator", function() | ||
local FooAction = makeActionCreator("foo", function() | ||
return {} | ||
end) | ||
|
||
expect(FooAction().type).to.equal("foo") | ||
end) | ||
|
||
it("should set values", function() | ||
local FooAction = makeActionCreator("foo", function(value) | ||
return { | ||
value = value | ||
} | ||
end) | ||
|
||
expect(FooAction(100).value).to.equal(100) | ||
end) | ||
|
||
it("should throw when its result does not return a table", function() | ||
local FooAction = makeActionCreator("foo", function() | ||
return function() end | ||
end) | ||
|
||
expect(FooAction).to.throw() | ||
end) | ||
|
||
it("should throw if the first argument is not a string", function() | ||
expect(function() | ||
makeActionCreator(nil, function() | ||
return {} | ||
end) | ||
end).to.throw() | ||
|
||
expect(function() | ||
makeActionCreator(100, function() | ||
return {} | ||
end) | ||
end).to.throw() | ||
end) | ||
|
||
it("should throw if the second argument is not a function", function() | ||
expect(function() | ||
makeActionCreator("foo", nil) | ||
end).to.throw() | ||
|
||
expect(function() | ||
makeActionCreator("foo", {}) | ||
end).to.throw() | ||
end) | ||
end |