@acdf/build 中文文档教程

发布于 3年前 浏览 20 项目主页 更新于 3年前

Namespace

名称空间的概念已在 Campaign 中用于数据库,以保护您的表在共享相同名称时不会与本机表发生冲突。 ACDF 在 Javascript 方面使用了类似的概念。

项目命名空间本质上只是一个对象,它将作为您自定义代码的容器。 为了避免冲突,您应该始终将脚本封装在 IIFE 中,然后分配这些实体您确实想在命名空间的脚本之外使用它。 请参阅下面关于库的部分以获得更深入的解释。

Filenames

ACDF 使用文件名来确定应如何处理文件。

Javascript

格式:{name}.{suffix}.js

名字可以随便起。 后缀将告诉 ACDF 如何在构建期间处理您的文件。 以下是不同后缀及其代表的细分:

Libraries

库允许您组织和/或重用您的代码。 在概念上,它对应于 Campaign 中的 xtk:javascript 实体。 一个库应该导出你想在别处使用的函数和对象,方法是将它们分配给你的命名空间。

例如,如果您想创建一个可重用函数并在工作流活动中调用它:

hello.library.js

(() => {
    // This defines a function without saving it in the global scope.
    function helloWorld() {
        logInfo("Hello world");
    }

    // This assigns the helloWorld function to the ACDF namespace.
    ACDF.helloWorld = helloWorld;
})();

hello.activity.js

(() => {
    // This loads the library, similarly to a require() in CommonJS or the 'import' statement in ES modules
    loadLibrary("acdf:hello.library.js");

    // This calls the function from the namespace
    ACDF.helloWorld();
})();
- `library`: This denotes a JS library which can be called via `loadLibrary()`. This corresponds to the `xtk:javascript` entity. You should use 
- `activity`: This is JS activity in a workflow.

示例: - demo.library.js:使用 loadLibrary() 加载的库,它提供了 demo 描述的功能。 - dev.env.js

Namespace

The concept of a namespace is already used in Campaign with regards to the database to protect your tables from conflicting with native ones if they share the same name. ACDF uses a similar concept with regards to Javascript.

The project namespace is essentially just an object which will serve as a container for your custom code. In order to avoid conflicts, you should always envelop your scripts in an IIFE and then assign those entities which you do want to use outside of a script to the namespace. See the section below on libraries for a more in-depth explanation.

Filenames

ACDF uses filenames to determine how a file should be processed.

Javascript

Format:{name}.{suffix}.js

The name can be anything you want it to be. The suffix will tell ACDF how to process your file during the build. Here is a breakdown of the different suffixes and what they represent:

Libraries

Libraries allow you to organise and/or reuse your code. In concept, it corresponds to the xtk:javascript entity in Campaign. A library should export the functions and objects which you want to use elsewhere by assigning them to your namespace.

For example, if you wanted to create a reusable function and call it in a workflow activity:

hello.library.js

(() => {
    // This defines a function without saving it in the global scope.
    function helloWorld() {
        logInfo("Hello world");
    }

    // This assigns the helloWorld function to the ACDF namespace.
    ACDF.helloWorld = helloWorld;
})();

hello.activity.js

(() => {
    // This loads the library, similarly to a require() in CommonJS or the 'import' statement in ES modules
    loadLibrary("acdf:hello.library.js");

    // This calls the function from the namespace
    ACDF.helloWorld();
})();
- `library`: This denotes a JS library which can be called via `loadLibrary()`. This corresponds to the `xtk:javascript` entity. You should use 
- `activity`: This is JS activity in a workflow.

Examples: - demo.library.js: A library to be loaded using loadLibrary() which provides a feature described by demo. - dev.env.js

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