generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #630 from codeKraken19/xstate-actors
Add Reusable Xstate actors and utils
- Loading branch information
Showing
7 changed files
with
23,275 additions
and
13,514 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,106 +1,108 @@ | ||
{ | ||
"name": "@layer5/sistent", | ||
"version": "0.14.11", | ||
"description": "Reusable React Components and SVG Icons library", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://[email protected]/layer5io/sistent.git" | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index..js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "NODE_ENV=production tsup", | ||
"build:watch": "NODE_ENV=production tsup --watch", | ||
"commitlint": "commitlint --edit", | ||
"coverage": "jest --coverage", | ||
"dev": "NODE_ENV=development tsup", | ||
"format:check": "prettier --check \"**/*.{ts,tsx,md}\" --config ./.prettierrc", | ||
"format:write": "prettier --write \"**/*.{ts,tsx,md}\" --config ./.prettierrc", | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"lint:fix": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --fix", | ||
"prepare": "husky install", | ||
"test": "jest", | ||
"versionup:major": "npm version major", | ||
"versionup:minor": "npm version minor", | ||
"versionup:patch": "npm version patch" | ||
}, | ||
"lint-staged": { | ||
"*.{ts,tsx,md}": [ | ||
"prettier --write", | ||
"eslint --fix" | ||
] | ||
"name": "@layer5/sistent", | ||
"version": "0.14.11", | ||
"description": "Reusable React Components and SVG Icons library", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://[email protected]/layer5io/sistent.git" | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index..js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "NODE_ENV=production tsup", | ||
"build:watch": "NODE_ENV=production tsup --watch", | ||
"commitlint": "commitlint --edit", | ||
"coverage": "jest --coverage", | ||
"dev": "NODE_ENV=development tsup", | ||
"format:check": "prettier --check \"**/*.{ts,tsx,md}\" --config ./.prettierrc", | ||
"format:write": "prettier --write \"**/*.{ts,tsx,md}\" --config ./.prettierrc", | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"lint:fix": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --fix", | ||
"prepare": "husky install", | ||
"test": "jest", | ||
"versionup:major": "npm version major", | ||
"versionup:minor": "npm version minor", | ||
"versionup:patch": "npm version patch" | ||
}, | ||
"lint-staged": { | ||
"*.{ts,tsx,md}": [ | ||
"prettier --write", | ||
"eslint --fix" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^17.7.2", | ||
"@commitlint/config-conventional": "^17.7.0", | ||
"@mui/icons-material": "^5.15.11", | ||
"@testing-library/react": "^14.1.2", | ||
"@types/jest": "^29.5.11", | ||
"@types/react": "^18.2.45", | ||
"@types/react-dom": "^18.2.18", | ||
"@typescript-eslint/eslint-plugin": "^6.12.0", | ||
"@typescript-eslint/parser": "^6.12.0", | ||
"commitizen": "^4.3.0", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^8.49.0", | ||
"eslint-plugin-react": "^7.33.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.4.4", | ||
"eslint-plugin-storybook": "^0.6.15", | ||
"husky": "^8.0.0", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"lint-staged": "^14.0.1", | ||
"mui-datatables": "^4.3.0", | ||
"notistack": "^3.0.1", | ||
"prettier": "^3.0.3", | ||
"prettier-plugin-organize-imports": "^3.2.3", | ||
"react-error-boundary": "^4.0.12", | ||
"react-markdown": "^8.0.7", | ||
"remark-gfm": "^3.0.1", | ||
"ts-jest": "^29.1.1", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.3.3" | ||
}, | ||
"peerDependencies": { | ||
"@emotion/react": "^11.11.3", | ||
"@emotion/styled": "^11.11.0", | ||
"@mui/material": "^5.15.11", | ||
"@types/mui-datatables": "*", | ||
"mui-datatables": "*", | ||
"react": ">=17", | ||
"react-dom": ">=17", | ||
"@xstate/react": "^4.1.1", | ||
"xstate": "^5.13.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"@emotion/react": { | ||
"optional": true | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
"@emotion/styled": { | ||
"optional": true | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^17.7.2", | ||
"@commitlint/config-conventional": "^17.7.0", | ||
"@mui/icons-material": "^5.15.11", | ||
"@testing-library/react": "^14.1.2", | ||
"@types/jest": "^29.5.11", | ||
"@types/react": "^18.2.45", | ||
"@types/react-dom": "^18.2.18", | ||
"@typescript-eslint/eslint-plugin": "^6.12.0", | ||
"@typescript-eslint/parser": "^6.12.0", | ||
"commitizen": "^4.3.0", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^8.49.0", | ||
"eslint-plugin-react": "^7.33.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.4.4", | ||
"eslint-plugin-storybook": "^0.6.15", | ||
"husky": "^8.0.0", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"lint-staged": "^14.0.1", | ||
"mui-datatables": "^4.3.0", | ||
"notistack": "^3.0.1", | ||
"prettier": "^3.0.3", | ||
"prettier-plugin-organize-imports": "^3.2.3", | ||
"react-error-boundary": "^4.0.12", | ||
"react-markdown": "^8.0.7", | ||
"remark-gfm": "^3.0.1", | ||
"ts-jest": "^29.1.1", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.3.3" | ||
"@mui/material": { | ||
"optional": true | ||
}, | ||
"peerDependencies": { | ||
"@emotion/react": "^11.11.3", | ||
"@emotion/styled": "^11.11.0", | ||
"@mui/material": "^5.15.11", | ||
"@types/mui-datatables": "*", | ||
"mui-datatables": "*", | ||
"react": ">=17", | ||
"react-dom": ">=17" | ||
"mui-datatables": { | ||
"optional": true | ||
}, | ||
"peerDependenciesMeta": { | ||
"@emotion/react": { | ||
"optional": true | ||
}, | ||
"@emotion/styled": { | ||
"optional": true | ||
}, | ||
"@mui/material": { | ||
"optional": true | ||
}, | ||
"mui-datatables": { | ||
"optional": true | ||
}, | ||
"react": { | ||
"optional": true | ||
}, | ||
"react-dom": { | ||
"optional": true | ||
} | ||
"react": { | ||
"optional": true | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
"react-dom": { | ||
"optional": true | ||
} | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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,18 @@ | ||
export { | ||
DATA_VALIDATOR_COMMANDS, | ||
DATA_VALIDATOR_EVENTS, | ||
dataValidatorCommands, | ||
dataValidatorEvents, | ||
dataValidatorMachine, | ||
selectIsValidating, | ||
selectValidationResults | ||
} from './validators/dataValidator'; | ||
|
||
export { | ||
XSTATE_DEBUG_EVENT, | ||
deadLetter, | ||
forwardToActors, | ||
reply, | ||
sendToActor, | ||
sendToActors | ||
} from './utils'; |
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,45 @@ | ||
// disbale stict no any for now for full file | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import { AnyActorRef, AnyEventObject, enqueueActions, sendTo } from 'xstate'; | ||
import { AnyActorSystem } from 'xstate/dist/declarations/src/system'; | ||
|
||
type ContextWithReturnAddress = { returnAddress: AnyActorRef }; | ||
|
||
export const sendToActor = (actor: string, event: AnyEventObject) => | ||
sendTo(({ system }: { system: AnyActorSystem }) => { | ||
console.log('sendToActor', actor, event); | ||
return system.get(actor); | ||
}, event); | ||
|
||
export const sendToActors = ( | ||
actorSystemIds: string[], | ||
eventCreator: (actionArgs: any, params: any) => AnyEventObject | ||
) => | ||
enqueueActions(({ enqueue, ...actionArgs }, params) => { | ||
actorSystemIds.forEach((actorSystemId) => { | ||
const actor = actionArgs.system.get(actorSystemId); | ||
if (!actor) { | ||
console.log('actor not found --sendToActors', actorSystemId); | ||
return; | ||
} | ||
enqueue.sendTo(actor, eventCreator(actionArgs, params)); | ||
}); | ||
}); | ||
|
||
export const forwardToActors = (actorSystemIds: string[]) => | ||
enqueueActions(({ enqueue, event, system }) => { | ||
actorSystemIds.forEach((actorSystemId) => { | ||
const actor = system.get(actorSystemId); | ||
if (actor) { | ||
enqueue.sendTo(actor, event); | ||
} | ||
}); | ||
}); | ||
|
||
export const deadLetter = (event: AnyEventObject) => ({ type: 'DEAD_LETTER', event }); | ||
|
||
export const reply = (eventFn: (actionArgs: any, params: any) => AnyEventObject) => | ||
sendTo(({ context }: { context: ContextWithReturnAddress }) => context.returnAddress, eventFn); | ||
|
||
export const XSTATE_DEBUG_EVENT = 'XSTATE_DEBUG_EVENT'; |
Oops, something went wrong.