Central rewind stack for Ember apps that work with chatty APIs.
npm install ember-rewind-stackThe question is - what happens when some critical path call fails in the middle of one of these giant chains?
Enter the rewind-stack-service, which allows you to manage multiple, possibly parallel, operation stacks. In the event of a failure, your .catch() block can ask the service for all the completed operations, and then take action to roll-back the changes.
ember install ember-rewind-stack
.catch(), then consider using this.| method | returns | description |
| --- | --- | --- |
| addOperation (stackName, operationObj) | n/a | add an operation to a named stack. Creates the stack if it does not exist. Sets the .current to the passed in operation. If there is a .current, it is pushed into the stack's .completed array. A .startedAt property is added to the operation when pushed in. A .completedAt property is set when it's pushed into the .completed array.|
| completeOperation (stackName, options) | n/a | Moves the current operation onto the .completed array, adding the .completedAt property, and clearing the stack's .current property. The options are merged into the current operation, allowing useful stuff like itemId's to be added after an operation completes.|
| getCompleted (stackName) | array of completed operations, reversed | Used by exception handlers to rewind the completed actions |
| removeStack (stackName) | n/a | clean up a stack |
| getCurrent (stackName) | Current Operation Obj | Returns the current operation |
| getStack (stackName) | stack object | returns the entire stack object |
````
{
"name": "create site item", // some sort of name that makes sense to you
"type": "create-item", // something that would make sense in a log
"cleanup": "remove-item", // a key for your clean up code to use...
"inputs": { // whatever your cleanup code needs...
"id": "3ef...", // in this case, to delete an item we need the id and owner
"owner": "dcadmin"
}
}