@tramvai/core 1.59.0 → 1.62.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 +153 -5
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,21 +1,169 @@
1
+ ---
2
+ title: '@tramvai/core'
3
+ sidebar_position: 1
4
+ ---
5
+
1
6
  # Core
2
7
 
3
8
  Ядро tramvai. В основном требуется для разработки модулей трамвая.
4
9
 
5
- ## Экспортируемые токены
10
+ ## API
11
+
12
+ ### createApp
13
+
14
+
15
+ `createApp` - configuring, creating and running the application
16
+
17
+ #### createApp({ modules, bundles, providers })
18
+
19
+ - `modules` - array with used [modules](concepts/module.md) in the application
20
+ - `bundles` - object with used bundles with data in the application. The key is the bundle identifier, the value is `Promise` which returns the bundle
21
+ - `providers` - an array with application providers, which will be added last in the DI (after module providers) and thus it will be possible to overwrite the implementation of the tokens
22
+ - `actions` - array with global [actions](concepts/action.md), which will be registered for all bundles and pages
23
+
24
+ #### Usage
25
+
26
+ ```tsx
27
+ import { createApp, provide } from '@tramvai/core';
28
+ import { RouterModule } from '@tramvai/module-router';
29
+ import { RenderModule } from '@tramvai/module-render';
30
+ import { ServerModule } from '@tramvai/module-server';
31
+
32
+ createApp({
33
+ name: 'my-awesome-app',
34
+ modules: [RouterModule, RenderModule, ServerModule],
35
+ providers: [
36
+ provide({
37
+ provide: 'options',
38
+ useValue: {},
39
+ }),
40
+ ],
41
+ bundles: {
42
+ mainDefault: () => import(/* webpackChunkName: "mainDefault" */ './bundles/mainDefault'),
43
+ },
44
+ actions: [loadDepositConfig],
45
+ });
46
+ ```
47
+
48
+ After calling createApp, [СommandLineRunner](concepts/command-line-runner.md) is started which performs the chain of actions necessary to initialize the application.
49
+
50
+ ### Module
51
+
52
+ `Module` - Decorator for configuring and creating a module.
53
+
54
+ [Read more about modules](concepts/module.md)
55
+
56
+ #### @Module({ providers, deps, imports })(class)
57
+
58
+ - `providers` - [Providers](concepts/provider.md), which will be added to the root DI container and become available in other modules
59
+ - `deps` - List of dependencies from the DI container, necessary to initialize the module
60
+ - `imports` - A list of modules from which providers will be obtained and added to the DI. Allows you to create modules that combine many other modules
61
+
62
+ #### Usage
63
+
64
+ ```tsx
65
+ import { Module, provide } from '@tramvai/core';
66
+
67
+ @Module({
68
+ providers: [
69
+ provide({
70
+ provide: 'token',
71
+ useValue: 'value-in-token',
72
+ }),
73
+ ],
74
+ deps: {
75
+ logger: 'logger',
76
+ },
77
+ imports: [ModuleLogger],
78
+ })
79
+ class ModulePubSub {
80
+ constructor({ logger }) {
81
+ logger.info('Module create');
82
+ }
83
+ }
84
+ ```
85
+
86
+ ### createAction
87
+
88
+ `createAction` - 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
+
90
+ [More about actions](concepts/action.md)
91
+
92
+ #### createAction({ name, fn, deps, conditions })
93
+
94
+ - `name` - The name of the action, a unique identifier is expected
95
+ - `fn(context, payload, deps)` - Implementation of the action, this function will be called when the action is used, maybe `async`
96
+ - `context` - [ConsumerContext](references/tokens/common.md#context-tokens-list)
97
+ - `payload` - data passed to action
98
+ - `deps` - provider instances from `deps`
99
+ - `deps` - List of providers that are needed for the action to work
100
+ - `conditions` - List of restrictions for the execution of the action
101
+
102
+ #### Usage example
103
+
104
+ ```tsx
105
+ import { createAction } from '@tramvai/core';
106
+
107
+ createAction({
108
+ name: 'action log error',
109
+ fn: (context, payload, deps) => {
110
+ deps.logger.error('ERROR');
111
+ },
112
+ deps: {
113
+ logger: 'logger',
114
+ },
115
+ conditions: {
116
+ requiredCoreRoles: ['god'],
117
+ },
118
+ });
119
+ ```
120
+
121
+ ### createBundle
122
+
123
+ `createBundle(options: BundleOptions)` - method to create a bundle.
124
+
125
+ [Read more about bundles](concepts/bundle.md)
126
+
127
+ #### Properties BundleOptions
128
+
129
+ - `name` - Name of the bundle. The value will be used as a bundle identifier.
130
+ - `components: {}` - An object with registered components for the bundle, which you can use in application routes
131
+ - `presets?: []` - A list of additional properties for the current bundle. This list is merged with the current properties. Needed to extract common parts, e.g. a set with actions and components for authorization. Reference - babel and eslint presets
132
+ - `actions?: []` - List of [actions](concepts/action.md) that will be registered globally for the bundle
133
+ - `reducers?: []` - List of [reducers](references/tramvai/state/base.md), which must be registered with the loading of the bundle
134
+
135
+ #### Usage
136
+
137
+ ```tsx
138
+ import { createBundle } from '@tramvai/core';
139
+ import { lazy } from '@tramvai/react';
140
+
141
+ createBundle({
142
+ name: 'app/bundle',
143
+ presets: [commonPreset],
144
+ components: {
145
+ 'app/pages/MainPage': lazy(() => import('../pages/MainPage')),
146
+ 'app/pages/SecondPage': lazy(() => import('../pages/SecondPage')),
147
+ },
148
+ actions: [fooAction, barAction],
149
+ reducers: [bazReducer],
150
+ });
151
+ ```
152
+
153
+ ## Exported tokens
6
154
 
7
155
  ### DI_TOKEN
8
156
 
9
- Используется для доступа к инстансу DI
157
+ Dependency Injection container implementation
10
158
 
11
159
  ### APP_INFO_TOKEN
12
160
 
13
- Содержит информацию о запущенном приложении
161
+ Information about running application
14
162
 
15
163
  ### COMMAND_LINE_RUNNER_TOKEN
16
164
 
17
- Реализация раннера для исполнения команд
165
+ CommandLineRunner implementation
18
166
 
19
167
  ### COMMAND_LINES_TOKEN
20
168
 
21
- Задание списка команд
169
+ Commands for CommandLineRunner
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/core",
3
- "version": "1.59.0",
3
+ "version": "1.62.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -20,9 +20,9 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@tinkoff/utils": "^2.1.2",
23
- "@tramvai/tokens-common": "1.59.0",
24
- "@tramvai/tokens-core": "1.59.0",
25
- "@tramvai/types-actions-state-context": "1.59.0",
23
+ "@tramvai/tokens-common": "1.62.0",
24
+ "@tramvai/tokens-core": "1.62.0",
25
+ "@tramvai/types-actions-state-context": "1.62.0",
26
26
  "@tinkoff/dippy": "0.7.38",
27
27
  "tslib": "^2.0.3"
28
28
  },