Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from Roblox:master #9

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aa744e7
Update non-cached third party actions to use Roblox-ActionsCache in G…
ZoteTheMighty Feb 16, 2022
82f6a37
Merge pull request #67 from Roblox/eeci-2596-update-gha-non-cached-ac…
cliffchapmanrbx Feb 25, 2022
8aa7b32
Change the path of the `setup-foreman` action to reflect its current …
ZoteTheMighty Mar 21, 2022
6382570
Add extra argument to thunk middleware (#69)
tonycuadra Mar 24, 2022
574ba20
Add Error Reporter docs
ZoteTheMighty Apr 21, 2022
07f634e
Add Luau types for actions and reducers (#70)
jkelaty-rbx Jun 9, 2022
ce63e3d
Add Luau types for thunks and the store (#71)
jkelaty-rbx Jun 13, 2022
1ab1845
Bump version to 4.0.0
ghostnaps Jul 18, 2022
550a45a
Mark changes for v4
ghostnaps Jul 18, 2022
5f15988
Add wally.toml
ghostnaps Jul 18, 2022
64a5dcb
Use a release candidate
ghostnaps Jul 18, 2022
4518ddb
Use luau-lsp for analysis (#75)
ghostnaps Jul 18, 2022
a7c8ab7
Merge remote-tracking branch 'origin/master' into bump-version
ghostnaps Jul 18, 2022
800f1cb
Update changelog version to use rc
ghostnaps Jul 18, 2022
6758f69
Bump version to 4.0.0-rc.0
ghostnaps Jul 19, 2022
8c8da37
Adds support for non-string error objects to be caught by NoYield (#79)
ZoteTheMighty Oct 7, 2022
a5002a3
Luau Type Improvements (#76)
jkelaty-rbx Oct 7, 2022
2f9e881
Only call Signal tracebacks in dev mode (#78)
jkelaty-rbx Oct 7, 2022
b8a5d01
update CLA signature bot workflow
Jan 18, 2023
3b4a327
Merge pull request #80 from Roblox/fix/EECI-4699-update-clabot-workflows
rgychiu Jan 30, 2023
7664c16
Update clabot.yml
ZoteTheMighty Aug 22, 2023
9099e95
LUAFDN-1706 Add support for devtools (#84)
zovits Aug 22, 2023
68cb44c
#flagged - Add Flag around disabling connection callbacks
pturner-roblox Nov 19, 2024
f29a4de
Merge pull request #98 from pturner-roblox/connect-traceback-flag
jkelaty-rbx Nov 19, 2024
bfab958
Remove CLA bot
BitwiseAndrea Nov 20, 2024
d8a2ea5
Merge pull request #100 from Roblox/adhoc/remove-cla-bot
BitwiseAndrea Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ on:
- master

jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: Roblox/setup-foreman@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Download global Roblox types
shell: bash
run: curl -s -O https://raw.githubusercontent.com/JohnnyMorganz/luau-lsp/master/scripts/globalTypes.d.lua

- name: Generate sourcemap for LSP
shell: bash
run: rojo sourcemap default.project.json -o sourcemap.json

- name: Analyze
shell: bash
run: luau-lsp analyze --sourcemap=sourcemap.json --defs=globalTypes.d.lua --defs=testez.d.lua src/


test:
runs-on: ubuntu-latest

Expand All @@ -18,11 +40,11 @@ jobs:
with:
submodules: true

- uses: leafo/gh-actions-lua@v8
- uses: roblox-actionscache/leafo-gh-actions-lua@v8
with:
luaVersion: "5.1"

- uses: leafo/gh-actions-luarocks@v4
- uses: roblox-actionscache/leafo-gh-actions-luarocks@v4

- name: Install dependencies
run: |
Expand All @@ -31,27 +53,26 @@ jobs:
luarocks install luacov-reporter-lcov

- name: install code quality tools
uses: rojo-rbx/setup-foreman@v1
uses: Roblox/setup-foreman@v1
with:
version: "^1.0.1"
token: ${{ secrets.GITHUB_TOKEN }}

- name: install and run darklua
- name: code quality
shell: bash
run: |
selene src
stylua -c src/

- name: run darklua
run: |
cargo install --git https://gitlab.com/seaofvoices/darklua.git#v0.6.0
darklua process src/ src/ --format retain-lines

- name: Test
run: |
lua -lluacov test/lemur.lua
luacov -r lcov

- name: code quality
shell: bash
run: |
selene src
stylua -c src/

- name: Report to Coveralls
uses: coverallsapp/[email protected]
with:
Expand Down
21 changes: 0 additions & 21 deletions .github/workflows/clabot.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ roblox.toml
# Darklua
**/darklua*

# Analysis artifacts
sourcemap.json
globalTypes.d.lua

# Misc OS and editor files
.DS_Store
.vscode
Expand Down
43 changes: 28 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,40 @@

## Unreleased Changes

Nothing yet...

## 4.0.0-rc.0 (2022-07-18)

- Add makeThunkMiddleware to inject custom argument ([#69](https://github.com/Roblox/rodux/pull/69)).
- Add Luau types for actions and reducers ([#70](https://github.com/Roblox/rodux/pull/70)).
- Add Luau types for thunks and the store ([#71](https://github.com/Roblox/rodux/pull/71)).

## 3.0.0 (2021-03-25)
* Revise error reporting logic; restore default semantics from version 1.x ([#61](https://github.com/Roblox/rodux/pull/61)).

- Revise error reporting logic; restore default semantics from version 1.x ([#61](https://github.com/Roblox/rodux/pull/61)).

## 2.0.0 (2021-03-17)
* Introduce error handling to catch and report errors during reducers ([#60](https://github.com/Roblox/rodux/pull/60)).

- Introduce error handling to catch and report errors during reducers ([#60](https://github.com/Roblox/rodux/pull/60)).

## 1.1.0 (2021-01-04)
* Added color schemes for documentation based on user preference ([#56](https://github.com/Roblox/rodux/pull/56)).
* Added `makeActionCreator` utility for common action creator pattern ([#35](https://github.com/Roblox/rodux/pull/35))

- Added color schemes for documentation based on user preference ([#56](https://github.com/Roblox/rodux/pull/56)).
- Added `makeActionCreator` utility for common action creator pattern ([#35](https://github.com/Roblox/rodux/pull/35))

## 1.0.0 (2019-09-18)
* Added `combineReducers` utility, mirroring Redux's ([#9](https://github.com/Roblox/rodux/pull/9))
* Added `createReducer` utility, similar to `redux-create-reducer` ([#10](https://github.com/Roblox/rodux/pull/10))
* `type` is now required as a field on all actions
* Introduced middleware ([#13](https://github.com/Roblox/rodux/pull/13))
* Thunks are no longer enabled by default, use `Rodux.thunkMiddleware` to add them back.
* Added `Rodux.loggerMiddleware` as a simple debugger
* The middleware API changed in [#29](https://github.com/Roblox/rodux/pull/29) in a backwards-incompatible way!
* Middleware now run left-to-right instead of right-to-left!
* Errors thrown in `changed` event now have correct stack traces ([#27](https://github.com/Roblox/rodux/pull/27))
* Fixed `createReducer` having incorrect behavior with `nil` state values ([#33](https://github.com/Roblox/rodux/pull/33))

- Added `combineReducers` utility, mirroring Redux's ([#9](https://github.com/Roblox/rodux/pull/9))
- Added `createReducer` utility, similar to `redux-create-reducer` ([#10](https://github.com/Roblox/rodux/pull/10))
- `type` is now required as a field on all actions
- Introduced middleware ([#13](https://github.com/Roblox/rodux/pull/13))
- Thunks are no longer enabled by default, use `Rodux.thunkMiddleware` to add them back.
- Added `Rodux.loggerMiddleware` as a simple debugger
- The middleware API changed in [#29](https://github.com/Roblox/rodux/pull/29) in a backwards-incompatible way!
- Middleware now run left-to-right instead of right-to-left!
- Errors thrown in `changed` event now have correct stack traces ([#27](https://github.com/Roblox/rodux/pull/27))
- Fixed `createReducer` having incorrect behavior with `nil` state values ([#33](https://github.com/Roblox/rodux/pull/33))

## Public Release (2017-12-13)
* Initial release!

- Initial release!
72 changes: 72 additions & 0 deletions docs/advanced/devtools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
The fifth argument to [`Store.new`](../api-reference.md#storenew) takes a devtools object that you can optionally provide. A devtools object has only two requirements: `devtools.__className` must be `"Devtools"` and `devtools:_hookIntoStore(store)` must be a valid function call. Beyond that, your devtools can be anything you need it to be.

Devtools can be very useful during development in gathering performance data, providing introspection, debugging, etc. We leave the devtools implementation up to the user in order to support any and all use cases, such as store modification in unit testing, live state inspection plugins, and whatever else you come up with.

A simple example of a devtools that profiles and logs:

```Lua
local Devtools = {}
Devtools.__className = "Devtools"
Devtools.__index = Devtools

-- Creates a new Devtools object
function Devtools.new()
local self = setmetatable({
_events = table.create(100),
_eventsIndex = 0,
}, Devtools)

return self
end

-- Overwrites the store's reducer and flushHandler with wrapped versions that contain logging and profiling
function Devtools:_hookIntoStore(store)
self._store = store
self._source = store._source

self._originalReducer = store._reducer
store._reducer = function(state: any, action: any): any
local startClock = os.clock()
local result = self._originalReducer(state, action)
local stopClock = os.clock()

self:_addEvent("Reduce", {
name = action.type or tostring(action),
elapsedMs = (stopClock - startClock) * 1000,
action = action,
state = result,
})
return result
end

self._originalFlushHandler = store._flushHandler
store._flushHandler = function(...)
local startClock = os.clock()
self._originalFlushHandler(...)
local stopClock = os.clock()

self:_addEvent("Flush", {
name = "@@FLUSH",
elapsedMs = (stopClock - startClock) * 1000,
listeners = table.clone(store.changed._listeners),
})
end
end

-- Adds an event to the log
-- Automatically adds event.timestamp and event.source
function Devtools:_addEvent(eventType: "Reduce" | "Flush", props: { [any]: any })
self._eventsIndex = (self._eventsIndex or 0) + 1
self._events[self._eventsIndex] = {
eventType = eventType,
source = self._source,
timestamp = DateTime.now().UnixTimestampMillis,
props = props,
}
end

-- Returns a shallow copy of the event log
function Devtools:GetLoggedEvents()
return table.clone(self._events)
end
```
55 changes: 55 additions & 0 deletions docs/advanced/error-reporters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
When Rodux encounters errors during action processing or when updating consumers, it will rethrow them by default. In some cases, you may want to intercept errors and record them somewhere useful, often with additional context.

The `Rodux.Store.new` function accepts an optional `errorReporter` object with the following shape:
```
ErrorReporter = {
reportReducerError(prevState, action, errorResult) -> (),
reportUpdateError(prevState, currentState, actionLog, errorResult) -> (),
}
```

The default implementation used by rodux looks like this:
```lua
local rethrowErrorReporter = {
reportReducerError = function(prevState, action, errorResult)
error(string.format("Received error: %s\n\n%s", errorResult.message, errorResult.thrownValue))
end,
reportUpdateError = function(prevState, currentState, lastActions, errorResult)
error(string.format("Received error: %s\n\n%s", errorResult.message, errorResult.thrownValue))
end,
}
```

In practice, you might use a custom error reporter to send detailed error information to an analytics endpoint:
```lua
-- This example supposes that we have some utilities for serializing the store
-- objects that were involved when an error was thrown
local inspectObject = require(MyUtils.inspectObject)
local tableDiff = require(MyUtils.tableDiff)
local sendToAnalyticsBackend = require(MyUtils.sendToAnalyticsBackend)

local rethrowErrorReporter = {
reportReducerError = function(prevState, action, errorResult)
local message = string.format(
"%s\n\nAction:\n%s\n\nError contents:\n%s",
errorResult.message,
inspectObject(action),
tostring(errorResult.thrownValue)
)
sendToAnalyticsBackend(message)
end,
reportUpdateError = function(prevState, currentState, lastActions, errorResult)
local message = string.format(
"%s\n\n" ..
"Store changes in the last flush:\n%s\n\n" ..
"Most recent actions (starting with the oldest):\n%s\n\n" ..
"Error contents:\n%s",
errorResult.message,
inspectObject(tableDiff(prevState, currentState)),
inspectObject(actionLog),
tostring(errorResult.thrownValue)
)
sendToAnalyticsBackend(message)
end,
}
```
27 changes: 26 additions & 1 deletion docs/advanced/thunks.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,29 @@ store:dispatch(function(store)
end)
```

Thunks are a simple way to introduce more complex processing of `action` objects, but you may want to consider creating custom [`middleware`](middleware.md) for complex features instead of relying on thunks alone.
Thunks are a simple way to introduce more complex processing of `action` objects, but you may want to consider creating custom [`middleware`](middleware.md) for complex features instead of relying on thunks alone.

It is also possible to inject a custom argument into the thunk middleware. This is useful for cases like using an API service layer that could be swapped out for a mock service in tests. This is accomplished by using the `Rodux.makeThunkMiddleware` API instead:

```lua
local myThunkMiddleware = Rodux.makeThunkMiddleware(myCustomArg)
local store = Rodux.Store.new(reducer, initialState, {
myThunkMiddleware,
})

store:dispatch(function(store, myCustomArg)
print("Hello from a thunk with extra argument:", myCustomArg)
store:dispatch({
type = "thunkAction"
})
end)
```

If multiple values need to be passed in, they can be combined into a single table:

```lua
local myThunkMiddleware = Rodux.makeThunkMiddleware({
[RoactNetworking] = networking,
AvatarEditorService = AvatarEditorService,
})
```
Loading