@tramvai/core 2.11.0 → 2.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +51 -0
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -97,6 +97,30 @@ class ModulePubSub {
97
97
  - `params` - data passed to action
98
98
  - `deps` - List of providers that are needed for the action to work
99
99
  - `conditions` - List of restrictions for the execution of the action
100
+ - `conditionsFailResult` - [see](#conditionsfailresult)
101
+
102
+ #### Action Execution Context
103
+
104
+ Action execution context that contains some helper functions and resolved deps
105
+
106
+ Context has next fields:
107
+ - `deps` - resolved deps that were specified when declaring action
108
+ - `executeAction` - allows to execute another actions inside current one
109
+ - `getState` - quick access to `STORE_TOKEN.getState`
110
+ - `dispatch` - quick access to `STORE_TOKEN.dispatch`
111
+ - `abortSignal` - instance of signal related to the current execution tree
112
+ - `abortController` - instance of `AbortController` created exclusively for the current action execution
113
+
114
+ #### conditionsFailResult
115
+
116
+ Specifies the output of the action in case its `conditions` was not met during execution.
117
+
118
+ > If `conditions` are not met for action, action's `fn` won't be executed in any way
119
+
120
+ Possible values for the `conditionsFailResult`:
121
+ - `empty` - (default) execution will be resolved with `undefined` as a result
122
+ - `error` - execution will be rejected with [ConditionFailError](references/libs/errors.md#conditionfailerror)
123
+
100
124
 
101
125
  #### Usage example
102
126
 
@@ -117,6 +141,33 @@ declareAction({
117
141
  });
118
142
  ```
119
143
 
144
+ abort execution:
145
+ ```ts
146
+ const innerAction = declareAction(/** ... */);
147
+
148
+ const action = declareAction({
149
+ name: 'root',
150
+ async fn() {
151
+ setTimeout(() => {
152
+ this.abortController.abort()
153
+ }, 4000);
154
+
155
+ const { payload } = await this.deps.httpClient.request({
156
+ url: 'https://www.domain.com/api/endpoint',
157
+ // pass signal to the request
158
+ signal: this.abortSignal,
159
+ });
160
+
161
+ // if innerAction1 will end after abortController.abort was called
162
+ // then calling innerAction2 will throw an instance of ExecutionAbortError
163
+ await this.executeAction(innerAction, payload);
164
+ },
165
+ deps: {
166
+ httpClient: HTTP_CLIENT,
167
+ },
168
+ });
169
+ ```
170
+
120
171
  ### createBundle
121
172
 
122
173
  `createBundle(options: BundleOptions)` - method to create a bundle.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/core",
3
- "version": "2.11.0",
3
+ "version": "2.21.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -20,10 +20,10 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@tinkoff/utils": "^2.1.2",
23
- "@tramvai/tokens-common": "2.11.0",
24
- "@tramvai/tokens-core": "2.11.0",
25
- "@tramvai/types-actions-state-context": "2.11.0",
26
- "@tinkoff/dippy": "0.7.45",
23
+ "@tramvai/tokens-common": "2.21.0",
24
+ "@tramvai/tokens-core": "2.21.0",
25
+ "@tramvai/types-actions-state-context": "2.21.0",
26
+ "@tinkoff/dippy": "0.8.2",
27
27
  "tslib": "^2.0.3"
28
28
  },
29
29
  "peerDependencies": {