Giter VIP home page Giter VIP logo

angular-component-spec's Introduction

Specification for reusable AngularJS components

Attention: This document is a WIP! Since we want to collect as many opinions as possible, feel free to fork and send a Pull Request. We hope that once this specification is called final, developers of angular components will do things the same way, which will allow the Angular Team to provide better tooling.

Preface

This specification should help you as a developer, as well as a consumer of Angular components, to find, use and develop reusable Angular components. Angular components are distributed as Bower packages. See bower.io for more information.

It has two parts:

  1. The consumer perspective
  2. The creator/forker perspective

The consumer perspective covers all topics on finding and using Angular components, whereas the creator or forker part gives an in-depth description of how to create, structure and publish an Angular component, as well as which naming conventions to follow for the component itself and the resulting bower package.

Dependencies

This specification also expects that needed tools are already installed and ready to use. Which means the following commands should be used to install the needed tools on a local machine:

Node Package Manager

Visit https://nodejs.org/download/

Bower Package Manager

$ npm install -g bower

Definitions in this specification

This specification contains expressions like components, packages and modules. These are the definitions:

Component

Component is a Bower concept. A component is a repo which contains some files for client-side use in a web browser. This may include, but is not limited to, JavaScript, CSS, HTML, and images. A Bower component has a component.json (or bower.json) file that describes the component and its dependencies.

Package

Package is a Bower concept. For the time being, one can think of the terms package and component as being interchangeable in the context of Bower. In general, package is the thing that you can download, and contains a component, which is a group of one or more assets. Saying one can think of them as interchangeable for now, is because there's a one-to-one correspondence of package to component.

Module

When the word module appears, this specification means an AngularJS module. An AngularJS module may have multiple directives, services, or filters. For components, each module typically has its own file. Bower components typically contain just one AngularJS module, though in theory there can be more.

AngularJS Components Consumer

This part of the Reusable AngularJS components specification is highly inspired by @btford 's blog post.

Table Of Contents

Naming Conventions

Registered Angular components

To make searching and filtering for Angular components with Bower as easy as possible, the name under which Angular components get registered should match the following pattern.

angular-[optional-namespace]-[thing-name]-[optional-thing-type]

Name should be prefixed with angular-.

optional-namespace

Can be used to group similar components such as

angular-phonegap-ready
angular-phonegap-geolocation
thing-name

This is the actual module name. It should match the functionality of the module. E.g. the geolocation in angular-phonegap-geolocation. Or the translate in angular-translate.

optional-thing-type

Could be filter, directive or service. This is for clarification if [thing-name] isn't enough.

Searching and Finding

Search for packages

Since registered Angular components follow a naming convention, finding them can be achieved by simply searching for all registered Bower packages which have an angular in their registry name.

$ bower search angular

Should return a list of registered bower packages with an angular in their name.

Finding packages with keywords

Bower doesn't currently support a search with keywords. Filtering packages by keyboard can be done by using bower search in combination with the grep command. So the following command searches for Angular packages with the keyword "phonegap".

$ bower search angular | grep "phonegap"

Installing packages

Once the right package is found, one can install it using the Bower install command. E.g. installing AngularJS itself as a package would look like this:

$ bower install angular

This will download the specified package into the folder which is configured as components folder via .bowerrc.

Installing unregistered packages

It is possible that there's an AngularJS component on GitHub, which is not registered as bower component. This could have several reasons:

  • The author doesn't plan to publish it as a Bower component
  • The name the author wants to register it is already been taken
  • The package is actually registered but the endpoint is broken (which unfortunately happens often, and there's currently no way to take care of that as a package maintainer. See bower/bower#120

In that cases one can install the package by specifying the GitHub user and the repository. This works for every GitHub repository.

$ bower install <username>/<repository>

TL;DR

Your modules should be publicly distributed with this convention ('Publicly' as in bower names, repository names, website names, etc):

angular-[optional-namespace]-[thing-name]-[optional-thing-type]

Example:

angular-phonegap-ready
angular-superman-directives

Your angular modules in the source should have this convention:

[author-name].[thing-name].[thing-type]

Example:

angular.module('btford.phonegap-ready', []);
angular.module('doctor-evil.superman-directives.kryptonite', [])

Bad Practices

Please don't do these things.

Registering controllers, services, filters, etc. on the ng module

// this is bad
angular.module('ng').filter('tel', function (){});

Instead create your own module and add it as a dependency to your application's top-level module.

Why: this is needlessly frail. See this issue.

References

angular-component-spec's People

Contributors

0x-r4bbit avatar ajoslin avatar btford avatar gjungb avatar igorminar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-component-spec's Issues

Purpose?

What is the purpose of this spec? Or is that also a WIP?

The reason I ask is because I didn't know about this repo until a couple of hours ago. Not having any standard blueprint or conventions for angular development has been bothering me. My response to this earlier this morning, not knowing about this repo, was to start https://github.com/mikehaas763/angular-conventions.

I now see that the repo I started may A) be completely redundant or B) have overlap with this repository/spec. Obviously, I mentioned on that repo's readme about figuring out how to organize into a proper component for bower. However, my main goal and hope is to get an overall application structure for the developing in the framework. Not just individual components.

So ultimately, is angular-component-spec just for defining how to make smaller modular components that still need to be "plugged in" to an applications structure?

P.S. Getting solid framework application structure conventions whether official or just well accepted by the community is something I really care about at this point. So let's keep these discussions going.

Add instructions for publishing to npm

We decided that we prefer npm to bower. We should update this guide accordingly.

We should still preserve the bower install instructions, and encourage developers to support both as best as they can.

Decide what to do with this repo

We haven't touched this in months, but I think there are valuable things in here.

I vote we move this content into the official angular docs.

Recently, we get a lot of PRs for new features that should be implemented as third-party modules instead. Having a canonical explanation for how to do this would be nice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.