@tramvai/core 2.7.0 → 2.11.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.
- package/README.md +10 -11
- package/lib/actions/createActions.d.ts +3 -0
- package/lib/actions/declareAction.d.ts +3 -0
- package/lib/actions/declareAction.test-types.d.ts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.es.js +14 -1
- package/lib/index.js +15 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -83,31 +83,30 @@ class ModulePubSub {
|
|
|
83
83
|
}
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
###
|
|
86
|
+
### declareAction
|
|
87
87
|
|
|
88
|
-
`
|
|
88
|
+
`declareAction` - Method for creating asynchronous actions. It is used both for building chains of sagas and for performing global actions when building a response to a client
|
|
89
89
|
|
|
90
90
|
[More about actions](concepts/action.md)
|
|
91
91
|
|
|
92
|
-
####
|
|
92
|
+
#### declareAction({ name, fn, deps, conditions })
|
|
93
93
|
|
|
94
94
|
- `name` - The name of the action, a unique identifier is expected
|
|
95
|
-
- `fn(
|
|
96
|
-
- `
|
|
97
|
-
- `
|
|
98
|
-
- `deps` - provider instances from `deps`
|
|
95
|
+
- `fn(...params)` - Implementation of the action, this function will be called when the action is used, maybe `async`
|
|
96
|
+
- `this` - action execution context that contains some helper functions and resolved deps
|
|
97
|
+
- `params` - data passed to action
|
|
99
98
|
- `deps` - List of providers that are needed for the action to work
|
|
100
99
|
- `conditions` - List of restrictions for the execution of the action
|
|
101
100
|
|
|
102
101
|
#### Usage example
|
|
103
102
|
|
|
104
103
|
```tsx
|
|
105
|
-
import {
|
|
104
|
+
import { declareAction } from '@tramvai/core';
|
|
106
105
|
|
|
107
|
-
|
|
106
|
+
declareAction({
|
|
108
107
|
name: 'action log error',
|
|
109
|
-
fn
|
|
110
|
-
deps.logger.error('ERROR');
|
|
108
|
+
fn(payload) {
|
|
109
|
+
this.deps.logger.error('ERROR');
|
|
111
110
|
},
|
|
112
111
|
deps: {
|
|
113
112
|
logger: 'logger',
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { ActionParameters, Action } from '@tramvai/tokens-core';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated: use `declareAction`
|
|
4
|
+
*/
|
|
2
5
|
export declare function createAction<Result = any, Payload = any, Deps = any>(action: ActionParameters<Payload, Result, Deps>): Action<Payload, Result, Deps>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TramvaiAction, TramvaiActionDefinition } from '@tramvai/types-actions-state-context';
|
|
2
|
+
export declare function declareAction<Params extends any[], Result, Deps = {}>(action: TramvaiActionDefinition<Params, Result, Deps>): TramvaiAction<Params, Result, Deps>;
|
|
3
|
+
export declare function isTramvaiAction<Params extends any[], Result, Deps>(action: any): action is TramvaiAction<Params, Result, Deps>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { createApp, App } from './createApp';
|
|
2
2
|
export { createBundle } from './bundles/createBundle';
|
|
3
3
|
export { createAction } from './actions/createActions';
|
|
4
|
+
export * from './actions/declareAction';
|
|
4
5
|
export { Module, deprecatedModule as module, MODULE_PARAMETERS } from './modules/module';
|
|
5
6
|
export { getModuleParameters } from './modules/getModuleParameters';
|
|
6
7
|
export { walkOfModules } from './modules/walkOfModules';
|
package/lib/index.es.js
CHANGED
|
@@ -225,6 +225,9 @@ function createBundle(options) {
|
|
|
225
225
|
return mergeOptions(presets, options);
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
/**
|
|
229
|
+
* @deprecated: use `declareAction`
|
|
230
|
+
*/
|
|
228
231
|
function createAction(action) {
|
|
229
232
|
const result = Object.assign(action.fn, {
|
|
230
233
|
[ACTION_PARAMETERS]: action,
|
|
@@ -236,4 +239,14 @@ function createAction(action) {
|
|
|
236
239
|
return result;
|
|
237
240
|
}
|
|
238
241
|
|
|
239
|
-
|
|
242
|
+
function declareAction(action) {
|
|
243
|
+
return {
|
|
244
|
+
...action,
|
|
245
|
+
tramvaiActionVersion: 2,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function isTramvaiAction(action) {
|
|
249
|
+
return 'tramvaiActionVersion' in action && action.tramvaiActionVersion === 2;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export { App, MODULE_PARAMETERS, Module, createAction, createApp, createBundle, declareAction, getModuleParameters, isExtendedModule, isTramvaiAction, deprecatedModule as module, walkOfModules };
|
package/lib/index.js
CHANGED
|
@@ -233,6 +233,9 @@ function createBundle(options) {
|
|
|
233
233
|
return mergeOptions(presets, options);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
/**
|
|
237
|
+
* @deprecated: use `declareAction`
|
|
238
|
+
*/
|
|
236
239
|
function createAction(action) {
|
|
237
240
|
const result = Object.assign(action.fn, {
|
|
238
241
|
[tokensCore.ACTION_PARAMETERS]: action,
|
|
@@ -244,6 +247,16 @@ function createAction(action) {
|
|
|
244
247
|
return result;
|
|
245
248
|
}
|
|
246
249
|
|
|
250
|
+
function declareAction(action) {
|
|
251
|
+
return {
|
|
252
|
+
...action,
|
|
253
|
+
tramvaiActionVersion: 2,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function isTramvaiAction(action) {
|
|
257
|
+
return 'tramvaiActionVersion' in action && action.tramvaiActionVersion === 2;
|
|
258
|
+
}
|
|
259
|
+
|
|
247
260
|
Object.defineProperty(exports, 'DI_TOKEN', {
|
|
248
261
|
enumerable: true,
|
|
249
262
|
get: function () { return dippy.DI_TOKEN; }
|
|
@@ -274,8 +287,10 @@ exports.Module = Module;
|
|
|
274
287
|
exports.createAction = createAction;
|
|
275
288
|
exports.createApp = createApp;
|
|
276
289
|
exports.createBundle = createBundle;
|
|
290
|
+
exports.declareAction = declareAction;
|
|
277
291
|
exports.getModuleParameters = getModuleParameters;
|
|
278
292
|
exports.isExtendedModule = isExtendedModule;
|
|
293
|
+
exports.isTramvaiAction = isTramvaiAction;
|
|
279
294
|
exports.module = deprecatedModule;
|
|
280
295
|
exports.walkOfModules = walkOfModules;
|
|
281
296
|
Object.keys(tokensCore).forEach(function (k) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.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.
|
|
24
|
-
"@tramvai/tokens-core": "2.
|
|
25
|
-
"@tramvai/types-actions-state-context": "2.
|
|
26
|
-
"@tinkoff/dippy": "0.7.
|
|
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",
|
|
27
27
|
"tslib": "^2.0.3"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|