@adityahegde/typescript-framework 中文文档教程

发布于 3年前 浏览 3 更新于 3年前

typescript-framework

一个完整的堆栈框架,包含用于服务器的 Express.js 和用于 UI 的 React.js。 这是一项正在进行中的工作。 API 会改变。

检查 test/functional/ui/app 文件夹中的真实用例。 检查 docs 文件夹以获取详细的 API 文档。

Models

用于为 React 应用程序定义模型的实用程序包。 模型是使用各种装饰器定义的。

Creating a Model

要在生态系统中创建模型,模型类必须扩展 BaseType 并具有 ModelMetadata.Model 装饰器。

import {
  ModelMetadata,
  TextField,
  DisplayField,
} from "@adityahegde/models";

@ModelMetadata.Model({
  // Overrides the singular representation.
  // By default it will be class name with 1st letter as lower case.
  singular: "sample",
  // Overrides the plural representation.
  // By default it will be output of pluralize pacakge of singular attribute.
  plural: "samples",
  // API base for the model. This is used to build the api route for this model.
  // apiPath = `${apiBase}/${plural}`
  apiBase: "/api",
  // Specifies the base class for a polymorphic inheritance.
  // NOTE: Not implemented just yet.
  polymorphic: "",
})
class SampleModel extends BaseType {
  @DisplayField()
  // Add field decorators at the end for other decorators to work
  @TextField()
  public textField: string;
}

Server

具有各种类,可以轻松地为模型构建端点并为 UI 提供服务。

UI

具有基于模型配置呈现的 UI 元素的不同组件。

typescript-framework

A full stack framework with Express.js for server and React.js for UI. This is a very much work in progress. API will change.

Check test/functional/ui/app folder for a real life use case. Check docs folder for detailed API docs.

Models

Utility package used to define models for a React app. Models are defined using various decorators.

Creating a Model

To create a model in the ecosystem the model class has to extend BaseType and have ModelMetadata.Model decorator.

import {
  ModelMetadata,
  TextField,
  DisplayField,
} from "@adityahegde/models";

@ModelMetadata.Model({
  // Overrides the singular representation.
  // By default it will be class name with 1st letter as lower case.
  singular: "sample",
  // Overrides the plural representation.
  // By default it will be output of pluralize pacakge of singular attribute.
  plural: "samples",
  // API base for the model. This is used to build the api route for this model.
  // apiPath = `${apiBase}/${plural}`
  apiBase: "/api",
  // Specifies the base class for a polymorphic inheritance.
  // NOTE: Not implemented just yet.
  polymorphic: "",
})
class SampleModel extends BaseType {
  @DisplayField()
  // Add field decorators at the end for other decorators to work
  @TextField()
  public textField: string;
}

Server

Has various classes to easily build an endpoint for models and serving the UI.

UI

Has different components for UI elements that are rendered based on model's configuration.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文