npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tramvai/core

v4.41.104

Published

--- title: '@tramvai/core' sidebar_position: 1 ---

Downloads

2,271

Readme


title: '@tramvai/core' sidebar_position: 1

Core

Ядро tramvai. В основном требуется для разработки модулей трамвая.

API

createApp

createApp - configuring, creating and running the application

createApp({ modules, bundles, providers })

  • 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 is Promise 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

Usage

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

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

More about actions

declareAction({ name, fn, deps, conditions })

  • 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, maybe async
    • 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

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 to STORE_TOKEN.getState
  • dispatch - quick access to STORE_TOKEN.dispatch
  • abortSignal - instance of signal related to the current execution tree
  • abortController - instance of AbortController created exclusively for the current action execution

conditionsFailResult

Specifies the output of the action in case its conditions was not met during execution.

If conditions are not met for action, action's fn won't be executed in any way

Possible values for the conditionsFailResult:

  • empty - (default) execution will be resolved with undefined as a result
  • error - execution will be rejected with ConditionFailError

Usage example

import { declareAction } from '@tramvai/core';

declareAction({
  name: 'action log error',
  fn(payload) {
    this.deps.logger.error('ERROR');
  },
  deps: {
    logger: 'logger',
  },
  conditions: {
    requiredCoreRoles: ['god'],
  },
});

createBundle

createBundle(options: BundleOptions) - method to create a bundle.

Read more about bundles

Properties BundleOptions

  • 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

Usage

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],
});

Exported tokens

DI_TOKEN

Dependency Injection container implementation

APP_INFO_TOKEN

Information about running application

COMMAND_LINE_RUNNER_TOKEN

CommandLineRunner implementation

COMMAND_LINES_TOKEN

Commands for CommandLineRunner