您的位置:首页 > Web前端

前端框架Aurelia - feature()

2017-05-08 14:56 351 查看

Introduction

有时,您拥有完整的组件或相关功能,它们共同构成了一个“特性”。这个“特性”甚至可能是由您的团队中的一组特定的开发人员所拥有的。你想要这些开发者能够管理自己的资源配置和功能,而不干扰其他地区的应用。对于这个场景,水母提供了“特性”特性。

想象一下,如上所述,我们有一个my-component组件。想象一下,这是在你的应用中形成了一个逻辑功能的十几个组件之一。与其将该功能的配置逻辑放在应用程序的配置模块中,我们还可以将该特性的配置放在它自己的特性配置模块中。

要创建一个“特性”,简单地创建一个文件夹在您的应用程序;在我们的示例:my-feature。在该文件夹中,放置与该功能相关的所有组件和其他代码。最后,创建一个索引。ts文件在my-特写文件夹的根目录下。索引。ts文件应该导出一个配置函数。下面是我们假设的my-特写特性的代码:

A feature module(index.ts)

import {FrameworkConfiguration} from 'aurelia-framework';

export function configure(config: FrameworkConfiguration): void {
config.globalResources(['./my-component', './my-component-2', 'my-component-3', 'etc.']);
}


The configure method receives an instance of the same FrameworkConfiguration object as the aurelia.use property. So, the feature can configure your app in any way it needs. An important note is that resources should be configured using paths relative to the index.ts itself.

Use feature

import {Aurelia} from 'aurelia-framework';

export function configure(aurelia: Aurelia): void {
aurelia.use
.standardConfiguration()
.developmentLogging()
.feature('my-feature');

aurelia.start().then(() => aurelia.setRoot());
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Aurelia feature