Skip to content

Commit 00b2f1e

Browse files
feat: UNT-T31323: Init redux saga dev tool for expo
0 parents  commit 00b2f1e

29 files changed

+20712
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true

.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @generated by expo-module-scripts
2+
module.exports = require('expo-module-scripts/eslintrc.base.js');

.github/workflows/publish.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: '🚀 Publish'
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
release:
10+
name: 🚀 Publish
11+
runs-on: macos-13
12+
steps:
13+
- name: 📚 checkout
14+
uses: actions/[email protected]
15+
- name: 🟢 node
16+
uses: actions/[email protected]
17+
with:
18+
node-version: 18
19+
registry-url: https://registry.npmjs.org
20+
- name: 🚀 Build & Publish
21+
run: yarn install && cd webui && yarn install && yarn run export && cd .. && yarn build && yarn publish --access public
22+
env:
23+
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}

.gitignore

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Diagnostic reports (https://nodejs.org/api/report.html)
7+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
8+
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
*.pid.lock
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
*.lcov
18+
19+
# Dependency directories
20+
node_modules/
21+
22+
# TypeScript cache
23+
*.tsbuildinfo
24+
25+
# Optional npm cache directory
26+
.npm
27+
28+
# Optional eslint cache
29+
.eslintcache
30+
31+
# Optional REPL history
32+
.node_repl_history
33+
34+
# Output of 'npm pack'
35+
*.tgz
36+
37+
# dotenv environment variable files
38+
.env
39+
40+
# Build files
41+
build/
42+
dist/
43+
.expo/
44+
45+
*.DS_Store

LICENCE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2024 Matthew Oakes
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# redux-saga-devtools-expo-dev-plugin
2+
3+
A React Native Redux Saga DevTool that can run in an Expo App
4+
5+
# Installation
6+
7+
### Add the package to your project
8+
9+
```
10+
npx expo install redux-saga-devtools-expo-dev-plugin
11+
```
12+
13+
### Integrate redux saga with the DevTool hook
14+
15+
```jsx
16+
import createSagaMiddleware from 'redux-saga';
17+
18+
let sagaMiddleware = createSagaMiddleware();
19+
if (__DEV__) {
20+
// eslint-disable-next-line @typescript-eslint/no-var-requires
21+
const { createSagaMonitor } = require('redux-saga-devtools-expo-dev-plugin');
22+
sagaMiddleware = createSagaMiddleware({ sagaMonitor: createSagaMonitor() });
23+
}
24+
25+
const store = configureStore({
26+
reducer: rootReducer,
27+
devTools: false,
28+
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(sagaMiddleware),
29+
});
30+
```

babel.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @generated by expo-module-scripts
2+
module.exports = require('expo-module-scripts/babel.config.base');

expo-module.config.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"platforms": ["devtools"],
3+
"devtools": {
4+
"webpageRoot": "dist"
5+
}
6+
}

package.json

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "redux-saga-devtools-expo-dev-plugin",
3+
"version": "1.0.0",
4+
"description": "Expo DevTools Plugin for Redux Saga",
5+
"homepage": "https://github.com/Krunal-K-SimformSolutions/redux-saga-devtools-expo-dev-plugin",
6+
"license": "MIT",
7+
"main": "build/index.js",
8+
"types": "build/index.d.ts",
9+
"sideEffects": false,
10+
"scripts": {
11+
"build": "expo-module build",
12+
"test:types": "expo-module tsc --noEmit",
13+
"test:lint": "expo-module lint",
14+
"test": "npm run test:types && npm run test:lint",
15+
"clean": "expo-module clean",
16+
"prepare": "expo-module prepare && npm run web:install",
17+
"prepublishOnly": "expo-module prepublishOnly && npm run web:export",
18+
"web:install": "cd webui && npm install",
19+
"web:dev": "cd webui && npm start",
20+
"web:export": "cd webui && npm run export"
21+
},
22+
"keywords": [
23+
"expo",
24+
"devtools",
25+
"redux",
26+
"saga",
27+
"redux-saga",
28+
"plugin"
29+
],
30+
"files": [
31+
"build",
32+
"dist",
33+
"expo-module.config.json"
34+
],
35+
"author": "Simform Solutions",
36+
"dependencies": {
37+
"@redux-saga/is": "^1.0.1",
38+
"@redux-saga/core": "^1.3.0"
39+
},
40+
"devDependencies": {
41+
"expo": "~52.0.4",
42+
"expo-module-scripts": "^4.0.2",
43+
"typescript": "^5.6.3",
44+
"redux": "^4.0.1",
45+
"redux-saga": "^1.0.1"
46+
},
47+
"peerDependencies": {
48+
"expo": ">=52",
49+
"redux": "*",
50+
"redux-saga": "*"
51+
}
52+
}

src/EffectManager.ts

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { Effect } from "@redux-saga/types";
2+
import { Saga } from "redux-saga";
3+
4+
export interface MonitoredEffect {
5+
effectId: number;
6+
parentEffectId?: number;
7+
name?: string;
8+
description?: string;
9+
saga?: Saga;
10+
root?: boolean;
11+
args?: any[];
12+
status: string;
13+
start?: number;
14+
end?: number;
15+
duration?: number;
16+
error?: any;
17+
label?: string;
18+
winner?: boolean;
19+
result?: any;
20+
21+
effect?: Effect;
22+
}
23+
24+
export default class EffectManager {
25+
rootIds: number[];
26+
map: { [id: number]: MonitoredEffect };
27+
childIdsMap: { [id: number]: number[] };
28+
alreadyExecutedEffects: Array<any> = [];
29+
30+
constructor() {
31+
this.rootIds = [];
32+
this.map = {};
33+
this.childIdsMap = {};
34+
}
35+
36+
get(effectId: number): MonitoredEffect {
37+
return this.map[effectId];
38+
}
39+
40+
set(effectId: number, desc: MonitoredEffect): void {
41+
this.map[effectId] = desc;
42+
43+
if (desc.parentEffectId && !this.childIdsMap[desc.parentEffectId]) {
44+
this.childIdsMap[desc.parentEffectId] = [];
45+
}
46+
if (desc.parentEffectId) {
47+
this.childIdsMap[desc.parentEffectId]?.push(effectId);
48+
}
49+
}
50+
51+
setRootEffect(effectId: number, desc: MonitoredEffect): void {
52+
this.rootIds?.push(effectId);
53+
this.set(effectId, { ...desc, root: true });
54+
}
55+
56+
getRootIds(): number[] {
57+
return this.rootIds;
58+
}
59+
60+
getChildIds(parentEffectId: number): number[] {
61+
return this.childIdsMap[parentEffectId] || [];
62+
}
63+
64+
setAlreadyExecutedEffects(params: any) {
65+
this.alreadyExecutedEffects.push(params);
66+
}
67+
68+
get allAlreadyExecutedEffects(): Array<any> {
69+
return this.alreadyExecutedEffects;
70+
}
71+
72+
clearAlreadyExecutedEffects() {
73+
this.alreadyExecutedEffects = [];
74+
}
75+
}

src/constants.ts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { effectTypes } from "redux-saga/effects";
2+
3+
const {
4+
TAKE,
5+
PUT,
6+
ALL,
7+
RACE,
8+
CALL,
9+
CPS,
10+
FORK,
11+
JOIN,
12+
CANCEL,
13+
SELECT,
14+
ACTION_CHANNEL,
15+
CANCELLED,
16+
FLUSH,
17+
GET_CONTEXT,
18+
SET_CONTEXT,
19+
} = effectTypes;
20+
21+
const PARALLEL = "PARALLEL";
22+
const ITERATOR = "ITERATOR";
23+
const PROMISE = "PROMISE"; // not from redux-saga
24+
const UNKNOWN = "UNKNOWN"; // not from redux-saga
25+
26+
// monitoring statuses
27+
const PENDING = "PENDING";
28+
const RESOLVED = "RESOLVED";
29+
const REJECTED = "REJECTED";
30+
31+
export {
32+
TAKE,
33+
PUT,
34+
ALL,
35+
RACE,
36+
CALL,
37+
CPS,
38+
FORK,
39+
JOIN,
40+
CANCEL,
41+
SELECT,
42+
ACTION_CHANNEL,
43+
CANCELLED,
44+
FLUSH,
45+
GET_CONTEXT,
46+
SET_CONTEXT,
47+
PARALLEL,
48+
ITERATOR,
49+
PROMISE,
50+
UNKNOWN,
51+
PENDING,
52+
RESOLVED,
53+
REJECTED,
54+
};

src/helpers/getEffectDescription.ts

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import * as is from "@redux-saga/is";
2+
import { Effect } from "@redux-saga/types";
3+
4+
import * as effectTypes from "../constants";
5+
6+
const getEffectDescription = (
7+
effect: Effect | any[] | IterableIterator<any> | Promise<any>,
8+
): any => {
9+
if (!effect) return effectTypes.UNKNOWN;
10+
11+
if ((effect as any)?.root) return (effect as any)?.saga?.name; // TODO: Better typing
12+
if (is.iterator(effect)) {
13+
return (effect as any)?.name || effectTypes.UNKNOWN;
14+
}
15+
if (is.array(effect)) return null;
16+
if (is.promise(effect)) {
17+
let display: string;
18+
if ((effect as any)?.name) {
19+
// a promise object with a manually set name prop for display reasons
20+
display = `${effectTypes.PROMISE}(${(effect as any)?.name})`;
21+
} else if (effect?.constructor instanceof Promise.constructor) {
22+
// an anonymous promise
23+
display = effectTypes.PROMISE;
24+
} else {
25+
// class which extends Promise, so output the name of the class to precise
26+
display = `${effectTypes.PROMISE}(${effect?.constructor?.name})`;
27+
}
28+
return display;
29+
}
30+
if (is.effect(effect)) {
31+
const { type, payload: data } = (effect || {}) as Effect;
32+
if (type === effectTypes.TAKE) {
33+
return data?.pattern || "channel";
34+
} else if (type === effectTypes.PUT) {
35+
return data?.channel ? data?.action : data?.action?.type;
36+
} else if (type === effectTypes.ALL) {
37+
return null;
38+
} else if (type === effectTypes.RACE) {
39+
return null;
40+
} else if (type === effectTypes.CALL) {
41+
return !data?.fn?.name || data?.fn?.name?.trim() === ""
42+
? "(anonymous)"
43+
: data?.fn?.name;
44+
} else if (type === effectTypes.CPS) {
45+
return data?.fn?.name;
46+
} else if (type === effectTypes.FORK) {
47+
return data?.fn?.name;
48+
} else if (type === effectTypes.JOIN) {
49+
return data?.name;
50+
} else if (type === effectTypes.CANCEL) {
51+
return data?.name;
52+
} else if (type === effectTypes.SELECT) {
53+
return data?.selector?.name;
54+
} else if (type === effectTypes.ACTION_CHANNEL) {
55+
return data?.buffer == null ? data?.pattern : data;
56+
} else if (type === effectTypes.CANCELLED) {
57+
return null;
58+
} else if (type === effectTypes.FLUSH) {
59+
return data;
60+
} else if (type === effectTypes.GET_CONTEXT) {
61+
return data;
62+
} else if (type === effectTypes.SET_CONTEXT) {
63+
return data;
64+
}
65+
}
66+
67+
return effectTypes.UNKNOWN;
68+
};
69+
70+
export default getEffectDescription;

0 commit comments

Comments
 (0)