Created
February 15, 2023 19:04
-
-
Save ahmadseder/5071930acd143afd95eb5cb705646316 to your computer and use it in GitHub Desktop.
Canaan CQRS
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
# You need to clone the project and run it | |
# For the CQRS and domains create everything under a file called CQRS.js | |
# For handling the flow create a file called services.js |
Import this file to https://www.json-rule-editor.com/#/home and initialise the rules engine
{
"name": "Demo",
"attributes": [
{
"name": "data",
"type": "object"
},
{
"name": "context",
"type": "object"
},
{
"name": "user.data.info.subscriptionType",
"type": "string"
},
{
"name": "type",
"type": "string"
},
{
"name": "CanaanApp.data.commandCounter.projects-addEntry.count",
"type": "number"
}
],
"decisions": [
{
"conditions": {
"all": [
{
"fact": "data",
"operator": "equal",
"value": "Free",
"path": ".user.data.info.subscriptionType"
},
{
"fact": "context",
"operator": "equal",
"value": "addEntry",
"path": ".type"
},
{
"fact": "data",
"operator": "greaterThanInclusive",
"value": "3",
"path": ".CanaanApp.data.commandCounter.projects-addEntry.count"
}
]
},
"event": {
"type": "FreeSubscriptionLimitExceeded",
"params": {
"message": "You are on a free plan You can't add on more than 3 logs per visit, Upgrade your plan to add more"
}
}
}
]
}
To use the subscribe with React use
const [some,setSome] = useState();
useEffect(()=>{
domain.subscribe(query,setSome);
},[]);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check the utils file to get all the needed functionality
You will need to use two domains ( projects, and user ) and should be named like this
The project app will be like this
So when creating commands or queries the paths will be
selectedProject
,balance
,entries[]
, andprojects[]
mind the brackets and check the documentation if you haven't alreadyThe query doesn't require
[]
so you can directly define the path asentries
for exampleFor the user it will be
so the path will
info