Skip to content
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

Define order of tag script properties/methods and lifecycle events #50

Open
MartinMuzatko opened this issue Apr 20, 2016 · 1 comment
Open

Comments

@MartinMuzatko
Copy link

MartinMuzatko commented Apr 20, 2016

I'd define more than just properties/methods.

While it is usual for angular/angular2 to have the lifecycle events at the top (constructor/ngOnInit) I'd put them at the bottom.
That is to be discussed.

So I'd declare this structure as best practice / well organized:

  1. mixins
  2. opts properties
  3. properties
  4. eventhandlers
  5. methods
  6. lifecycle events

e.g.:

// MIXINS
this.mixin('selectable')

// OPTS PROPERTIES
this.min = opts.min || 0
this.max = opts.max || 100

// PRIVATE / MODULE SPECIFIC PROPERTIES
this.maxWidth = '800px'

// EVENTS
add(event) {
    /* ... */
}

edit(event) {
    /* ... */
}

toggle(event) {
    /* ... */
}

// METHODS

this.setup = function() {

}

// LIFECYCLE EVENTS

this.on('mount', () => {
    this.setup()
})
@jbmoelker
Copy link
Member

I fully agree with having mixins on top. I personally don't mind if properties and "opts properties" are mixed as it's just a matter of initiation. In practice I think those are mostly moved to .on('update'). And I would maybe combine lifecycle other event handlers, as they are both just event listeners. And otherwise I would prefer mount, update, updated, otherEvents, unmount as that would basically be the chronological order.

So simplified order:

  1. mixins
  2. properties
  3. methods
  4. (lifecycle) event listeners

I wouldn't mind extending "put tag properties and methods on top".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants