最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Coding standards for Angular2TypeScript - Stack Overflow

programmeradmin0浏览0评论

I'm wondering if there's at least some munity consensus on how to write reusable Angular2 code in TypeScript. I tried to summarise what I found out and what I'd like to know in context of Angular2.

Module/App directory structure and file names

  • In the official tutorial I see they put all code into app directory and all dependencies like node_modules or typings are in the parent directory.

  • Lowercase file names, ponent.ts suffix for ponents and .service.ts for services. They put all files to the same directory which is going to be a huge mess?

  • One class/interface/enum per file. For classes, functions, interfaces and other names its probably best to stick to Coding guidelines for TypeScript by Microsoft?

Modules

  • Should modules pile and bundle themselves using postinstall npm hook? Or is it better to provide bundled version directly on git like most JavaScript libraries do?
  • Should I stick to system type of modules by default when I'm expecting that my module's going to be used only by browser or is it better to always use UMD?
  • Is there any reason to use CommonJS or AMD instead of system?

Using 3rd party modules

  • Should I expect that other developers will embed my modules with <script> tags or they'll load it using System.import()?
  • If my modules has dependencies on other JavaScript libraries, is it better to provide a bundled version of my whole module with all dependencies or just define them in package.json?

I'm wondering if there's at least some munity consensus on how to write reusable Angular2 code in TypeScript. I tried to summarise what I found out and what I'd like to know in context of Angular2.

Module/App directory structure and file names

  • In the official tutorial I see they put all code into app directory and all dependencies like node_modules or typings are in the parent directory.

  • Lowercase file names, .ponent.ts suffix for ponents and .service.ts for services. They put all files to the same directory which is going to be a huge mess?

  • One class/interface/enum per file. For classes, functions, interfaces and other names its probably best to stick to Coding guidelines for TypeScript by Microsoft?

Modules

  • Should modules pile and bundle themselves using postinstall npm hook? Or is it better to provide bundled version directly on git like most JavaScript libraries do?
  • Should I stick to system type of modules by default when I'm expecting that my module's going to be used only by browser or is it better to always use UMD?
  • Is there any reason to use CommonJS or AMD instead of system?

Using 3rd party modules

  • Should I expect that other developers will embed my modules with <script> tags or they'll load it using System.import()?
  • If my modules has dependencies on other JavaScript libraries, is it better to provide a bundled version of my whole module with all dependencies or just define them in package.json?
Share Improve this question asked Feb 22, 2016 at 18:17 martinmartin 97.1k26 gold badges204 silver badges236 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

There's the Angular 2 Style Guide (https://github./mgechev/angular2-style-guide), as featured in Angular2 News:

The purpose of the following style guide is to present a set of best practices and style guidelines for the development of Angular 2 applications. If you are looking for an opinionated style guide for syntax, conventions...

Angular 1 had a munity accepted style guide written by John Papa. There will be something similar created for Angular 2 in fact you can see the start of this ing together with the Tour of Heroes examples in place at angular.io

发布评论

评论列表(0)

  1. 暂无评论