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

Suggest 'components' be placed before 'props' #62

Open
fritx opened this issue Oct 13, 2017 · 2 comments
Open

Suggest 'components' be placed before 'props' #62

fritx opened this issue Oct 13, 2017 · 2 comments

Comments

@fritx
Copy link

fritx commented Oct 13, 2017

https://github.com/pablohpsilva/vuejs-component-style-guide#why-6

Again, grouping makes the component easier to read (name; extends; props, data and computed; components; watch and methods; lifecycle methods, etc.);

export default {
    // Do not forget this little guy
    name: 'RangeSlider',
    // share common functionality with component mixins
    mixins: [],
    // compose new components
    extends: {},
    // component properties/variables
    props: {
      bar: {}, // Alphabetized
      foo: {},
      fooBar: {},
    },
    // variables
    data() {},
    computed: {},
    // when component uses other components
    components: {},
    // methods
    watch: {},
    methods: {},
    // component Lifecycle hooks
    beforeCreate() {},
    mounted() {},
};

I suggest components be placed after extends and before props,
because it is intensively related to the<template> on top, and nothing else.

like: https://github.com/vuejs/vue-hackernews-2.0/blob/master/src/views/ItemList.vue

I suffer from scrolling too much, and think it is not relational(rational).
Any thoughts?
Cheers!

@pablohpsilva
Copy link
Owner

Hello @fritx !
Let's talk about it. Yeap, I do believe all components attributes should be easy to read and easy to spot.
With that in mind, I believe it would be better if computed attr could be placed right after props.

"But... Why?" You may ask. I believe name, mixins, extends, props are very important to know what the component is (name), what is made of (mixins, extends) and what you can do with it (props). Everything else, from a user (another developer) point of view is not really relevant, specially if the component works.

I love having the props all the way up, because, usually, that's what really matters to me when using components.

What do you think?

@fritx
Copy link
Author

fritx commented Oct 31, 2017

@pablohpsilva Hah, thanks for your reply!

I believe name, mixins, extends, props are very important to know what the component is (name), what is made of (mixins, extends) and what you can do with it (props).

I'm very agreed with that, and I think, "Birds of a feather flock together",
another principle is cool as well -- things should be categorized by types.

The accepted values of components are same as extends and mixins, are all Components,
so I think a better practice is to place them together, it would look very clear.

For example, in one of my libraries:
https://github.com/fritx/vue-threejs/search?utf8=%E2%9C%93&q=components%3A&type=

import { PositionalAudio, AudioLoader } from 'three'
import Object3D from './Object3D'

export default {
  name: 'PositionalAudio',
  mixins: [Object3D],
  components: { Object3D },
  inject: ['global'],

  props: {
    refDistance: { type: Number, default: 10 },
    volume: { type: Number, default: 1 },
    paused: Boolean,
    loop: Boolean,
    url: String
  },

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