Ядро tramvai. В основном требуется для разработки модулей трамвая.
createApp
- configuring, creating and running the application
-
modules
- array with used modules in the application -
bundles
- object with used bundles with data in the application. The key is the bundle identifier, the value isPromise
which returns the bundle -
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 -
actions
- array with global actions, which will be registered for all bundles and pages
import { createApp, provide } from '@tramvai/core';
import { RouterModule } from '@tramvai/module-router';
import { RenderModule } from '@tramvai/module-render';
import { ServerModule } from '@tramvai/module-server';
createApp({
name: 'my-awesome-app',
modules: [RouterModule, RenderModule, ServerModule],
providers: [
provide({
provide: 'options',
useValue: {},
}),
],
bundles: {
mainDefault: () => import(/* webpackChunkName: "mainDefault" */ './bundles/mainDefault'),
},
actions: [loadDepositConfig],
});
After calling createApp, СommandLineRunner is started which performs the chain of actions necessary to initialize the application.
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
-
name
- The name of the action, a unique identifier is expected -
fn(...params)
- Implementation of the action, this function will be called when the action is used, maybeasync
-
this
- action execution context that contains some helper functions and resolved deps -
params
- data passed to action
-
-
deps
- List of providers that are needed for the action to work -
conditions
- List of conditions for the execution of the action -
conditionsFailResult
- see
Action execution context that contains some helper functions and resolved deps
Context has next fields:
-
deps
- resolved deps that were specified when declaring action -
executeAction
- allows to execute another actions inside current one -
getState
- quick access toSTORE_TOKEN.getState
-
dispatch
- quick access toSTORE_TOKEN.dispatch
-
abortSignal
- instance of signal related to the current execution tree -
abortController
- instance ofAbortController
created exclusively for the current action execution
Specifies the output of the action in case its conditions
was not met during execution.
If
conditions
are not met for action, action'sfn
won't be executed in any way
Possible values for the conditionsFailResult
:
-
empty
- (default) execution will be resolved withundefined
as a result -
error
- execution will be rejected with ConditionFailError
import { declareAction } from '@tramvai/core';
declareAction({
name: 'action log error',
fn(payload) {
this.deps.logger.error('ERROR');
},
deps: {
logger: 'logger',
},
conditions: {
requiredCoreRoles: ['god'],
},
});
createBundle(options: BundleOptions)
- method to create a bundle.
-
name
- Name of the bundle. The value will be used as a bundle identifier. -
components: {}
- An object with registered components for the bundle, which you can use in application routes -
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 -
actions?: []
- List of actions that will be registered globally for the bundle -
reducers?: []
- List of reducers, which must be registered with the loading of the bundle
import { createBundle } from '@tramvai/core';
import { lazy } from '@tramvai/react';
createBundle({
name: 'app/bundle',
presets: [commonPreset],
components: {
'app/pages/MainPage': lazy(() => import('../pages/MainPage')),
'app/pages/SecondPage': lazy(() => import('../pages/SecondPage')),
},
actions: [fooAction, barAction],
reducers: [bazReducer],
});
Dependency Injection container implementation
Information about running application
CommandLineRunner implementation
Commands for CommandLineRunner