Skip to content

ES6 Style Guide Discussion #390

Open
@philmerrell

Description

@philmerrell

Last week I listened to episode 39 of Adventures in Angular, which was a great discussion around ES6 language features and the tooling to support it.

I've seen some posts on the web about using Angular 1.x in conjunction with ES6, but it's pretty sparse. I'm hoping to strike up a conversation about how we can take all the great ideas in this style guide and apply them in the context of ES6. If possible maybe an ES6 branch of this style guide could be created to help facilitate the discussion with input from the community.

After spending the week in ES6 and angular 1.x, one the most obvious pattern changes is through the use of ES6 modules. I really like how angular modules can be isolated to just an angular module definition file and everything else (controllers, services, directives, etc...) can be plain old JS and imported in using the ES6 module loader.

// app.module.js
import AppCtrl from './app.controller';
import './survey/survey.module';
import './core/core.module';
import './services/services.module';
import 'ui-router';
import 'angular-material';

angular
  .module('app', ['app.core', 'app.services', 'app.survey'])
  .controller('AppCtrl', AppCtrl)
  .config(function() {

  });
/// survey.module.js
'use strict';

import SurveyCtrl from './survey.controller';
import MultiChoiceCtrl from './multi-choice/multi-choice.controller';
import MultiSelectCtrl from './multi-select/multi-select.controller';
import StaggeredMultiSelectCtrl from './staggered-multi-select/staggered-multi-select.controller';

angular
  .module('app.survey', [])
  .controller('SurveyCtrl', SurveyCtrl)
  .controller('MultiChoiceCtrl', MultiChoiceCtrl)
  .controller('MultiSelectCtrl', MultiSelectCtrl)
  .controller('StaggeredMultiSelectCtrl', StaggeredMultiSelectCtrl)
;

I'd be interested to hear thoughts on this approach. In Angular 1.x we still have to inform the Angular module system about controllers, services, etc. With this approach I like that it delegates the wiring up of Angular assets only in the module definition files. I think this could also lend itself well to migrating to Angular 2. Since angular.module will be going away it might be prudent to reduce the amount of angular.module references throughout the code base.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions