Skip to content

Style guide #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Style guide #427

wants to merge 1 commit into from

Conversation

Brocco
Copy link
Contributor

@Brocco Brocco commented Apr 12, 2016

No description provided.

templateUrl: '<%= dasherizedModuleName %>.component.html',
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']
})
export class <%= classifiedModuleName %>Component {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to implement the OnInit interface if we're defining ngOnInit method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgechev I agree with that (didn't know it existed) but do you agree with having ngOnInit defined by default in a component? I think we should have something other than a constructor in there so devs don't see that as the primary place to put code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. Also I noticed that the VSCode snippets by @johnpapa declare ngOnInit as well.

On the other hand, I haven't used this hook that often in the components that I've developed and if I was using the CLI in most cases I'd have to remove the ngOnInit declaration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good point. We dont want to add things people will remove.

without ngOnInit I have noticed many people end up putting that startup code in the ctor. That makes it awful to test. That's why I like it there form a template standpoint. But if you have no startup code, you would need to remove it. I almost always use it.

That said, I'd be OK removing ngOnInit and the interface and the import if everyone here wants it that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it comes down to the use case, what fraction of generated components will end up needing/using this? Unfortunately at this point we don't have enough of a sample size to make a decision based upon facts/research only based upon gut feeling and the risk of devs being aware of the lifecycle hooks for components. I've seen enough examples of initialization code inside of the ctor, which is what lead me to add this in the first place.

Personally I think it should be there (with the interface reference also added), but I am also OK with it not being there at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also prefer it being there. And the interface always goes with it, IMO. Otherwise folks are apt to change a spelling of it and then it never runs. Uh oh

I vote with Mike and say keep it for now.

Copy link
Member

@mgechev mgechev Apr 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I prefer it to be there as well. Seems like a great suggestion for making your code more testable. In the end, if you don't like it nothing stops you from deleting it from the generated component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly and potentially down the road an option could be added to the generator to control what gets generated

@Brocco Brocco force-pushed the style-guide branch 2 times, most recently from 9746373 to aeae925 Compare April 16, 2016 01:05
@Brocco Brocco force-pushed the style-guide branch 4 times, most recently from d8e3ed4 to ddcee2f Compare April 16, 2016 02:32

describe('<%= classifiedModuleName %> Component', () => {

beforeEachProviders((): any[] => []);


it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb.createAsync(<%= classifiedModuleName %>).then((fixture) => {
return tcb.createAsync(<%= classifiedModuleName %>Component).then((fixture: ComponentFixture) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is <%= classifiedModuleName %>Component better than adding Component to the moduleName instead? Just curious.

We could even do logic to see if the user is saying ng g component my-comp.component we don't add a second component to it. WDYT?

@hansl
Copy link
Contributor

hansl commented Apr 18, 2016

LGTM assuming the Windows test are fixed. Good work!

Implements the majority of style guide angular#316
Moves systemjs configuration our of index.html angular#429
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants